Connecting to an SQL Server Database : SQLServer « Access « VBA / Excel / Access / Word






Connecting to an SQL Server Database

 
Sub ConnectToSQL_SQLOLEDB()
   Dim conn As ADODB.Connection

   Set conn = New ADODB.Connection
   With conn
      .Provider = "SQLOLEDB"
      .ConnectionString = "Data Source=mySource;" & _
          "database=yourDatabase; UserId=sa; Password=;"
      .Open
   End With
   If conn.State = adStateOpen Then
      Debug.Print "Connection was established."
   End If
   conn.Close
   Set conn = Nothing
End Sub

 








Related examples in the same category

1.Connecting to an SQL Server Using a DSN-less Connection
2.DSN-less connection using the SQLOLEDB provider
3.Creating a SQL Server Connection Object with SQL Server Security
4.Creating a SQL Server Connection Object with Integrated Security
5.Transfer SQLServer database