views:

400

answers:

8

I'm at the end of my rope on this. It should be so simple. I just need to know what's wrong with this connection string:

dbc.open ("Driver={SQL Server}; Data Source = ServerName; Initial Catalog = InitialDB; " "User ID = Username; Password = Password;")

I get this error when running that line:

[Microsoft][ODBC Driver Manager] Data source name not found and no default driver specified

I know ServerName is up and accepting connections, I know InitialDB exists, I know User ID and Password are valid for the database. What am I missing?

A: 

What's with the " " in the middle of the string?

John
A: 

Do you have visual studio?

Connect to the database server, and locate the database you want to connect to.

Right click, select properties. Your connection string to the db is right there. Copy to wherever you want. -- Should be in web config, but you can paste it directly into code if you so desire.

chris
This is Classic ASP
CptSkippy
+3  A: 

In notepad create file anyname.udl - let it be empty. After in explorer click it - you will get a dialog to create OLEDB connection string, select expected driver, and all connection param, ensure that "Allow saving password" = True. Press Ok. Then again open file with notepad. Content is valid connection string

Dewfy
FWIW, this technique omitted the Provider property and thus did not work.
Look at "Advanced"/"All" tab and press Edit value - there are extended properties for provider.
Dewfy
+1  A: 

Try this...

dbc.open ("Provider=SQLOLEDB; Driver={SQL Server}; Data Source = ServerName; Initial Catalog = InitialDB; User ID = Username; Password = Password; Network Library=dbmssocn;")
CptSkippy
I think this got it. Thank you.
@TTT : Are you using an ADODB.connection? What version of SQL Server are you using? Are either Named Pipes or TCP connections disabled?
CptSkippy
Sorry, I deleted my previous comment - I must have screwed something up before. I deleted the entire string and typed it back in using your code block as a guide and it seems to be working now.Making too many mistakes today, I need a nap! Thank you for your help!
+1  A: 

As someone has already pointed out, udl is the best easiest way to create a conn string - here is a link that talks about it. http://www.4guysfromrolla.com/webtech/070400-1.shtml

OpenSource
That would have been great to know about 6 years ago! :)
CptSkippy
A: 

Your connection string appears to be mixing ODBC and OLEDB. I would suggest visiting http://www.connectionstrings.com/ and finding the correct syntax for the desired provider.

Yours: "Driver={SQL Server}; Data Source = ServerName; Initial Catalog = InitialDB; " "User ID = Username; Password = Password;"

ODBC: "Driver={SQL Server};Server=ServerName;Database=InitialDB;Uid=Username;Pwd=Password;"

OLEDB: "Provider=sqloledb;Data Source=ServerName;Initial Catalog=InitialDB;User Id=Username;Password=Password;"

Mayo
+1  A: 

If you are using ADOdb you might want to try

"Provider=SQLNCLI10;Server=SERVER;Database=DATABASE;Uid=USERNAME;Pwd=PASSWORD"

for SQL Server 2008 Native Client or

"Provider=SQLNCLI;Server=SERVER;Database=DATABASE;Uid=USERNAME;Pwd=PASSWORD"

for SQL Server 2005 Native Client.

For ODBC, use

"Driver=SQL Server Native Client 10.0"

for SQL Server 2008 Native Client or

"Driver=SQL Native Client"

for SQL Server 2005 Native Client.

skettler
A: 

www.connectionstrings.com has the answer for you I'm sure :)

The real napster