0

I am unable to connect to my database using VBA:

Sub testSub()
    Dim cn As Object
    Dim cnStr As String
    cnStr = "DRIVER=SQL Server;SERVER=myServerName;Database=myDbName;Trusted_Connection=Yes"
    Set cn = CreateObject("ADODB.Connection")
    With cn
        .ConnectionString = cnStr
        .ConnectionTimeout = 10
        .Open
        If .State = 1 Then
            'rest of code
        End If
    End With
End Sub

the code fails on the .Open line with the error message:

enter image description here

No problems connecting to this database via SSMS. Also, no problems connecting to some other databases using the above VBA. Any idea why it's not allowing me to connect via Excel/VBA and how to fix this, please?

1 Answer 1

3

Use the new Microsoft OLE DB Driver for SQL Server or even the new Microsoft ODBC Driver for SQL Server.

See Using ADO with OLE DB Driver for SQL Server for guidance on updating VB, VBA, and ASP.OLD apps to use the new driver.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.