帮助关于连接字符串 [英] help about Connection String

查看:86
本文介绍了帮助关于连接字符串的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



i使用此连接字符串



hi ,
i use this connection string

string sip = serverIP.Text;
            SqlConnection connection = new SqlConnection("network library = dbmssocn ; Data Source=" + sip + " ;Initial Catalog= Parking_Database ;Integrated Security=True");
            connection.Open();





但是当运行程序时显示错误:



建立与SQL Server的连接时发生与网络相关或特定于实例的错误。服务器未找到或无法访问。验证实例名称是否正确,以及SQL Server是否配置为允许远程连接。 (提供者:命名管道提供者,错误:40 - 无法打开与SQL Server的连接)



问题是什么???



but when run program this error shown :

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)

what the problem ???

推荐答案

很难(如果不是不可能)从这些信息中辨别出来。



所以,自己修理吧!要做的第一件事就是找出你正在使用的字符串:所以稍微改变你的代码:

Difficult (if not impossible) to tell from that information.

So, fix it yourself! The first thing to do is to find out exactly what string you are using: so change your code slightly:
string sip = serverIP.Text;
string strCon = "network library = dbmssocn ; Data Source=" + sip + " ;Initial Catalog= Parking_Database ;Integrated Security=True";
SqlConnection connection = new SqlConnection(strCon);
connection.Open();



使用调试器在创建新SqlConnection之前立即检查strCon变量的内容,或者将其记录到输出中稍后阅读 - 日志文件,或者控制台很好。

然后,尝试使用Server Explorer窗格在VS中建立连接:

1)打开服务器资源管理器。

2)右键单击数据连接并选择添加连接

3)在随后的对话框中,选择您的数据源和数据库,指定安全信息,并按测试连接按钮。

4)当连接正常时,按确定

5)在服务器资源管理器窗格中突出显示数据库,然后查看在属性窗格中。将显示连接字符串的工作示例,您可以将其复制并粘贴到您的应用程序或配置文件中。



将其与您正在使用的字符串进行比较,以及问题可能会变得更加清晰。


either use the debugger to examine the content of the "strCon" variable immediately before the new SqlConnection is created, or log it to an output where you can read it later - a log file, or teh console is fine.
Then, try setting up a connection in VS with the Server Explorer pane:
1) Open Server Explorer.
2) Right click "Data connections" and select "Add connection"
3) In the dialog that follows, select your DataSource, and database, specify the security info, and press the "Test connection" button.
4) When the connection works, press "OK"
5) Highlight your database in the Server Explorer pane, and look at the Properties pane. A working example of the connection string will be shown, which you can copy and paste into your app or config file.

Compare that to the string you are using, and the problem may become clearer.


这篇关于帮助关于连接字符串的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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