[英]Connect to SQL Server 2012 Database with C# (Visual Studio 2012)
[英]error connect to remote SQL Server Express 2012 windows 10 c#
我在 windows 10 64 位上安裝了 SQL 服務器 express 2012,來自同一台計算機的連接工作正常,當我從同一網絡上的另一台計算機連接時出現問題,我收到錯誤消息:
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 connection
-provider TCP provider error 0 the wait operation timeout
我嘗試了以下事情,但沒有解決問題:
這是我的代碼:
public static bool TestSQLServerConnection(
string ComputerNameOrIPAddress,
string SQLServerInstanceName,
string PortNumber)
{
try
{
SqlConnectionStringBuilder SQLServerConnectionString = new SqlConnectionStringBuilder();
SQLServerConnectionString.DataSource = ComputerNameOrIPAddress+",+"+PortNumber+"\\"+SQLServerInstanceName;
SQLServerConnectionString.InitialCatalog = DatabseName;
SQLServerConnectionString.TrustServerCertificate = true;
SQLServerConnectionString.IntegratedSecurity = true;
//SQLServerConnectionString.UserID = "...";
//SQLServerConnectionString.NetworkLibrary = "DBMSSOCN";
//SQLServerConnectionString.Password = "...";
SqlConnection con = new SqlConnection(SQLServerConnectionString.ConnectionString);
SqlCommand cmd = con.CreateCommand();
cmd.CommandType = CommandType.Text;
cmd.CommandText= "select 1";
con.Open();
cmd.ExecuteScalar();
con.Close();
return true;
}
catch (Exception ex)
{
throw ex;
}
}
當我 ping SQL 服務器的 ip 地址或計算機名稱時,它連接並返回響應,表示計算機已連接到網絡。 我在沒有任何解決方案的情況下搜索,請幫助我。謝謝
我在防火牆上添加了 SQL 瀏覽器服務 UDP 端口 1434 並且工作正常。 使用 SQL Server Management Studio 遠程連接到 Azure 虛擬機上托管的 SQL Server Express 實例
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.