I’ve created a web application project in Visual Studio 2010 using Entity Framework Code First. I’ve specified where I want my db file to reside using the connection string. However, when I add the database to my project (once it has been automatically created) I cannot run the application without errors ranging from – DB cannot be accessed, authentication errors, cannot drop db as it is in use etc….
Only when I “Detach” database in my solution explorer and run application does it work correctly. Shouldn’t the sql server instance and Visual Studio be able to access DB at the same time or does it require separate instances? I like having the option to view my table data through VS. Is this the norm or am I doing something wrong?
I’ve searched for a few hours now and can’t find a solution. Any help would be appreciated.
Sounds like you’re using the default SQL Express database instance which means only one application can access the database at a time.
SQL Express behaves slightly different from it’s big brother SQL Server. SQL Server is a server that that receives connections from applications where as SQL Express is a runtime that’s part of your application. If you were using SQL Server, your application and your Visual Studio Server Explorer could both have open connections to the server that would then execute queries in a proxy fashion against a Database. With SQL Express the Visual Studio Server Explorer and your ASP.NET Application are both trying to open the Database and execute queries themselves. Hence the locking and errors.
It’s exactly what would happen if you and someone else both tried to open up a Word Doc to edit at the same time.