使用.NET连接MSDE2000时的连接问题
我有一个奇怪的问题。我正在尝试从 C# (.Net 4.0) 连接到 Microsoft SQL 服务器。服务器正在运行 MSDE2000(8.00.194)。当我连接时,我收到以下消息:
System.Data.SqlClient.SqlException (0x80131904): 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.)
我的连接字符串如下所示,(是的,我使用的是空白密码): “用户 ID=sa;密码=;数据源=192.168.0.100\?,1433;Trusted_Connection=false;初始目录=DATABASE1;”
我尝试更改连接字符串中的几乎所有内容以使其正常工作,但没有成功。我什至尝试过使用 OleDBConnection 而不是 SqlConnection 但没有成功。
奇怪的是,当我通过 Microsoft Management Studio 连接时,我能够连接并查看所有内容。但是我发送的每个命令之间都会断开连接,并且必须重新连接。
有谁知道问题可能是什么或者我应该从哪里开始寻找问题?
编辑:我可能会补充一点,我尝试通过端口 1433 远程登录到计算机,但收到“连接被主机关闭”。问题是我无权访问计算机,因此无法检查防火墙设置,但 Management Studio 的连接方式是否与 .Net 相同?
I have a strange problem. I'm trying to connect to a Microsoft SQL server from C# (.Net 4.0). The server is running MSDE2000(8.00.194). When I connect I get the following message:
System.Data.SqlClient.SqlException (0x80131904): 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.)
My connectionstring looks like this,(yes i'm using a blank password):
"User Id=sa;Password=;Data Source=192.168.0.100\?,1433;Trusted_Connection=false;Initial Catalog=DATABASE1;"
I've tried changing pretty much everything in the connection string to get it to work without success. I've even tried doing an OleDBConnection instead of the SqlConnection but without success.
The strange thing is that when I connect through Microsoft Management Studio I'm able to connect and see everything. But I get disconnected between every command I send and have to reconnect.
Does anyone know what the problem might be or where I should start looking to find the problem?
Edit: I might add that I tried to telnet to the machine on port 1433 but got "Connection closed by host". The thing is that I do not have access to the computer so I can't check firewall settings but isn't the Management Studio connecting the same way as .Net do?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您确定此类 MSDE 2000 的实例已启动并正在运行吗?您可以使用 SQL Management Studio 远程连接到该实例吗?谁安装了该实例?默认情况下,tcp 连接在默认安装中被禁用,这在 SQL Server 2005 Express 中仍然发生(不确定 2008 版本),因此除非安装它的人已正确配置它或知道如何设置它,否则您可能会缺少一些要启用的协议。
该实例在该机器上本地可用吗?
检查这里的默认连接字符串,我也怀疑?是有效的实例名称,如果您知道实例名称,则应指定它,
http://connectionstrings.com/ sql-server#p1
Are you sure the instance of such MSDE 2000 is up and running? can you connect to that instance remotely with your SQL Management Studio? Who has installed that instance? by default tcp connections are disabled in a default install, this still happened also in SQL Server 2005 Express (not sure about the 2008 version) so unless the guy who installed it has configured it properly or knew how to set it up, you could be missing some protocols to be enabled.
is that instance available locally on that machine?
check here for default connection strings, I also doubt that ? is a valid instance name and if you know the instance name you should specify it,
http://connectionstrings.com/sql-server#p1