I am trying to embed credentials into an Excel 2016 workbook for an account on my SQL Server 2008R2 database that has execute permissions on certain stored procedures to provide end users read-only data. User accounts don't have access to the database itself, the idea is to embed the credentials of this read-only account into an excel spreadsheet and the user will just click "Refresh All" to get the most recent data returned from the stored procedure.
To clarify, I don't care if the user knows the password to the account - that's not an issue. I just don't want them to ever have to type the password to refresh the data.
Here's what I've tried so far in Excel:
I wouldn't think I would enter anything here as I already entered credentials when building the query string but I entered anyways as it seems it's required to enter something. I hand the Excel file over to another user and sure enough access is denied because it's defaulting to their current Windows login to access the database.
What gives? I have a colleague that has an Excel 2010 file where they can go in and edit the connection string properties without issue and their files work. How can I get this to work in Excel 2016?
I would really appreciate any help you guys can provide!
Edit: This question doesn't seem that far off..does anyone know how to do this? I feel like it should be pretty simple.
Go to the SQL Spreads tab in Excel and select Design mode. A list of databases will appear on the right. Chose the database you are using and select an SQL table to update from Excel. From the Columns tab you can fine-tune how your table is presented in Excel.
In Excel, select Data > Queries & Connections, and then select the Queries tab. In the list of queries, locate the query, right click the query, and then select Load To. The Import Data dialog box appears. Decide how you want to import the data, and then select OK.
Select a cell in the external data range. Select Data > Queries & Connections > Connections tab, right click a query in the list, and then select Properties . Select the Usage tab. Select the Enable background refresh check box to run the query in the background.
Better late than never? You need to use the legacy "Microsoft Query" (rather than Power Query) to create the data connection. MS have explicitly removed the ability to store username and password in the connection string (in ODC files - ignored) with Power Query data sources.
To Create:
Get Data > From Other sources > From Microsoft Query
You can access (and edit) the connection string (connection properties -> definition) - and store the password persistently (non-securely) this way.
Also Via VBA (for existing connection)
With ActiveWorkbook.Connections("yourconnection").ODBCConnection
.Connection = _
"ODBC;DRIVER=SQL Server;SERVER=sql2012.servername.com,99999;UID=username;PWD=password"
.SavePassword = True
End With
Would love a method for O365.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With