Automating ADO/ODBC connection

gayjaybird

New Member
Joined
Aug 6, 2007
Messages
39
I have a client with an excel spreadsheet that is based on several ODBC queries. He is writing a macro to automate the data refresh. He has the username/password for the server coded in the connection string as described on Microsoft's support site: "DSN=<dsn name>; UID=<userid>; PWD=<password>;" and the password is saved in the ODBC connection as well. However, when he runs the Macro to refresh, it still prompts him for the password as it refreshes each query. The username populates correctly but the password field stays blank. Any ideas?
 

Excel Facts

Create a chart in one keystroke
Select the data and press Alt+F1 to insert a default chart. You can change the default chart to any chart type
Ok, here's the code we're using:

Code:
Sub Refresh_Data()
'
' Macro1 Refresh_Data
'
Dim cnt As ADODB.Connection
Dim rst As ADODB.Recordset

Const stCon As String = "DSN=HDReader;Uid=AR$Reader; Pwd=RE@d-0nly;"

Set cnt = New ADODB.Connection
Set rst = New ADODB.Recordset
cnt.ConnectionString = "DSN=HDReader;Uid=AR$Reader; Pwd=RE@d-0nly;"
cnt.Properties("prompt") = adPromptNever
cnt.Open

' Unhide sheets
    Sheets("Group Name").Visible = True
    Sheets("Categories_All").Visible = True
    Sheets("Categories_CHG").Visible = True
    Sheets("Categories_HDC").Visible = True
    Sheets("Categories").Visible = True
    Sheets("Business Impact").Visible = True
    Sheets("Extent of Damage").Visible = True
    Sheets("SHR_Location_Query").Visible = True
    Sheets("Reference").Visible = True
'Update data
    Sheets("Extent of Damage").Select
    Range("A3").Select
    Selection.QueryTable.Refresh BackgroundQuery:=False
    Sheets("Business Impact").Select
    Range("A3").Select
    Selection.QueryTable.Refresh BackgroundQuery:=False
    Sheets("Categories_HDC").Select
    Range("A1").Select
    Selection.QueryTable.Refresh BackgroundQuery:=False
    Sheets("Categories_CHG").Select
    Range("A1").Select
    Selection.QueryTable.Refresh BackgroundQuery:=False
    Sheets("Categories_All").Select
    Range("A1").Select
    Selection.QueryTable.Refresh BackgroundQuery:=False
    Sheets("SHR_Location_Query").Select
    Range("A3").Select
    Selection.QueryTable.Refresh BackgroundQuery:=False
    Sheets("Group Name").Select
    Range("A3").Select
    Selection.QueryTable.Refresh BackgroundQuery:=False
' Hide sheets
    Sheets("Group Name").Select
    ActiveWindow.SelectedSheets.Visible = False
    Sheets("Categories_All").Select
    ActiveWindow.SelectedSheets.Visible = False
    Sheets("Categories_CHG").Select
    ActiveWindow.SelectedSheets.Visible = False
    Sheets("Categories_HDC").Select
    ActiveWindow.SelectedSheets.Visible = False
    Sheets("Categories").Select
    ActiveWindow.SelectedSheets.Visible = False
    Sheets("Business Impact").Select
    ActiveWindow.SelectedSheets.Visible = False
    Sheets("Extent of Damage").Select
    ActiveWindow.SelectedSheets.Visible = False
    Sheets("SHR_Location_Query").Select
    ActiveWindow.SelectedSheets.Visible = False
    Sheets("Reference").Select
    ActiveWindow.SelectedSheets.Visible = False

' rst.Close

cnt.Close
End Sub

Even though we've got the password specified in the Conneciton string, it still prompts us for the password! Any ideas?
 
Upvote 0

Forum statistics

Threads
1,214,659
Messages
6,120,785
Members
448,992
Latest member
prabhuk279

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