Quantcast
Channel: Visual Studio and Visual Web Developer Express
Viewing all articles
Browse latest Browse all 3509

Code first database - Can't be opened after creating it.

$
0
0

W8
VS2012
ASP.NET App coded in C#

After running the app once, the database with two tables has been created and I can open it in VS2012, but not in SSMS 2012.

I'm shown in the VS 2012 properties window as the owner of the database.

I'm getting the infamous error 18456 state 38 in the SQL Server log, when I try to open this database in my app, which is supposed to mean the database is missing (it's not missing and the error message states that it cannot open the database ... and points directly to it. 

Here is my code to open the database:

            string strConn = "Server=LAPTOP06\\SQLEXPRESS;Database=~\\App_Data\\MyDataBase.mdf;Trusted_Connection=True;";
            SqlConnection con = new SqlConnection(strConn);
            SqlCommand cmd = new SqlCommand("SELECT * from dbo.clsFinisheds WHERE [Position] = '" + Request.QueryString["ID"] + "'", con);
            cmd.Connection.Open();  <--- Error here.

I've even tried hardcoding the path by moving the project to the c:\root in order to shorten the path (limited to 128 chars), to no avail.


Viewing all articles
Browse latest Browse all 3509

Trending Articles



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