troubleshooting Question

SQL server ODBC connection, DSN works, direct connection does not

Avatar of capsoftuk
capsoftukFlag for United Kingdom of Great Britain and Northern Ireland asked on
Microsoft SQL Server.NET Programming
10 Comments1 Solution4135 ViewsLast Modified:
I'm trying to create a test application that connects to a database.
Unfortunately, I do not have access to the site where this is to be deployed and I don't have access to the database so I'm having to send it to someone else to test.
I'm also not 100% sure if the database is SQL Server 2000 or 2005, although I'm pretty sure it's 2005.
This is being done in .NET 2.0 (C#)

The initial tests were successful using a system DSN that's already set up and an OdbcConnection.
OdbcConnection dbConn = new OdbcConnection(ConnectionStringTextBox.Text)

The connection string being used was
Dsn=dsnname;persist security info=False;

However we can't seem to get it to connect using a direct connection.
When using this connection string:
Driver={SQL Server};Server=sqlServerInstance;Database=dbName;Persist Security Info=False;Trusted_Connection=Yes;

We get the error:
ERROR [08001] [Microsoft][ODBC SQL Server Driver][DBNETLIB]SQL Server does not exist or access denied.
ERROR [01000] [Microsoft][ODBC SQL Server Driver][DBNETLIB]ConnectionOpen (Connect()).
ERROR [01S00] [Microsoft][ODBC SQL Server Driver]Invalid connection string attribute

And if we try:
Driver={SQL Native Client};Server=sqlServerInstance;Database=dbName; Trusted_Connection=yes;

We get the error:
ERROR [IM002] [Microsoft][ODBC Driver Manager] Data source name not found and no default driver specified

So, what am I doing wrong with the connection string?
Or should I be using something other than OdbcConnection and using a completely different connection string, perhaps one that specifies the Provider?
Join the community to see this answer!
Join our exclusive community to see this answer & millions of others.
Unlock 1 Answer and 10 Comments.
Join the Community
Learn from the best

Network and collaborate with thousands of CTOs, CISOs, and IT Pros rooting for you and your success.

Andrew Hancock - VMware vExpert
See if this solution works for you by signing up for a 7 day free trial.
Unlock 1 Answer and 10 Comments.
Try for 7 days

”The time we save is the biggest benefit of E-E to our team. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange.

-Mike Kapnisakis, Warner Bros