我有一个控制台应用程序,并希望连接其他已经创建用户,数据库表的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] = {&#34;与网络相关或 建立连接时发生特定于实例的错误 SQL Server。服务器未找到或无法访问。校验 实例名称正确且SQL Server配置为 允许远程连接。
有人有任何建议吗?
答案 0 :(得分:1)
在sql配置PROTOCOL MSQSQLSERVER TCP / IP中没有默认端口,我将其更改为1433,现在没问题。