简体   繁体   English

在Visual Studio中使用LocalDB

[英]Using LocalDB with Visual Studio

I have Visual Studio 2015 installed and I created a sample application from some Microsoft tutorial. 我安装了Visual Studio 2015,并从一些Microsoft教程创建了一个示例应用程序。

This is the connection string I got in web.config : 这是我在web.config获得的连接字符串:

<add name="DefaultConnection" 
     connectionString="Data Source=(localdb)\MSSQLLocalDB;AttachDbFilename=|DataDirectory|\aspnet-GeekQuiz-20160203041206.mdf;Initial Catalog=aspnet-GeekQuiz-20160203041206;Integrated Security=True" 
     providerName="System.Data.SqlClient" />

But it doesn't work, this is the error I got: 但这不起作用,这是我得到的错误:

A network-related or instance-specific error occurred while establishing a connection to SQL Server. 建立与SQL Server的连接时发生与网络相关或特定于实例的错误。 The server was not found or was not accessible. 服务器未找到或无法访问。 Verify that the instance name is correct and that SQL Server is configured to allow remote connections. 验证实例名称正确,并且已将SQL Server配置为允许远程连接。

Should I install SQL Server Express separately or I got it along with Visual Studio? 我应该单独安装SQL Server Express还是将其与Visual Studio一起安装?

I usually use the next trick to set the correct connectionString in the Web.config: 我通常使用下一个技巧在Web.config中设置正确的connectionString:

In Visual Studio, go to the “SQL Server Object Explorer” label, right-click on the Database you wish to use and click on “Properties”. 在Visual Studio中,转到“ SQL Server对象资源管理器”标签,右键单击要使用的数据库,然后单击“属性”。 Then get the string in the “Connection string” field. 然后在“连接字符串”字段中获取字符串。

Try giving permissions to SQL server on the directory of App_Data. 尝试在App_Data目录上授予SQL Server权限。 Go to properties->Security->Edit->Add and add the sql server instance name. 转到“属性”->“安全性”->“编辑”->“添加”,然后添加sql服务器实例名称。 It is usually NT Service\\MSSQL$InstanceName. 通常是NT Service \\ MSSQL $ InstanceName。 You can find instance name from sql server configuration manager-> Under SQL Server Network Configuration. 您可以从SQL Server配置管理器->在“ SQL Server网络配置”下找到实例名称。 If this doesn't help, then try adding PC Name\\Users. 如果这样做没有帮助,请尝试添加PC名称\\用户。 It should work after that 在那之后它应该工作

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何在 visual studio 中使用 localDB(MDF) 重新播种数据库中的标识列 - How to reseed identity column in database using localDB(MDF) in visual studio 未使用 Visual Studio 19 中的实体框架将数据添加到 LocalDB - Data not getting added to LocalDB using Entity Framework in Visual Studio 19 Visual Studio 2015中无法识别LocalDB - LocalDB not recognized in Visual Studio 2015 使用Visual Studio和NUnit连接到localdb - Connecting to localdb with Visual Studio and NUnit 在 Visual Studio 中选择 LocalDB 版本 - Choose LocalDB version in Visual Studio Entity Framework 5中的Visual Studio 2010是否支持LocalDB? - Is LocalDB supported by Visual Studio 2010 in Entity Framework 5? Visual Studio 2015中缺少LocalDB吗? - LocalDB missing from Visual Studio 2015? 使用SQL Server 2014 LocalDB和Visual Studio 2013的LightSwitch构建失败 - LightSwitch build fails using SQL Server 2014 LocalDB and Visual Studio 2013 C#Visual Studio:将列添加到localdb重设所有数据 - C# Visual studio : adding columns to localdb reset all data 关闭Visual Studio后,localDB中添加的行消失了还是无法查询? - Added rows in localDB disappear after closing Visual Studio or cannot be queried?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM