如何使用C#.net中的连接字符串连接到远程数据库 [英] How to connect to the Remote Database using Connection String in C#.net

查看:68
本文介绍了如何使用C#.net中的连接字符串连接到远程数据库的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何使用C#.net中的连接字符串连接到远程数据库
我想使用C#.net中的Sql Connection String连接远程数据库,我正在尝试执行该操作,但连接失败.

 SqlConnection connect =  SqlConnection(" ); 


出现以下错误

与SQL Server建立连接时发生与网络相关或特定于实例的错误.找不到服务器或无法访问该服务器.请验证实例名称正确并且已配置SQL Server允许远程连接.(提供程序:SQL网络接口,错误:26 –错误指定了服务器/实例的位置)"


在sqlserver中启用了TCP/IP.

解决方案

检查以下链接以查看用于连接到SQL 2008的其他选项:

http://www.connectionstrings.com/sql-server-2008 [ http://blogs.msdn.com/b/sql_protocols/archive/2007/05/13/sql-network-interfaces-error-26-error-locating-server-instance-specified.aspx

检查

1. SQL Server是否可以接受远程连接?
在您的SQL Server Management Studio中,右键单击数据库,然后选择属性",然后单击左侧的连接",然后选中允许对此服务器进行远程连接"复选框.


2.是否可以Ping?在命令提示符下

ping SERVER


3.您的实例名称是否正确?
4.是否在防火墙上打开了端口以连接SQL Server

http://support.microsoft.com/kb/287932 [SqlConnection connect = new SqlConnection("server=SERVER\\MSSQLSERVER2008; Database = DataConverter; Trusted_Connection = True");


getting the following error

"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) "


ienabled TCP/IP in the sqlserver. Does it mean that remote system and local system not in network?

Check the following link to see different options for connecting to SQL 2008:

http://www.connectionstrings.com/sql-server-2008[^]


Have a look at this.

http://blogs.msdn.com/b/sql_protocols/archive/2007/05/13/sql-network-interfaces-error-26-error-locating-server-instance-specified.aspx


Check

1. Whether th SQL server can accept remote connection ?
In your SQL server management studio right click on the database and select "properties" and the click on "connection" in the left hand side and make you the check box "Allow remote conenctions to this servers" is ticked


2. Whether you can ping ?

ping SERVER

in the command prompt
3. Whether your instance name is correct ?
4. Whether the ports are opened on the firewalls to connect the SQL server

http://support.microsoft.com/kb/287932[^]


这篇关于如何使用C#.net中的连接字符串连接到远程数据库的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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