Reputation: 6872
Two Questions
My Scenario
I have setup my MVC application to use IIS and when I first ran the application it asked me to switch from SQL Server Express LocalDb to SQL Server Express.
The result, I now have no data in the Database as I am now connecting to a new Database Server.
Question 1: How do I connect to SQL Server Express Database from SQL Management Studio?
Question 2: How do I get my MVC Entity Framework application to connect to my original SQL Server Express LocalDB database?
I can connect to the old "SQL Server Express LocalDB" database from a unit test, but when I use the exact same connection string in MVC, I get the new server "SQL Server Express"
Connection String in UnitTest
Unit Test is connecting to LocalDB
<connectionStrings>
<add name="RqDbContext" connectionString="Data Source=(LocalDb)\v11.0;Initial Catalog=Rq;Integrated Security=True;Pooling=false" providerName="System.Data.SqlClient" />
</connectionStrings>
Connection String in Web.config
Web Site is connecting to another database that I can't find
<connectionStrings>
<add name="RqDbContext" connectionString="Data Source=(LocalDb)\v11.0;Initial Catalog=Rq;Integrated Security=True;" providerName="System.Data.SqlClient" />
</connectionStrings>
The image below shows that the Unit Test is writing data from the old LocalDB but the Website which is connected to a Database Server, but it's database is empty.
They are using the same connection strings.
I have used debugger to check the entity framework models and it's clearly a different Database but with the same structure being used.
I'm not sure what is going on
Upvotes: 4
Views: 1157
Reputation: 1127
Four thing you need to do:
1) Check if SQL Server Express is already installed in your PC or not. Follow these steps:
2) To connect to Management Studio:
3) For moving your database from LocalDb to Sql Server:
4) To use SQL Server Instance in your project:
<add name="RqDbContext" connectionString="Data Source=.\sqlexpress;Initial Catalog=Rq;Integrated Security=True;" providerName="System.Data.SqlClient" />
Hope this helps. Cheers!!
Upvotes: 1