G
Gidmaestro
Guest
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?
Continue reading...
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?
Continue reading...