Creating a New DB-Library for Visual Basic Project

To create a new 32-bit Visual Basic 4.0 project that uses the DB-Library for Visual Basic OLE custom control, follow these steps, which are fully outlined in the following text:

  1. Create a new Visual Basic project.
  2. Add the DB-Library for Visual Basic OLE custom control to your Toolbox.
  3. Add the DB-Library for Visual Basic header file to your project.
  4. Add the DB-Library for Visual Basic OLE custom control to a form in your project.
  5. Add code to the error handling and message handling event procedures.
    To add the DB-Library for Visual Basic OLE custom control (VBSQL.OCX) to your Toolbox
  1. From the Tools menu, choose Custom Controls.

    The Custom Controls dialog box appears.

  2. Choose the Browse button.

    The Add Custom Control dialog box appears.

  3. Select the VBSQL.OCX file. By default, it is located in the C:\MSSQL\DLL directory.
  4. Choose the Open button.

    The Available Controls list now includes "Vbsql OLE Custom Control module," and it is selected.

  5. Choose the OK button.

    The DB-Library for Visual Basic OLE custom control is now included in the Toolbox. Its tooltip is "Vbsql."

    To add the DB-Library for Visual Basic header file (VBSQL.BAS) to your project
  1. From the File menu, choose Add File.

    The Add File dialog box appears.

  2. Select the VBSQL.BAS file. By default, it is located in the C:\MSSQL\DBLIB\INCLUDE directory.
  3. Choose the OK button.

    The Project window now includes the VBSQL.BAS module. Visual Basic will automatically generate a unique name for this module. For a new project, the default name for this module will be "Module1."

It is recommended that you not change the VBSQL.BAS header file. If you use the Visual Basic Code window to edit the VBSQL.BAS header file, Visual Basic will add a line to the top of the file similar to the following:

Attribute VB_Name = "Module1"
  

The Visual Basic Code window does not display this line. After this line has been added, Visual Basic will use the specified module name, and will not automatically generate a unique name. If your project already includes a module with the same name as the modified VBSQL.BAS header file, attempting to add it will generate the following error:

Name conflicts with existing module, project, or object library
  

If you must change the VBSQL.BAS header file, use either Notepad (or other text editor that will not add the VB_Name line to the file), or make a copy of the VBSQL.BAS header file and include that copy in your project.

    To add the DB-Library for Visual Basic OLE custom control to a form in your project
  1. From the Toolbox, select the DB-Library for Visual Basic OLE custom control.
  2. Move the pointer onto a form.

    The pointer becomes a cross hair.

  3. Drag the cross hair pointer to place the control on the form.

    The control will be called "Vbsql1" by default.

  4. You can set the Visible property of the control to False.

Add one and only one control to a single form in your project, and always keep that form loaded. Do not add the DB-Library for Visual Basic OLE custom control to more than one form, and do not unload the form that contains the control.

The DB-Library for Visual Basic OLE custom control has two custom event procedures:

Event Occurs
Error When a DB-Library error occurs
Message When a SQL Server message is received

    To edit the code in the error handling and message handling event procedures
  1. Double-click the DB-Library for Visual Basic OLE custom control.

    The Visual Basic Code window appears.

  2. From the Proc box, select Error to bring up the DB-Library error handler event procedure.
  3. From the Proc box, select Message to bring up the SQL Server message handler event procedure.

The Error event procedure has the following syntax:

Private Sub Vbsql1_Error (
ByVal
SqlConn As Long,
ByVal
Severity As Long,
ByVal
ErrorNum As Long,
ByVal
ErrorStr As String,
ByVal
OSErrorNum As Long,
ByVal
OSErrorStr As String,
RetCode As Long )

The OSErrorNum and OSErrorStr parameters are new with the DB-Library for Visual Basic OLE custom control, and they match the parameters that are available with DB-Library for C.

The Message event procedure has the following syntax:

Private Sub Vbsql1_Message (
ByVal
SqlConn As Long,
ByVal
Message As Long,
ByVal
State As Long,
ByVal
Severity As Long,
ByVal
MsgStr As String,
ByVal
ServerNameStr As String,
ByVal
ProcNameStr As String,
ByVal
Line As Long )

The ServerNameStr, ProcNameStr, and Line parameters are new with the DB-Library for Visual Basic OLE custom control, and they match the parameters that are available with DB-Library for C.

Note that Visual Basic will create a VBSQL.OCA file, usually in the same directory as VBSQL.OCX. Visual Basic stores cached-type library information (and other data that is specific to the custom control) in the VBSQL.OCA file and re-creates it as needed.

For more information about managing Visual Basic projects, see the Microsoft Visual Basic 4.0 Programmer's Guide.