0

i wokring in windows form and make a complete project in vb.net with sql server 2014.i mae connection in this way on form load event.

   Dim con As New SqlConnection
   Dim cmd As New SqlCommand
   con.ConnectionString = "data source=(localdb)\\MSSQLLocalDB;initial 
   catalog=LoginDB;integrated security=true"
   cmd.Connection = con
   con.Open()

when i use my computer name in datasource then it working correctly.but when i use "localdb" in datasource as show in code for creating setup then connection can not be created and araise error while opening the connection..what should i do????

1 Answers1

0

Normally, when you define the datasource, you specify there the COMPUTERNAME in case of SQL Server has been installed on the default instance.

Or you specify COMPUTERNAME\INSTANCENAME in case of SQL Server has been installed on a named instance.

If you use the COMPUTERNAME alone and it works, your SQL Server is installed on your computer on the default instance (Without Instance Name). So this is the way you need to work.

Or maybe you have installed the default instance, but where you want to connect is to your (localdb) instance, in that case, you need to check if your localdb has been correctly installed and if you are using the correct data in datasource. For that you could see this post where all this checks are covered: What is the connection string for localdb for version 11

Jortx
  • 707
  • 1
  • 7
  • 22