MDAC 2.5 SDK - ADO


 

Provider and DefaultDatabase Properties Example (VB)

See Also

This example demonstrates the Provider property by opening three Connection objects using different providers. It also uses the DefaultDatabase property to set the default database for the Microsoft ODBC Provider.

Public Sub ProviderX()

   Dim cnn1 As ADODB.Connection
   Dim cnn2 As ADODB.Connection
   Dim cnn3 As ADODB.Connection

   ' Open a connection using the Microsoft ODBC provider.
   Set cnn1 = New ADODB.Connection
   cnn1.ConnectionString = "driver={SQL Server};" & _
      "server=srv;uid=sa;pwd=pwd"
   cnn1.Open strCnn
   cnn1.DefaultDatabase = "Pubs"
   
   ' Display the provider.
   MsgBox "Cnn1 provider: " & cnn1.Provider

   ' Open a connection using the Microsoft Jet provider.
   Set cnn2 = New ADODB.Connection
   cnn2.Provider = "Microsoft.Jet.OLEDB.3.51"
   cnn2.Open "C:\Samples\northwind.mdb", "admin", ""

   ' Display the provider.
   MsgBox "Cnn2 provider: " & cnn2.Provider

   ' Open a connection using the Microsoft SQL Server provider.
   Set cnn3 = New ADODB.Connection
   cnn3.Provider = "sqloledb"
   cnn3.Open "Data Source=srv;Initial Catalog=Pubs;", "sa", ""

   ' Display the provider.
   MsgBox "Cnn3 provider: " & cnn3.Provider

   cnn1.Close
   cnn2.Close
   cnn3.Close

End Sub