Introduction
It is a useful tool to minimize your database related code. Just using CDatabaseServer
by following some steps, you will find it very useful for your project.
Requirements
- Your database retrieval must rely on stored procedures.
- SQL Server must be installed on the same machine where this code is running.
Explanation
The reason to write this article is that our database applications have somehow redundant code and may cause problems. For example, ADO library, we use it when we have to make a call to database. Usually, it's our practice that when we need data from database, we open connection every time and get data in RecordSet
object every time...
I have tried to implement a class that will fulfill the request of database calls whether incoming or outgoing.
You guys will really enjoy when you use it in your C++ application. I suggest you to follow these steps:
- For your database project, add provided two files, databaserver.h and databaserver.cpp.
- Whenever you need data, call
CDatabaseServer
's methods getExecStoredProcedure
by putting arguments correctly. That method will return VARIANT
array using GetRows
method of ADO Recordset
so that data can be marshaled properly. - Whenever you need to insert/update data, then call
CDatabaseServer
's method setExecStoredProcedure
. That method will return long
value which could be ID entity to which operation was performed. - Now it's your responsibility to manually update your connection information in the method
SetConnectionsting
. - Create database in SQL Server, modify local variable
szDatabase
with newly created database name in the setConnectionsting
method. - When calling
getExecStoredProcedure
/setExecStoredProcedure
, be careful to send proper stored procedure name and and its parameter in SAFEARRAY
pointer. - Parameter must be in the same sequence as in stored procedure.
Please don’t hesitate to ask about any problems and also if you guys have some better suggestions, then please leave a comment below.
History
- 4th May, 2001: Initial version
License
This article has no explicit license attached to it, but may contain usage terms in the article text or the download files themselves. If in doubt, please contact the author via the discussion board below. A list of licenses authors might use can be found here.