I am trying figure out what needs to go in the connection string for SQL server via VBA.
This is the code I have right now,
Sub ConnectSqlServer()
Dim conn As ADODB.Connection
Dim rs As ADODB.Recordset
Dim sConnString As String
' Create the connection string.
sConnString = "Provider=SQLOLEDB;Data Source=INSTANCE\SQLEXPRESS;" & _
"Initial Catalog=MyDatabaseName;" & _
"Integrated Security=SSPI;"
' Create the Connection and Recordset objects.
Set conn = New ADODB.Connection
Set rs = New ADODB.Recordset
' Open the connection and execute.
conn.Open sConnString
'Do my stuff here
If CBool(conn.State And adStateOpen) Then conn.Close
Set conn = Nothing
Set rs = Nothing
End Sub
Problem is I don't know what to put in the Connection string. My full File Path is this.
C:\Program Files\Microsoft SQL Server\MSSQL12.SQLEXPRESS\MSSQL\DATA\Staff_Manager.mdf
Can someone tell what needs to go with the,
"Provider"
"Source"
"Initial Catalog"
Thanks.
Please see this link.
http://www.connectionstrings.com/
Also, see this sample script, which works perfectly fine for me.
Server_Name = YOUR SERVER NAME or SERVER IP in double quotes for example "192.168.0.89,1433" in the case of SQL SERVER
The server name is the name that you put when you install it or try:
.\SQLEXPRESS