简体   繁体   English

找不到SQL Server Express 2014的数据库

[英]Cannot find Database for SQL Server Express 2014

Two Questions 两个问题

  1. How do I connect to "SQL Server Express" Database from SQL Management Studio? 如何从SQL Management Studio连接到“ SQL Server Express”数据库?
  2. How do I get my MVC Entity Framework application to connect to my original "SQL Server Express LocalDB " database. 如何使我的MVC实体框架应用程序连接到原始的“ SQL Server Express LocalDB ”数据库。

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。

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数据库?

如何连接到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 我不确定发生了什么

网站与Nuit

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: 跟着这些步骤:

  • Go to Run, start services.msc 转到运行,启动services.msc
  • Look for "SQL Server (....)" entries with running state. 查找具有运行状态的“ SQL Server(....)”条目。 The text inside the bracket is the instance name, if you dont find any such entry then you need to install SQL Server. 括号内的文本是实例名称,如果找不到任何此类条目,则需要安装SQL Server。

2) To connect to Management Studio: 2)要连接到Management Studio:

  • Start Management Studio. 启动Management Studio。
  • In Server Name, type in: .\\(instancename) 在“服务器名称”中,键入: 。\\(实例名称)
  • Instance name is what you see in brackets in step 1. 实例名称就是您在步骤1中的括号中看到的内容。

3) For moving your database from LocalDb to Sql Server: 3)要将数据库从LocalDb移动到Sql Server:

  • Locate your LocalDb database file. 找到您的LocalDb数据库文件。 Typically LocalDb databases are created inside the "C:\\Users(Your Username)" folder. 通常,LocalDb数据库是在“ C:\\ Users(您的用户名)”文件夹中创建的。
  • Copy the MDF and LDF files from above step to some other location, this step is optional. 将上述步骤中的MDF和LDF文件复制到其他位置,此步骤是可选的。
  • Using Management studio, Attach the MDF file from above step to your SQL Server Instance. 使用Management Studio,将上述步骤中的MDF文件附加到SQL Server实例。

4) To use SQL Server Instance in your project: 4)在您的项目中使用SQL Server实例:

  • Change connection to point to your SQL Server Instance instead of LocalDb. 更改连接以指向您的SQL Server实例而不是LocalDb。
  • For Eg: 例如:

  <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.

相关问题 使用存储过程或C#同步SQL Server 2014和SQL Server 2014 Express数据库 - Sync SQL Server 2014 and SQL Server 2014 Express database using stored procedure or C# 无法从Visual Studio 2012连接到SQL Server Express 2014 - Cannot connect to SQL Server Express 2014 from Visual Studio 2012 静默安装 SQL Server 2014 Express - Silent install of SQL Server 2014 Express 无法连接到SQL Server 2014 Express - Can't connect to SQL Server 2014 Express 从C#进行SQL Server 2014 Express Edition数据库备份-SQL错误 - Sql Server 2014 Express Edition database backup from c# - Sql Error Microsoft SQL Server 2014数据库错误 - Microsoft SQL Server 2014 database error 在SQL Server 2014数据库中保存指纹图像 - Saving fingerprint image in sql server 2014 database 如何以编程方式备份​​SQL Server 2014 Express Localdb(.mdf)文件 - How to backup a SQL Server 2014 Express Localdb (.mdf) file programmatically 使用本地帐户登录时无法连接到SQL Server Express 2014 - Unable to connect to SQL Server Express 2014 when signed in with local account 无法从 UWP 应用程序连接到 SQL Server Express 数据库 - Cannot connect to SQL Server Express database from an UWP app
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM