PDA

View Full Version : Connection to cloud based SQL Server database using VBA



agarwaldvk
07-11-2022, 02:41 AM
Hi Guys




I am trying to establish a connection to a cloud based SQL Server database (Azure database) with multi factor authentication.

I successfully created a DSN to it and tested it out manually and it works correctly. However, when I tried to connect to it using VBA code (through Excel (Office 365)) with a connection like the one below it doesn't connect, errors out!





Dim dbConnectStr As String

Dim adoCN As New ADODB.Connection
dbConnectStr = "Driver={ODBC Driver 17 for SQL Server};Server=tcp:azepermsqlgssp1.database.windows.net,1433;Database=gssp-prd-sdb;Encrypt=yes;TrustServerCertificate=no;Authentication=ActiveDirectoryInt egrated"

With adoCN
.CommandTimeout = 0: adoCN.ConnectionTimeout = 0
.CursorLocation = adUseClient
.Open dbConnectStr
End With

But this doesn't work.Is a connection string available that I can try and to connect to it through Excel VBA.



Best regards
Deepak

arnelgp
07-11-2022, 05:00 AM
can you use Power Query to connect?