简体   繁体   English

SQL Server连接字符串导致错误?

[英]SQL Server connection string causing error?

In a Winforms application, I have a connection string that causes an error 在Winforms应用程序中,我有一个导致错误的连接字符串

data source=(local);initial catalog=RegisterDB;persist security info=False

Error: 错误:

An unhandled exception of type 'System.Data.SqlClient.SqlException' occurred in System.Data.dll System.Data.dll中发生了类型为'System.Data.SqlClient.SqlException'的未处理的异常

Additional 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: Named Pipes Provider, error: 40 - Could not open a connection to SQL Server) (提供者:命名管道提供程序,错误:40-无法打开与SQL Server的连接)

Thanks for the help Arif Ansari but it still gives the same error. 感谢您的帮助Arif Ansari,但它仍然给出相同的错误。

I'm using Microsoft Visual Studio 2013 Express with SQL Server. 我正在将Microsoft Visual Studio 2013 Express与SQL Server一起使用。 I created the database from within Microsoft Visual Studio 2013 Express 我从Microsoft Visual Studio 2013 Express内部创建了数据库

Can anyone help? 有人可以帮忙吗?

Hi marc_s 嗨marc_s

Sorry it didnt work. 对不起,它没有用。 I created the Database RegisterDB manually with Microsoft Visual Studio 2013 Express in server "(localdb)\\v11.0" 我使用服务器“(localdb)\\ v11.0”中的Microsoft Visual Studio 2013 Express手动创建了数据库RegisterDB

Can anyone help ??????? 谁能帮忙???????

请尝试一下

 SqlConnection con = new SqlConnection("Data Source=(local);Database=RegisterDB;Integrated Security= true");

try this query as your connection string format 尝试将此查询作为您的连接字符串格式

Server=myServerName\myInstanceName;Database=myDataBase;User Id=myUsername;
Password=myPassword;

or this 或这个

Server=myServerAddress;Database=myDataBase;Trusted_Connection=True;

basically check the instance of the server that you are running. 基本上检查您正在运行的服务器的实例。

Check if the instance service is running or not. 检查实例服务是否正在运行。 Type services.msc in the start menu to open the Services List. 在开始菜单中键入services.msc以打开“服务列表”。 Check for the name SQL SERVER (your instance name) . 检查名称SQL SERVER(您的实例名称) If the instance status is Started , issue is in your connection string or user permissions. 如果实例状态为已启动 ,则问题出在您的连接字符串或用户权限中。 Else if the status is empty or stopped, start the instance and then try connecting. 否则,如果状态为空或已停止,请启动实例,然后尝试连接。

you may also refer this site for connection string format. 您也可以参考本网站的连接字符串格式。

The SQL Server that comes with Visual Studio 2013 is the 2012 Express version - and that by default install the "LocalDB" support. Visual Studio 2013附带的SQL Server是2012 Express版本-默认情况下安装“ LocalDB”支持。

So I would try this connection string instead: 因此,我将尝试使用此连接字符串:

"data source=(localdb)\v11.0;initial catalog=RegisterDB;Integrated Security=SSPI;"

Does that work? 那样有用吗? If not: are you auto-creating the database, or if not, did you manually create that database RegisterDB that you're referencing in the connection string? 如果不是:您是在自动创建数据库,还是在不是,是否手动创建了在连接字符串中引用的数据库RegisterDB

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

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