简体   繁体   English

Visual Studio 2013中的本地数据库连接错误

[英]Connection of local database error in Visual Studio 2013

I have an error in Visual Studio 2013. I use SQL Server 2017 and Visual Studio. 我在Visual Studio 2013中出错。我使用SQL Server 2017和Visual Studio。 I want to create a local database in my asp.net project. 我想在我的asp.net项目中创建一个本地数据库。 The problem is that when I connect to the local database with application in web config file, connection is created but when I try to open database I get an error 问题是,当我使用Web配置文件中的应用程序连接到本地数据库时,会创建连接,但是当我尝试打开数据库时出现错误

The attempt to attach to the database failed with the following information: 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配置为允许远程连接。 (provider: SQL Network Interfaces, error: 50 - Local Database Runtime error occurred. The specified LocalDB instance does not exist. ) (提供者:SQL网络接口,错误:50-发生本地数据库运行时错误。指定的LocalDB实例不存在。)

This is my connection string 这是我的连接字符串

<connectionStrings>
    <add name="Db" 
         connectionString="Server=(localdb)\MSSQLLocalDb;Integrated Security=true;AttachDbFileName=|DataDirectory|\cmsShoppingCart.mdf;"
         providerName="System.Data.SqlClient" />   
</connectionStrings>

I also read many articles and using techniques like enable SQL Server etc but nothing would be happen. 我也阅读了许多文章,并使用了诸如启用SQL Server等技术,但没有任何反应。

Thanks in advance if you help me out. 预先感谢您的帮助。

something is not correct in your connectionstring. 您的连接字符串中有些错误。 First Try to create your connection using Visual Studio Tool : 首先尝试使用Visual Studio Tool创建连接:

* Tools -> Connect To DataBase * *工具->连接到数据库*

In DataSource Selection, Select " MS SQL Server " And Click Continue, FilL The Next Page With Your Database Information And After That, Test Your Information Using " Test Connection " Button. 在“数据源选择”中,选择“ MS SQL Server ”,然后单击“继续”,使用数据库信息填写下一页,然后,使用“ 测试连接 ”按钮测试您的信息。 If It Says "Test Connection Succeeded", Click On " Advanced " Button And You Will See Correct "Connection String" For Yourself at the End Of The Page now Opened. 如果显示“测试连接成功”,则单击“ 高级 ”按钮,您将在现在打开的页面末尾看到正确的“连接字符串”。

I am thinking of three scenarios that you might be in : 我正在考虑您可能会遇到的三种情况:

  1. You are trying to connect to the Wrong Instance of SQL Server( check here for more ) 您正在尝试连接到错误的SQL Server 实例请在此处查看更多信息
  2. You don't have the SQL Database engine installed (Instead you may have only installed SQL Server Management Studio, so download the version you want accordingly from Microsoft site) 没有安装SQL数据库引擎 (相反,您可能只安装了SQL Server Management Studio,因此请从Microsoft网站下载所需的版本)
  3. The SQL Server services are not running ( more about it ) SQL Server服务未运行( 有关它的更多信息

You could also use the SQL server express localDB, but first you need to find out the version of it in order to use its exact instance. 您还可以使用SQL Server Express LocalDB,但是首先您需要找出它的版本才能使用其确切实例。

Say, if the version is 11.0 then your instance would be (localDB)\\v11.0 例如,如果版本为11.0,则您的实例为(localDB)\\ v11.0

To find the version of installed localDB Go to this directory - C:\\Program Files\\Microsoft SQL Server\\110\\Tools\\Binn\\SqlLocalDB.exe (110\\120\\130.. are the versions) 要查找已安装的localDB的版本,请转到以下目录-C:\\ Program Files \\ Microsoft SQL Server \\ 110 \\ Tools \\ Binn \\ SqlLocalDB.exe(版本为110 \\ 120 \\ 130 ..)

Run this command to create and start an instance of localDB(if localDB !Exists) 运行此命令以创建并启动localDB实例(如果localDB!Exists)

"C:\Program Files\Microsoft SQL Server\130\Tools\Binn\SqlLocalDB.exe" create "v13.0" 13.0 -s

Now go to SSMS or VS Server explorer connect to localDB and use an instance which for the above example would look like : localDB\\v13.0 and use windows authentication to access it 现在转到SSMS或VS Server资源管理器,连接到localDB并使用一个实例,对于上面的示例,该实例类似于: localDB \\ v13.0并使用Windows身份验证来访问它

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

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM