2

I have VBA code that uses a connection string to talk to an SQL Server. I would like to use an external DSN file for this connection, purely for the adaptability.

The current code:

Set cn = New ADODB.Connection
Set rs = New ADODB.Recordset
strConn = "DRIVER=SQLServer;SERVER=x;APP=Microsoft Excel;DATABASE=x;Trusted_Connection=Yes"
cn.Open strConn

The code works, but for our users a dsn file would be more appropriate.

The .DSN File:

[ODBC]
DRIVER=SQL Server
Database=x
APP=Microsoft Office 2013
Trusted Connection=Yes
SERVER=x
Description=x

1 Answer 1

2

You can use the File Name qualifier to specify a UDL or DSN file. For example:

cn.Open "File Name=c:\path\to\my.dsn;"
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.