[英]Cannot find Database for SQL Server Express 2014
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. 我已经将MVC应用程序设置为使用IIS,并且在我第一次运行该应用程序时,它要求我从SQL Server Express LocalDb切换到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? 问题1:如何从SQL Management Studio连接到SQL Server Express数据库?
Question 2: How do I get my MVC Entity Framework application to connect to my original SQL Server Express LocalDB database? 问题2:如何使我的MVC实体框架应用程序连接到原始SQL Server Express LocalDB数据库?
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" 我可以通过单元测试连接到旧的“ SQL Server Express LocalDB ”数据库,但是当我在MVC中使用完全相同的连接字符串时,就会得到新的服务器“ SQL Server Express”
Connection String in UnitTest UnitTest中的连接字符串
Unit Test is connecting to LocalDB 单元测试正在连接到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.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. 下图显示了单元测试正在从旧的LocalDB写入数据,但该网站已连接到数据库服务器,但其数据库为空。
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 我不确定发生了什么
Four thing you need to do: 您需要做的四件事:
1) Check if SQL Server Express is already installed in your PC or not. 1)检查您的PC中是否已安装SQL Server Express。 Follow these steps: 跟着这些步骤:
2) To connect to Management Studio: 2)要连接到Management Studio:
3) For moving your database from LocalDb to Sql Server: 3)要将数据库从LocalDb移动到Sql Server:
4) To use SQL Server Instance in your project: 4)在您的项目中使用SQL Server实例:
<add name="RqDbContext" connectionString="Data Source=.\\sqlexpress;Initial Catalog=Rq;Integrated Security=True;" providerName="System.Data.SqlClient" />
Hope this helps. 希望这可以帮助。 Cheers!! 干杯!!
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.