SQL 2008服务器连接
嘿有人可以告诉我这里有什么问题吗?
SqlConnection sqlConn = new SqlConnection();
sqlConn.ConnectionString = "server=zekyakad-7727\\sqlexpress.master.dbo;database=master;";
sqlConn.Open(); //error line
错误消息:建立与 SQL Server 的连接时发生与网络相关或特定于实例的错误。找不到服务器或无法访问服务器。验证实例名称是否正确以及 SQL Server 是否配置为允许远程连接。 (提供商:SQL 网络接口,错误:26 - 定位指定的服务器/实例时出错)
hey can someone tell me what is the problem here?
SqlConnection sqlConn = new SqlConnection();
sqlConn.ConnectionString = "server=zekyakad-7727\\sqlexpress.master.dbo;database=master;";
sqlConn.Open(); //error line
Error msg: 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: SQL Network Interfaces, error: 26 - Error Locating Server/Instance Specified)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
我建议您不要以这种方式输入连接字符串,而是按以下方式使用
SqlConnectionStringBuilder
。这不太容易出错。Rather than entering the connectionstring this way, I would suggest you to use the
SqlConnectionStringBuilder
in the following way. This is less error prone.可能有多种原因:
因此:
了解更多具体:
您将连接字符串中的
Server
设置为:这看起来不像服务器的名称。这可能应该是
zekyakad-7727
。查看 connectionstrings.com 以了解有效的连接字符串应是什么样子。
Could be any number of things:
So:
To be more concrete:
You set your
Server
in the connection string to be:This does not look like the name of a server. This should probably be
zekyakad-7727
.Take a look at connectionstrings.com to see what valid connection strings should look like.
检查以下事项。
确保您的数据库引擎配置为接受远程连接
• 开始>所有程序> SQL Server 2005 >配置工具> SQL Server 外围区域配置
• 单击“服务和连接”的“表面区域配置”
• 选择有问题的实例>数据库引擎>远程连接
• 启用本地和远程连接
• 重新启动实例
检查 SQL Server 服务帐户
• 如果您没有使用域帐户作为服务帐户(例如,如果您使用的是 NETWORK SERVICE),您可能需要先切换此帐户,然后再继续
如果您使用的是命名 SQL Server 实例,请确保您是在 ASweb P.NET 应用程序的连接字符串中使用该实例名称
• 通常指定数据库服务器所需的格式为机器名\实例名
• 还要检查您的连接字符串
您可能需要在防火墙上为 SQL Server 实例和您正在使用的端口创建例外
• 开始 >运行>防火墙.cpl
• 单击“例外”选项卡
• 添加 sqlservr.exe(通常位于 C:\Program Files (x86)\Microsoft SQL Server\MSSQL.x\MSSQL\Binn)和端口(默认为 1433)
• 同时检查您的连接字符串
5.如果您使用的是命名的 SQL Server 实例,请确保您在连接字符串中使用该实例名称
6.检查 SQLBrowser;检查它是否正在运行。您可能还需要在防火墙中为 SQLBrowser 创建例外。
7.检查您是否已连接到 SQL Server。请注意您用于连接的内容:机器名称、域名还是 IP 地址?检查连接性时使用此功能。例如,如果您正在使用 myserver
• 开始>运行>指令
•netstat -ano|查找str 1433
•telnet myserver 1433
•ping -a myserver
检查返回的IP 地址是哪些端口。
选择:
如果您仍然无法获得任何连接,您可能需要在服务器上创建一个 SQL 帐户,在相关数据库上创建一个相应的 SQL 用户,然后在您的 Web 应用程序中使用此用户名/密码组合。
Check the following things.
Make sure your database engine is configured to accept remote connections
• 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
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
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
You may need to create an exception on the firewall for the SQL Server instance and port you are using
• Start > Run > Firewall.cpl
• Click on exceptions tab
• Add the sqlservr.exe (typically located in C:\Program Files (x86)\Microsoft SQL Server\MSSQL.x\MSSQL\Binn), and port (default is 1433)
• Check your connection string as well
5.If you are using a named SQL Server instance, make sure you are using that instance name in your connection strings
6.Check SQLBrowser; check that it is running. You may also need to create an exception in your firewall for SQLBrowser.
7.Check that you have connectivity to the SQL Server. Note what you are using to connect: machine name, domain name or IP address? Use this when checking connectivity. For example if you are using myserver
• Start > Run > cmd
•netstat -ano| findstr 1433
•telnet myserver 1433
•ping -a myserver
Check what ports are IP addresses are being returned.
Alternative:
If you still can’t get any connection, you may want to create a SQL account on the server, a corresponding SQL user on the database in question, and just use this username/password combo in your web application.