SQL-DMO
Smartptr
The Smartptr sample illustrates using specific Microsoft® Visual C++® COM development features to reduce program source size and speed development.
Default Location
C:\Program Files\
Microsoft SQL Server\80\Tools\Devtools\Samples\sqldmo\cpp\Smartptr
Running the Sample
- Open the Smartptr.dsw workspace.
- Run the application.
Remarks
The sample shows:
- Using the #import directive to create smart pointers from the localized SQL-DMO type library.
- Creating an instance of a SQLServer object.
- Using smart pointers to manipulate SQLServer and QueryResults object properties and methods, including:
- Setting SQLServer object properties such as LoginTimeout and NetPacketSize.
- Calling the SQLServer object methods Connect and Close.
- Calling the ExecuteWithResults method to execute a Transact-SQL command batch and capture results.
- Setting and getting QueryResults object properties such as CurrentResultSet and Columns.
- Displaying result set members by using the QueryResults object GetColumnString method.
- Setting SQLServer object properties such as LoginTimeout and NetPacketSize.
- Error handling in a C++ application using smart pointers.
The Smartptr sample is a console application.
Smartptr requires Visual C++ 5.0 or later. Project files for Visual C++ (.dsp and .dsw extensions) are included. In the project files, build configurations are defined for computers using Intel or compatible processors. All configurations create a multibyte character application.
Objects, Methods, and Properties Illustrated
CoCreateInstance | QueryResults.ResultSets |
Err | QueryResults.Rows |
Err.Description | Release |
Err.Error | spSQLServer.Close |
Err.ErrorMessage | SQLServer |
Err.Source | SQLServer.ApplicationName |
QueryResults | SQLServer.Connect |
QueryResults.ColumnName | SQLServer.ExecuteWithResults |
QueryResults.Columns | SQLServer.HostName |
QueryResults.CurrentResultSet | SQLServer.LoginTimeout |
QueryResults.GetColumnString | SQLServer.NetPacketSize |