Excel macro connect to database driver error

Posted on 2010-01-12
Medium Priority
Last Modified: 2012-05-08
We have a macro made that has to connect to an sql server/database before proceeding.

But I think there's a driver issue, and I'm not sure what else I can try.

The macro spreadsheet worked before I did a sql management studio on my client PC and now when I run the macro I get an error:

"Unable to connect to the database. Please try again later".

This is the line I'm using:

Const cnct As String = "DRIVER=SQL Native Client;SERVER=SQL001\SQL001;UID=user;PWD=password;Database=sql_001;"

I know the database name and server and credentials are correct, because when I use "Provider=SQLOLEDB.1" in place of "DRIVER-SQL Native Client" I don't get the error and our spreadsheet can continue to run.

What else besides DRIVER or Provider can we use?
Question by:garryshape
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 4
  • 2

Expert Comment

ID: 26298701
i use the following

Provider=SQLOLEDB.1;Integrated Security=SSPI;Persist Security Info=True;Initial Catalog=DATABASEHERE;Data Source=NFP10\DYNAMICS;Use Procedure for Prepare=1;Auto Translate=True;Packet Size=4096;Workstation ID=NFP10;Use Encryption for Data=False;Tag with column collation when possible=False

Expert Comment

ID: 26298707
i do have the native client on SQL 2005, but i dont use it

Accepted Solution

fhillyer1 earned 2000 total points
ID: 26298732
for your SQL Native you can use the following

DRIVER=SQL Native Client;SERVER=NFP10\DYNAMICS;UID=sa;;APP=2007 Microsoft Office system;WSID=NFP10;DATABASE=HTC;

just replace your server and database
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!


Author Comment

ID: 26304943
DRIVER=SQL Native Client;SERVER=NFP10\DYNAMICS;UID=sa;;APP=2007 Microsoft Office system;WSID=NFP10;DATABASE=HTC;

I tried changing to that with specifying my username and server/database, but I still get this "Could not connect to database! Please try again later"

Author Comment

ID: 26305048
I think I found the issue

I went into SQL Server Configuration Manager and expanded the "SQL Native Client Configuration" in the left pane, and under "Client Protocols" there is a TCP/IP listed, and it was "disabled". After I changed this to "enabled" I was able to run the report and it could connect to the database.

Expert Comment

ID: 26305452
good, that you found it, i guess on mine worked because when i configured my SQL i always go to the surface config and enable everthing on the connections except for named pipes

Featured Post

New benefit for Premium Members - Upgrade now!

Ready to get started with anonymous questions today? It's easy! Learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article descibes how to create a connection between Excel and SAP and how to move data from Excel to SAP or the other way around.
If you need to forecast numbers -- typically for finance -- the Windows and Mac versions of Excel 2016 have a basket of tools to get the job done.
This Micro Tutorial will demonstrate in Google Sheets how to use the HYPERLINK function to create live links inside your spreadsheet.
Excel styles will make formatting consistent and let you apply and change formatting faster. In this tutorial, you'll learn how to use Excel's built-in styles, how to modify styles, and how to create your own. You'll also learn how to use your custo…

719 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question