C#sql异常,需要帮助 [英] C# sql exception, help needed

查看:92
本文介绍了C#sql异常,需要帮助的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

每当我单击注册按钮时,我都会收到此异常'建立与SQL Server的连接时发生了与网络相关或特定于实例的错误。服务器未找到或无法访问。验证实例名称是否正确,以及SQL Server是否配置为允许远程连接。 (提供者:命名管道提供程序,错误:40 - 无法打开与SQL Server的连接)'。



SqlConnection con = new SqlConnection(Data Source =。/ SQLEXPRESS; AttachDbFilename = C:/ ... Security = True; Connect Timeout = 30; User Instance = True;);



con.Open();

Whenever i click the register the button i get this exception 'A network-related or instance-specific error occurred while establishing a connection to 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. (provider: Named Pipes Provider, error: 40 - Could not open a connection to SQL Server)'.

SqlConnection con = new SqlConnection("Data Source=./SQLEXPRESS;AttachDbFilename=C:/... Security=True;Connect Timeout=30;User Instance=True; ");

con.Open();

推荐答案





看看这里:

建立与SQL Server的连接时发生网络相关或特定于实例的错误。找不到服务器或无法访问服务器。 [ ^ ]

HTTP://blog.sqlauthority .COM / 2009/05/21 / SQL服务器修复错误提供商,命名管道提供商,错误-40可能未打开,一个连接到SQL服务器,微软SQL服务器-error / [ ^ ]

http://www.technologycrowds.com/2014/02/无法打开连接到sql-server.html [ ^ ]

http://www.mssqltips。 com / sqlservertip / 2340 / resolving-could-not-open-a-connection-to-sql-server-errors / [ ^ ]

http://stackoverflow.com/questions/5435090/sql-server-was -not-found-or-was-not-accessible [ ^ ]

HTTP://计算器。 com / questions / 18060667 / connect-to-server-a-network-related-or-instance-specific-error [ ^ ]
Hi,

Have a look here:
A network-related or instance-specific error occurred while establishing a connection to SQL Server. The server was not found or was not accessible.[^]
http://blog.sqlauthority.com/2009/05/21/sql-server-fix-error-provider-named-pipes-provider-error-40-could-not-open-a-connection-to-sql-server-microsoft-sql-server-error/[^]
http://www.technologycrowds.com/2014/02/could-not-open-connection-to-sql-server.html[^]
http://www.mssqltips.com/sqlservertip/2340/resolving-could-not-open-a-connection-to-sql-server-errors/[^]
http://stackoverflow.com/questions/5435090/sql-server-was-not-found-or-was-not-accessible[^]
http://stackoverflow.com/questions/18060667/connect-to-server-a-network-related-or-instance-specific-error[^]


检查这些东西

1.确保您的数据库引擎配置为接受远程连接(我使用的是集中式数据库)

•开始>所有程序> SQL Server 2005>配置工具> SQL Server表面区域配置

•单击服务和连接的表面区域配置

•选择出现问题的实例>数据库引擎>远程连接

•启用本地和远程连接

•重启实例



2.检查SQL Server服务帐户

•如果您没有使用域帐户作为服务帐户(例如,如果您使用的是NETWORK SERVICE),您可能需要先切换它才能继续使用



3.如果您使用的是命名的SQL Server实例,请确保在ASweb P.NET应用程序的连接字符串中使用该实例名称

•通常是指定数据库服务器所需的格式是machinename \instancename

•检查连接字符串
check these things
1. Make sure your database engine is configured to accept remote connections(I you are using centralized database)
•Start > All Programs > SQL Server 2005 > Configuration Tools > SQL Server Surface Area Configuration
•Click on Surface Area Configuration for Services and Connections
•Select the instance that is having a problem > Database Engine > Remote Connections
•Enable local and remote connections
•Restart instance

2. Check the SQL Server service account
•If you are not using a domain account as a service account (for example if you are using NETWORK SERVICE), you may want to switch this first before proceeding

3.If you are using a named SQL Server instance, make sure you are using that instance name in your connection strings in your ASweb P.NET application
•Usually the format needed to specify the database server is machinename\instancename
•Check your connection string as well


基本上,当您无法连接到SQL Server时,问题可能是:

1)网络问题,

2)SQL Server配置问题。

3)防火墙问题,

4)客户端驱动程序问题,

5)应用程序配置问题。

6)身份验证和登录问题。

Basically, when you failed to connect to your SQL Server, the issue could be:
1) Network issue,
2) SQL Server configuration issue.
3) Firewall issue,
4) Client driver issue,
5) Application configuration issue.
6) Authentication and logon issue.



根据错误消息,您不允许远程访问连接到该机器,所以更改设置中的选项



检查这些

尝试解决SQL连接问题 [ ^ ]

SQ L Server 2005连接问题疑难解答 - 第I部分 [ ^ ]

解决SQL Server 2005中的连接问题 - 第二部分 [ ^ ]

解决SQL Server 2005中的连接问题 - 第III部分 [ ^ ]



BTW检查这一堆也是为了将来的错误


Based on the error message you didn't allow the remote connection to that machine so change the options in settings.

Check these
Steps to troubleshoot SQL connectivity issues[^]
SQL Server 2005 Connectivity Issue Troubleshoot - Part I[^]
Troubleshoot Connectivity Issue in SQL Server 2005 - Part II[^]
Troubleshoot Connectivity Issue in SQL Server 2005 - Part III[^]

BTW check this bunch also for future errors


这篇关于C#sql异常,需要帮助的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆