簡體   English   中英

錯誤連接到遠程 SQL 服務器 Express 2012 windows 10 c#

[英]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

我嘗試了以下事情,但沒有解決問題:

  • 啟用並自動啟動 SQL 瀏覽器
  • 為所有 IP 類型啟用 TCP/IP 並設置端口 1433
  • 啟動命名為inslance SQLExpress2012 autmaticaly as Build-in: Network service
  • 使用 IntegratedSecurity=true 無需用戶名和密碼即可連接
  • 數據庫正在使用混合模式身份驗證
  • 在防火牆中為端口 1433 添加例外
  • 啟用名為 pipe
  • 允許遠程連接

這是我的代碼:

        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.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM