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.
'BeginProviderVB 'To integrate this code 'replace the data source and initial catalog values 'in the connection strings Public Sub ProviderX() Dim Cnxn1 As ADODB.Connection Dim Cnxn2 As ADODB.Connection Dim Cnxn3 As ADODB.Connection Dim strCnxn As String ' Open a connection using the Microsoft ODBC provider Set Cnxn1 = New ADODB.Connection Cnxn1.ConnectionString = "driver={SQL Server};server=MyServer;uid=sa;pwd=;" Cnxn1.Open strCnxn Cnxn1.DefaultDatabase = "Pubs" ' Display the provider MsgBox "Cnxn1 provider: " & Cnxn1.Provider ' Open a connection using the Microsoft Jet provider Set Cnxn2 = New ADODB.Connection Cnxn2.Provider = "Microsoft.Jet.OLEDB.4.0" Cnxn2.Open "C:\Program Files\Microsoft Office\Office\Samples\northwind.mdb", "admin", "" ' Display the provider. MsgBox "Cnxn2 provider: " & Cnxn2.Provider ' Open a connection using the Microsoft SQL Server provider Set Cnxn3 = New ADODB.Connection Cnxn3.Provider = "sqloledb" Cnxn3.Open "Data Source=MyServer;Initial Catalog=Pubs;", "sa", "" ' Display the provider MsgBox "Cnxn3 provider: " & Cnxn3.Provider ' clean up Cnxn1.Close Cnxn2.Close Cnxn3.Close Set Cnxn1 = Nothing Set Cnxn2 = Nothing Set Cnxn3 = Nothing End Sub 'EndProviderVB
Connection Object | DefaultDatabase Property | Provider Property
© 1998-2001 Microsoft Corporation. All rights reserved.