Excel VBA Connection String for Azure

jay1983

New Member
Joined
Jul 29, 2021
Messages
1
Office Version
  1. 365
Platform
  1. Windows
Hello – I am struggling to replicate a db connection that was previously sybase using DSN and now azure

my old connection string was:
Sub PullData_Click()
Dim SSN As String
SSN = Range("G7")
Application.ScreenUpdating = False
'Clear Contents
Range("S2:x5000").Select
Selection.ClearContents

With ActiveSheet.QueryTables.Add(Connection:="ODBC;DSN=ddd_new;DB=DDD1;UID=****;PWD=*****", Destination:=Range("S2"))
CommandText = "SELECT t_......

so i had a DSN set up that it was referencing --- i'm trying to keep the format of the query (written years and years ago so prob not efficient --"
here's my new connection string:

With ActiveSheet.QueryTables.Add(Connection: = "Driver={ODBC Driver 17 for SQL Server};Server=tcp:<server>,1433;database=dddprod;Uid=****;Pwd=****;Encrypt=yes;TrustServerCertificate=no;Connection Timeout=30;Authentication=ActiveDirectoryPassword;ApplicationIntent=ReadOnly;", Destination:=Range("S2"))
.CommandText = "SELECT t_.......

i get a run time error 5 with invalid procedure call. I tried taking out the ODBC, tried using just 'connection' --- maybe it can't be replicated -- i dont want to go back to the DSN route if i dont have to, cant get it to connect and run the select query.

thanks
 

Excel Facts

Copy PDF to Excel
Select data in PDF. Paste to Microsoft Word. Copy from Word and paste to Excel.

Forum statistics

Threads
1,215,025
Messages
6,122,731
Members
449,093
Latest member
Mnur

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top