Quantcast
Channel: Visual Studio General Questions forum
Viewing all articles
Browse latest Browse all 21115

How do I find the connectionstring for localdb to use in my Visual Studio project?

$
0
0

I created a Visual Basic dot net project in Visual Studio (windows forms) and then did the following

1. opened Server Explorer window

2. Right clicked on data-connections and created a new database

3. In the server name box, I entered (localdb)]mssqllocaldb

4. In the New database name textbox, I entered "EchoDatabase"

5. I right clicked on the new data connection, and selected New Query, and then executed SQL statements that add tables to the database.

This all worked fine.   However, now I need a 'connection string' to the new localdb database I created.   In my code I have statements such as:

      Dim Conn As SqlConnection = New SqlConnection(myConnectionString)

And earlier on, I tried setting 

myConnectionString as follows:

 myConnectionString = "Data Source=(LocalDb)\MSSQLLocalDB;Initial Catalog=EchoDatabase;Integrated Security=SSPI;AttachDBFilename=|DataDirectory|\EchoDatabase.mdf"

This does not work!  I get the following error:

System.Data.SqlClient.SqlException
  HResult=0x80131904
  Message=Cannot attach the file 'C:\gideonwroteprograms\EchoTheory\EchoTheory\bin\Debug\EchoDatabase.mdf' as database 'EchoDatabase'.
  Source=.Net SqlClient Data Provider

What should I be doing?


Viewing all articles
Browse latest Browse all 21115

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>