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.
- Your database retrieval must rely on stored procedures.
- SQL Server must be installed on the same machine where this code is running.
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 its 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
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
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
- Create database in SQL Server, modify local variable
szDatabase with newly created database name in the
- When calling
setExecStoredProcedure, be careful to send proper stored procedure name and and its parameter in
- Parameter must be in the same sequence as in stored procedure.
Please don’t hesitate to ask about any kind of problems and also if you guys have some better suggestions, then keep me informed. My private e-mail address is firstname.lastname@example.org.