Using SQL Server Native Client to access SQL Server LocalDB

Colin Bowern picture Colin Bowern · Apr 25, 2012 · Viewed 13.1k times · Source

I'm trying to connect to a SQL Server LocalDB instance using the SQL Server Native Client driver. This is because we are looking to use Native Client in our production environment to gain access to the use of subject alternative names on SSL encryption for SQL Server. So far I'm not having much luck - is this a supported scenario? My connection string is:

<add name="Database" connectionString="Driver={SQL Server Native Client};Server=(localdb)\v11.0;Integrated Security=True;AttachDBFileName=|DataDirectory|Database.mdf;" providerName="System.Data.Odbc" />

The error I'm receiving is:

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

Any thoughts on how to connect?

Answer

Aaron Bertrand picture Aaron Bertrand · Apr 25, 2012

In addition to using the 11.0 provider,

  • Did you create an instance of SqlLocalDb?
  • Did you start the instance?
  • If you are not the owner, did you try (localdb)\.\InstanceName?

I recently updated a bunch of content on the following Wiki page:

http://social.technet.microsoft.com/wiki/contents/articles/4609.troubleshoot-sql-server-2012-express-localdb.aspx

Also, your connection string states both native client and ODBC, is this intentional? And are you using AttachDbFilename on purpose?