问题描述:在建立与服务器的连接时出错。在连接到 SQL Server 2005 时,在默认的设置下 SQL Server 不允许进行远程连接可能会导致此失败。 (provider: TCP 提供程序, error: 0 - 由于目标机器积极拒绝,无法连接。)System.Data.SqlClient.SqlException: 在建立与服务器的连接时出错。在连接到 SQL Server 2005 时,在默认的设置下 SQL Server 不允许进行远程连接可能会导致此失败。 (provider: TCP 提供程序, error: 0 - 由于连接方在一段时间后没有正确答复或连接的主机没有反应,连接尝试失败。)
   在 System.Data.ProviderBase.DbConnectionPool.GetConnection(DbConnection owningObject)
   在 System.Data.ProviderBase.DbConnectionFactory.GetConnection(DbConnection owningConnection)
   在 System.Data.ProviderBase.DbConnectionClosed.OpenConnection(DbConnection outerConnection, DbConnectionFactory connectionFactory)
   在 System.Data.SqlClient.SqlConnection.Open()
   在 DAL.SqlHelper.ExecuteReader(String connectionString, CommandType commandType, String commandText, SqlParameter[] commandParameters) 位置 D:\worker\News\News\SQLHelper.cs:行号 881
   在 DAL.SqlHelper.ExecuteReader(String connectionString, CommandType commandType, String commandText) 位置 D:\worker\News\News\SQLHelper.cs:行号 849
   在 News.Form1.InsertMTDVB(String lb, String title, String sDate, String ly, String Url) 位置 D:\worker\News\News\Form1.cs:行号 7623数据库安装在本机,数据库连接字符串代码为:
cn.ConnectionString = "Data Source=192.168.1.100,1433;Network Library=DBMSSOCN;Initial Catalog=tvsou;User ID=sa;Password=582401";

解决方案 »

  1.   

    是外网的数据库么?
    你先用sqlserver连接下这个服务器
    要是可以连上 程序没问题的
      

  2.   

    cn.ConnectionString = "Data Source=192.168.1.100;Network Library=DBMSSOCN;Initial Catalog=tvsou;User ID=sa;Password=582401";
      

  3.   

    解决办法:1. 确保服务器端的数据库中存在sa,并支持混合登录模式.默认安装的时候,可能会忽略建立sa.2. 确保服务器端的数据库是支持远程调用的.打开SQL Server Management Studio,选择该数据库,右键菜单"Properties",在打开的对话框中选择Connections,把Allow remote connections to this server选上.3. 确保服务器端的SQL服务的TCP/IP是Enable的.打开SQL Server Configuration Manager. 选择SQL Server 2005 Network Configuration下的Protocols for SQL2005( 我安装的SQL示例名为SQL2005), 把Named Pipes和TCP/IP都修改为Enabled,默认是Disabled.4. 确保服务器端的SQL实例的远程调用是支持TIP/IP和named pipes的. 打开SQL Server Surface Area Configuration Manager,在打开的页面中选择Surface Area Configuration for Services and Connections.选中实例的Remote Connections,把Using both TCP/IP and named pipes选中.5. 重启服务器端的SQL Server 2005服务,确保SQL Server Agent和SQL Server Browser的服务也启动了. 默认都是需要手动启动,可以改成Automatic.6. 因为服务器端的操作系统是WinXp+SP2,所以还需要检查防火墙.确保防火墙中的1433端口打开了.另外, SQL Server 2005的默认端口可能不是1433. 我们需要手动修改一下. 打开SQL Server Configuration Manager. 选择SQL Server 2005 Network Configuration下的Protocols for SQL2005( 我安装的SQL示例名为SQL2005), 查看TCP/IP的属性.在打开的对话框中选择IP Address, 把到IPAll下的TCP Dymanic Ports改为0,TCP Port的值修改为1433.在Windows防火墙中的Exceptions中Add Port:TCP 1433和UDP 1434, 同时还需要Add Program.先打开SQL Server Configuration Manager,在SQL Server 2005 Services中选中SQL Server,查看属性,在Advanced中记下Instance ID.如(Mssql.1)在防火墙的Exceptions中Add Program,找到诸如...\Microsoft SQL Server\MSSQL.1\Mssql\Binn\SQLservr.exe,添加.所有这些都做完了,客户端应该就可以访问了,最好客户端也在自己的Configration Manager的Client Configuration中设置TCP/IP为Enabled. 
      

  4.   

    是不是你的SQL服务没有启动?如果不是,再检查一下TCP/TP配置