Provider and DefaultDatabase Properties Example

This example demonstrates the Provider property by opening two 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

	' Open a connection using the Microsoft ODBC provider.
	Set cnn1 = New ADODB.Connection
	cnn1.ConnectionString = "driver={SQL Server};" & _
		"server=bigsmile;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

	cnn1.Close
	cnn2.Close

End Sub

© 1997 Microsoft Corporation. All rights reserved.