我正在尝试连接到我的SQL Server数据库。我正在使用C#。这是我的代码:
string connectionString = @"Server = tcp:<myLocalIP>,1433; Initial catalog = <DatabaseName>;
User Id = <User>; Password = <Passwd>;",queryString = "SELECT * FROM [...]";
SqlConnection connection = new SqlConnection(connectionString);
SqlCommand SelectCommand = new SqlCommand(queryString,connection);
SqlDataReader myreader;
connection.Open();
myreader = SelectCommand.ExecuteReader();
List<String> lst = new List<String>();
while (myreader.Read())
{
lst .Add(myreader[0].ToString());
}
connection.Close();
但是connection.Open()
会引发错误:
SqlException:建立与SQL Server的连接时发生与网络相关或特定于实例的错误。服务器未找到或无法访问。验证实例名称正确,并且已将SQL Server配置为允许远程连接。 (提供者:TCP提供程序,错误:0)。
我的服务器已启动,它允许远程连接并启用了TCP / IP。有什么想法吗?