简体   繁体   English

从Web表单连接到SQL Server时出错

[英]Error in Connecting to SQL Server from a web form

I want to connect SQL Server in my webform program. 我想在我的Webform程序中连接SQL Server。

I use this command : 我使用以下命令:

Connection = new SqlConnection("server=sharmi-PC/MSSQL2012;database=PeopleDb;trusted_connection=true");

but I get an error : 但我得到一个错误:

An unhandled exception of type 'System.Data.SqlClient.SqlException' occurred in PeopleManagement.BusinessLogic.dll PeopleManagement.BusinessLogic.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的连接)

My server name in SQL Server is 我在SQL Server中的服务器名称是

sharmi-PC\MSSQL2012

If you say yourself that your server name is 如果您说自己的服务器名称是

sharmi-PC\MSSQL2012

then why aren't you using that in your connection?? 那为什么不在连接中使用它呢?

Use this: 用这个:

Connection = new SqlConnection(@"server=sharmi-PC\MSSQL2012;database=PeopleDb;trusted_connection=true");

Use the proper notation for server/instance name - a backslash (as in sharmi-PC\\MSSQL2012 ) - not a forward slash as you used ( sharmi-PC/MSSQL2012 ) .... 对服务器/实例名称使用正确的符号- 反斜杠 (如sharmi-PC\\MSSQL2012 )-而不是您使用的正斜杠( sharmi-PC/MSSQL2012 )...。

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

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