Dim Cnxn1 As ADODB.Connection
Dim Cnxn2 As ADODB.Connection
Dim Cnxn3 As ADODB.Connection
Dim Cnxn4 As ADODB.Connection
' Open a connection without using a Data Source Name (DSN)
Set Cnxn1 = New ADODB.Connection
Cnxn1.ConnectionString = "rovider='sqloledb';Data Source='MySqlServer';" & _
"Initial Catalog='Pubs';Integrated Security='SSPI';"
Cnxn1.Open
MsgBox "Cnxn1 state: " & GetState(Cnxn1.State)
' Open a connection using a DSN and ODBC tags
' It is assumed that you have create DSN 'Pubs' with a user name as
' 'MyUserId' and password as 'MyPassword'.
Set Cnxn2 = New ADODB.Connection
Cnxn2.ConnectionString = "Data Source='Pubs';" & _
"User ID='MyUserId'assword='MyPassword';"
Cnxn2.ConnectionTimeout = 30
Cnxn2.Open
MsgBox "Cnxn2 state: " & GetState(Cnxn2.State)
' Open a connection using a DSN and OLE DB tags
' It is assumed that you have create DSN 'Pubs1' with windows authentication.
Set Cnxn3 = New ADODB.Connection
Cnxn3.ConnectionString = "Data Source='Pubs1';"
Cnxn3.Open
MsgBox "Cnxn2 state: " & GetState(Cnxn3.State)
' Open a connection using a DSN and individual
' arguments instead of a connection string
' It is assumed that you have create DSN 'Pubs' with a user name as
' 'MyUserId' and password as 'MyPassword'.
Set Cnxn4 = New ADODB.Connection
Cnxn4.Open "ubs", "MyUserId", "MyPassword"
MsgBox "Cnxn4 state: " & GetState(Cnxn4.State)