[英]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.