VB.net SQL connection string LocalDB

Murray Brown
Murray Brown used Ask the Experts™
on
Hi
What connection string would I use to access my local sql database on my computer. I remember using LocalDB etc
Thanks
Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
Chief Technology Ninja
Distinguished Expert 2018
Commented:
Hi Murray,

From https://www.connectionstrings.com/sql-server/


LocalDB automatic instance
Server=(localdb)\v11.0;Integrated Security=true;


LocalDB automatic instance with specific data file

Server=(localdb)\v11.0;Integrated Security=true;
AttachDbFileName=C:\MyFolder\MyData.mdf;

There are more scenarios supported by LocalDB. You can check them on the link mentioned above.

Regards,
Chinmay.
Most Valuable Expert 2012
Top Expert 2014
Commented:
Here's one that I use in an application that use LocalDB on the target environment. The user selects a specific file, and code uses that for Initial Catalog:

"Data Source=(LocalDB)\BBQSCORING;Initial Catalog=BBQ_Events;Integrated Security=True;MultipleActiveResultSets=True"

It's worked for me for several years. Ovbiously you'd have to change the InstanceName and Initial Catalog to match your own. It works for 2012 and 2014 instances of LocalDB.
Murray BrownASP.net/VSTO Developer

Author

Commented:
thank you

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial