Cadeia de ligação para o servidor SQL 2014 Express (VBA)

estou a tentar descobrir o que precisa de ir no texto de ligação para o servidor SQL via VBA.

Este é o código que tenho agora.
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
O problema é que não sei o que pôr na corda de ligação. O meu ficheiro completo é este.

C:\Program Files\Microsoft SQL Server\MSSQL12.SQLEXPRESS\MSSQL\DATA\Staff_Manager.mdf
Alguém pode dizer o que é preciso fazer com o ...
"Provider"
 "Source"
 "Initial Catalog"
Obrigado.

Author: Community, 2015-12-21

1 answers

Por favor, Veja este link.

Http://www.connectionstrings.com/

{[[2]}Veja Também este script de exemplo, que funciona perfeitamente para mim.
Sub ADOExcelSQLServer()
     ' Carl SQL Server Connection
     '
     ' FOR THIS CODE TO WORK
     ' In VBE you need to go Tools References and check Microsoft Active X Data Objects 2.x library
     '

    Dim Cn As ADODB.Connection
    Dim Server_Name As String
    Dim Database_Name As String
    Dim User_ID As String
    Dim Password As String
    Dim SQLStr As String
    Dim rs As ADODB.Recordset
    Set rs = New ADODB.Recordset

    Server_Name = "EXCEL-PC\EXCELDEVELOPER" ' Enter your server name here
    Database_Name = "AdventureWorksLT2012" ' Enter your database name here
    User_ID = "" ' enter your user ID here
    Password = "" ' Enter your password here
    SQLStr = "SELECT * FROM [SalesLT].[Customer]" ' Enter your SQL here

    Set Cn = New ADODB.Connection
    Cn.Open "Driver={SQL Server};Server=" & Server_Name & ";Database=" & Database_Name & _
    ";Uid=" & User_ID & ";Pwd=" & Password & ";"

    rs.Open SQLStr, Cn, adOpenStatic
     ' Dump to spreadsheet
    With Worksheets("sheet1").Range("a1:z500") ' Enter your sheet name and range here
        .ClearContents
        .CopyFromRecordset rs
    End With
     '            Tidy up
    rs.Close
    Set rs = Nothing
    Cn.Close
    Set Cn = Nothing
End Sub
 7
Author: , 2015-12-21 19:52:04