Reputation: 1865
EDIT 1
I tried creating and using a system DSN. I followed similar steps below resulting in a successful connection attempt. I then modified my connection string to reference this new DSN. I received an error The specified DSN contains an architecture mismatch between Driver and Application.
To resolve, I added an identical DSN using the sysWOW64 odbcad32 exe. My code now completes successfully. This only highlights the problem. The code CAN connect to the system DSN. But when I copy those attributes for a DSNless connection, the code fails. What is wrong with my connectionstring?
end EDIT 1
Why is my connection string failing when it succeeds in setup?
But in my project when I use this connection string "Driver=SQL Server Native Client 11.0;DATABASE=SynchronizerTester;Trusted_Connection=Yes;SERVER=(localdb)\v11.0;"
I get a System.Data.Odbc.OdbcException, named pipes couldn't open the connection etc.
Other articles advise I should use Data Source instead. This advice fails because "server or dsn attributes not specified".
What is different between the Odbc file DSN and my connection string that makes the difference here? Should I be using the Sql* family instead of the Odbc* family in my code? If so, how can I detect which one to use based on the connection string so I can inject the proper types?
Please note, I may be using the same code to work with a variety of connection strings. My original thinking was I would use ODBC libraries as lowest common denominator.
Upvotes: 2
Views: 2591
Reputation: 59
Just adding this here in case anyone else finds it useful: I had the same symptom from a different cause.
In my case the connection string was correct. The problem was that the workstation was not able to resolve the hostname's DNS. The DSN entry somehow managed to work. Perhaps it cached a fully qualified server name or something...? But the connection string failed.
Upvotes: 0
Reputation: 1865
OMG...
I will not be deleting this post because it ought to exist in my SO profile as a shrine to total stupidity... a reminder to strive to become less dumb.
The backslash is an escape character.
Change:
SERVER=(localdb)\v11.0;
To:
SERVER=(localdb)\\v11.0;
Upvotes: 5