Reputation: 2309
I created a user data source based on
http://blog.mclaughlinsoftware.com/2012/09/12/sql-server-odbc-osn/
When I try to invoke a powershell script that sends SQL data to EXCEL
$qt = $ws.QueryTables.Add("ODBC;DSN=$DSN", $ws.Range("A1"), $SQL)
if ($qt.Refresh()){
$ws.Activate()
$ws.Select()
}
The EXCEL spreadsheet appears and prompts me for the SAME password that I entered when creating the DSN
And when I go to ODBC Data Source Administrator, select the DSN I created, click "Configure", and keep going "Next", it shows password field is blank
How to I fix this so 1. Password remains in DSN 2. I am not prompted for password everytime I run Powershell script that sends SQL data to EXCEL
Upvotes: 0
Views: 2018
Reputation: 46231
You need to specify the user id and password in the application connection in order to avoid the prompt. The SQL Server ODBC drivers do not store user credentials. I believe you can just specify the credentials in the connection string:
$qt = $ws.QueryTables.Add("ODBC;DSN=$DSN;UID=YourLogin;PWD=YourLoginPassword", $ws.Range("A1"), $SQL)
Note that you should never use the sa
login for routine application data access.
Upvotes: 1