连接服务器故障 [英] Connecting to a server trouble

查看:78
本文介绍了连接服务器故障的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在使用Microsoft Server 2008将数据库连接到Windows应用程序时遇到了麻烦.使用本地连接字符串时,我没有收到任何错误,并且程序运行正常,因此我知道其与连接字符串有关的问题我完全看不到了.

将连接字符串更改为基于ip的连接字符串时出现的错误是:


与指定的绑定约束匹配的对类型为"CalorieCounter.MainWindow"的构造函数的调用引发了异常."行号"4"和行位置"9".

建立与SQL Server的连接时发生与网络相关或特定于实例的错误.服务器未找到或无法访问.验证实例名称正确,并且已将SQL Server配置为允许远程连接. (提供者:TCP提供程序,错误:0-无法建立连接,因为目标计算机主动拒绝了它.)


现在我知道该位置绝对没有问题,因为该位置从本地连接到服务器连接没有任何变化.我的2个连接字符串是:

Hi, I am having trouble connection my database to my windows application using a microsoft server 2008. When using a local connection string I am getting no errors and the program runs fine so I know its an issue with the connection string or something I am totally over looking.

The error I get when I change the connection string to an ip based one is this:


''The invocation of the constructor on type ''CalorieCounter.MainWindow'' that matches the specified binding constraints threw an exception.'' Line number ''4'' and line position ''9''.

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: TCP Provider, error: 0 - No connection could be made because the target machine actively refused it.)


Now I know there is absolutly nothing wrong with that position as nothing changes in that position from being a local connection to a server connection. My 2 connection strings are:

SqlConnection conn = new SqlConnection("Data Source= 192.168.0.104,1433;Network Library=DBMSSOCN;Initial Catalog=food;");





SqlConnection conn = new SqlConnection("Data Source=.\\SQLExpress;Initial Catalog=Food;Integrated Security=SSPI;");



第二个作品完美地连接了所有问题.第一次崩溃是我的程序.有人建议更改app.config中的连接字符串,但我尝试过这样做,对问题没有任何影响.我也查看了connectionStrings.com,但仍然无法正常工作!



The second works perfectly connects no issues. The first crash''s my program. Someone suggested changing the connection string within app.config I tried this and made no difference to the problem. I have also looked on connectionStrings.com but still can not get it to work!

Any help would be appreciated as it is starting to get very frustrating!

推荐答案

您可以按Ctrl-> Alt-E并确保引发异常"被检查是否存在公共语言运行时异常"

或者,在代码conn.Open()的行周围放置try catch块.
例如

You could press Ctrl->Alt-E and make sure that ''break when an exception is thrown'' is checked for ''common language runtime exceptions''

Or, put a try catch block around the line of code conn.Open()

e.g.

try
{
    SqlConnection conn = new SqlConnection("Data Source= 192.168.0.104,1433;Network Library=DBMSSOCN;Initial Catalog=food;");
    conn.Open()
}
catch (SqlException ex)
{
    Console.WriteLine(ex.Message);
}



现在,您可以调试并查看错误消息的确切含义.

基本上,在类型上调用构造函数..."异常只是表示它在表单构造内遇到错误,它没有为您提供解决潜在问题所需的详细信息.


编辑:会有防火墙阻止远程连接吗?

http://technet.microsoft.com/en-us/library/cc646023.aspx [ ^ ]



Now you can debug and see exactly what the error message is.

Basically, "The invocation of the constructor on type..." exception is just saying it encountered an error within your form construct, it''s not giving you the detail you need to solve the underlying problem.


Edit: Could there be a firewall blocking the remote connection?

http://technet.microsoft.com/en-us/library/cc646023.aspx[^]


您是否尝试过在服务器资源管理器中建立连接?正确设置后,连接字符串将在属性"窗格中提供.
Have you tried making a connection in the Server Explorer? When you have correctly made that, the connection string is available in the Properties Pane.


SqlConnection conn = new SqlConnection("Data Source= 192.168.0.104,1433;Network Library=DBMSSOCN;Initial Catalog=food;");



IP地址和端口之间的逗号可能是问题所在.我从未见过这种表示地址和端口的语法;通常,分隔符是'':''.

因此,我将尝试以下其中一种技巧:

-根本不要指出端口,因为1433是SQL Server实例的默认端口

-将192.168.0.104,1433替换为192.168.0.104:1433

...并查看您的连接会发生什么情况.

希望这会有所帮助.



Maybe the comma between the IP address and the port is the problem. I''ve never seen that syntax to indicate address and port ; usually, separator is rather '':''.

So, I would try one of these tricks :

- Do not indicate the port at all, as 1433 is the default port for SQL Server instances
OR
- Replace 192.168.0.104,1433 by 192.168.0.104:1433

... and see what happens with your connection.

Hope this helps.


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

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