ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Discussion (Misc queries) (https://www.excelbanter.com/excel-discussion-misc-queries/)
-   -   Querying SQL Server from Excel (https://www.excelbanter.com/excel-discussion-misc-queries/126306-querying-sql-server-excel.html)

James C.

Querying SQL Server from Excel
 
Hi,

I am trying to query a SQL database from Excel. I setup the query and it is
working, however, it prompts me each time to input the password for the SQL
Server.

Is there a way to save the SQL Server password in the excel document so that
i don't have to input it each time?

Thanks

[email protected]

Querying SQL Server from Excel
 

James C. wrote:
Hi,

I am trying to query a SQL database from Excel. I setup the query and it is
working, however, it prompts me each time to input the password for the SQL
Server.

Is there a way to save the SQL Server password in the excel document so that
i don't have to input it each time?

Thanks



Be sure sql server is setup in Control panel under Administrative
Tools- DataSources(ODBC)
Where you put in your info, you can substitute stagnant values for
functions if multiple users are using your tool.

Sub GetData()

'SET UP SQL
sql = "Select * from whatever"

'QUERY THE DATA
With ActiveSheet.QueryTables.Add(Connection:= _
"ODBC;DSN=YOURSQLSERVERNAME;UID=YOURUSERNAME;APP=M icrosoft
Office
XP;WSID=YOURCOMPUTERNAME;DATABASE=PUTNAMEOFDATABAS EHERE;Trusted_Connection=Yes"
_
, Destination:=Range("A1"))
.CommandText = sql
.Name = "MySQLQuery"
.FieldNames = True
.RowNumbers = False
.PreserveFormatting = True
.Refresh BackgroundQuery:=False
.Delete
End With
End Sub



All times are GMT +1. The time now is 04:34 AM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
ExcelBanter.com