Click here to Skip to main content
Click here to Skip to main content
Go to top

Generic Database Class Using ADO to execute Stored Procedures

, 3 May 2001
Rate this:
Please Sign up or sign in to vote.
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 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 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 kind of problems and also if you guys have some better suggestions, then keep me informed. My private e-mail address is amir_1580@yahoo.com.

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

Share

About the Author

Amir Samdani
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 PinmemberAlexEvans21-Sep-05 15:09 
GeneralCalling Oracle stored procedures from Visual C++ PinmemberDorian13-Apr-01 7:23 

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

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

| Advertise | Privacy | Mobile
Web03 | 2.8.140916.1 | Last Updated 4 May 2001
Article Copyright 2001 by Amir Samdani
Everything else Copyright © CodeProject, 1999-2014
Terms of Service
Layout: fixed | fluid