连接其他服务器数据库

连接其他服务器数据库

问题描述:

我有一个控制台应用程序,并希望连接其他Windows服务器,我已经创建了用户,数据库表。在conf.xml中我有连接其他服务器数据库

<configuration> 
    <crypto location="172.16.10.34" database="Crypto_Pan" username="PinbySms" password="ASDasd123"/> 
</configuration> 

然后我的代码是:

Dictionary<string, string> d = conf.getCrypto(); 

SqlConnectionStringBuilder bu = new SqlConnectionStringBuilder(); 

bu.DataSource = d["location"]; 
bu.NetworkLibrary = "DBMSSOCN"; 
bu.InitialCatalog = d["database"]; 

bu.IntegratedSecurity = false; 
bu.UserID = d["username"]; 
bu.Password = d["password"]; 
SqlConnection thisConnection = null; 

try 
{ 
    thisConnection = new SqlConnection(bu.ConnectionString); 
    thisConnection.Open(); 
    Console.WriteLine("success connected"); 
} 
catch (Exception e) 
{ 
    Console.WriteLine("exeption: " + e.ToString()); 

    thisConnection.Close(); 

} 

我有一个错误,当我的应用程序尝试连接该数据库:

[System.Data.SqlClient的.SqlException] = {“与SQL Server建立连接到 SQL Server时出现与网络有关的或 实例特定的错误。未找到服务器或无法访问。验证 实例名称是正确的,并且SQL Server配置为允许远程连接的 。

有没有人有任何建议?

+0

地址不正确或SQL Server未配置为允许远程连接 - 该IP是否可访问?你可以连接其他任何东西吗? –

+0

来自连接字符串构建器的连接字符串是否具有预期的内容?其他工具可以使用相同的细节连接到该数据库吗? (将连接字符串放在配置文件中有什么问题:这里有一整段内容?) – Richard

+0

我确定希望这些不是您真正的凭据... –

在sql配置PROTOCOL MSQSQLSERVER TCP/IP中没有默认端口,我将其更改为1433,现在没关系。