Adovcsp.exe Demonstrates Using Stored Procedures with ADO (184968)



The information in this article applies to:

  • Microsoft SQL Server 6.5
  • Microsoft SQL Server 7.0
  • ActiveX Data Objects (ADO) 2.7
  • ActiveX Data Objects (ADO) 1.5
  • ActiveX Data Objects (ADO) 2.0
  • ActiveX Data Objects (ADO) 2.1
  • ActiveX Data Objects (ADO) 2.5
  • ActiveX Data Objects (ADO) 2.6
  • Microsoft Visual C++, 32-bit Enterprise Edition 6.0
  • Microsoft Visual C++, 32-bit Professional Edition 6.0
  • Microsoft Visual C++, 32-bit Learning Edition 6.0

This article was previously published under Q184968

SUMMARY

Adovcsp.exe is a sample program that demonstrates opening keyset and forwardOnly cursors using ActiveX Data Objects (ADO) Recordsets by executing stored procedures on Microsoft SQL Server. It also shows how to open a disconnected record set. The sample uses the Visual C++ #import feature and demonstrates ADO Recordset GetState(), Parameters GetName() and GetValue(), and many other Recordset, Command and Connection methods.

MORE INFORMATION

The following file is available for download from the Microsoft Download Center:
Release Date: September 17, 2003

For additional information about how to download Microsoft Support files, click the following article number to view the article in the Microsoft Knowledge Base:

119591 How to Obtain Microsoft Support Files from Online Services

Microsoft scanned this file for viruses. Microsoft used the most current virus-detection software that was available on the date that the file was posted. The file is stored on security-enhanced servers that help to prevent any unauthorized changes to the file.

The application assumes that you have a Microsoft SQL Server installed with the sample Pubs database. If this is not the case, change the following code in the openConn function:
spCON->ConnectionString = L"Provider=SQLOLEDB.1;Integrated Security=SSPI;Initial Catalog=pubs;Data Source=serverName;";
Replace Data Source=serverName with the name of your server and specify the name of your database. The sample creates two stored procedures and a table, and then drops them when the application exits.

The OpenRd method takes an input parameter (GradYear) and passes it to the stored procedure sp_AdoTestInOut. sp_AdoTestInOut returns all the records with GradYear >= to the parameter passed. It returns an output parameter, the number of records returned and also returns a parameter (the max GradYear). The student table created is based on the Student table of the Student Enrollment database that ships with Visual C++.

In this sample, the text boxes to show the Output parameter and Return code are only used when running the stored procedure by clicking the OpenRead button. Please see the source code for more details.

The Supports button obtains the schema information from the database using the technique and code described in the following Microsoft Knowledge Base article:

182831 HOWTO: Using the ADO OpenSchema Method from Visual C++

The Open DisCon button opens a disconnected recordset. This code is taken from the following Microsoft Knowledge Base article:

184397 HOWTO: Getting ADO Disconnected Recordsets in VBA/C++/Java

REFERENCES

For additional information, click the following article numbers to view the articles in the Microsoft Knowledge Base:

182389 FILE: Adovcbm.exe ADO 1.5 with #import and Getrows/Bookmarks

181733 FILE: Adovcbtd.exe #import Using UpdateBatch and CancelBatch

220152 FILE: Sample: ADOVC1 Simple ADO/VC++ Application

200122 SAMPLE: ATL2ADO returns disconnected recordset from COM to VB

229088 SAMPLE: Vcspnp.exe Demonstrates Passing SQL NULL Parameters and Reading NULL Values with ADO


Modification Type:MinorLast Reviewed:8/9/2004
Keywords:kbdownload kbDatabase kbfile kbinfo KB184968 kbAudDeveloper