Click here to Skip to main content
15,881,173 members
Articles / Database Development / SQL Server

Generic Database Class Using ADO to Execute Stored Procedures

Rate me:
Please Sign up or sign in to vote.
3.50/5 (7 votes)
3 May 2001 93.7K   4.1K   37   2
Use this class to separate all database calls hidden to the callers. Nobody has to take care of how database retrieval is going on!

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

  1. Your database retrieval must rely on stored procedures.
  2. 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.


Written By
Team Leader
United Kingdom United Kingdom
.Over nine years work experience in different area of Software Engineering especially developing solutions in Visual C++, Visual Basic 6.0 and C# with multi tier architecture.
.Proficient in object-oriented analysis, design and programming especially in distributed client/Server environments.
.Extensive experience in WEB based software engineering using ASP.NET/ASP.
.Vast experience in designing/developing/implementing complex business applications in banking domain.
.Good work experience in Database programming using stored procedures, triggers and generating complex queries using Oracle and SQL Server 2005.

Comments and Discussions

 
GeneralExecution rights Pin
AlexEvans21-Sep-05 15:09
AlexEvans21-Sep-05 15:09 
GeneralCalling Oracle stored procedures from Visual C++ Pin
13-Apr-01 7:23
suss13-Apr-01 7:23 
Is there any way to execute a stored procedure in oracle from VC++? I tried passing the call to the stored procedure using the "ExecuteSQL()" call but I get errors.
Has anyone had success with this?

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.