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:
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?
