2012-10-11 34 views
6

我已經在外部服務器上有一個SQL服務器和數據庫設置(爲此目的我們稱域名爲「hello.com」),並且我想連接到此服務器通過C#程序。到目前爲止,我有這個(所有服務器/數據庫細節不同的以假亂真):在C#中連接到外部SQL數據庫

private static void SetupSQL() 
{ 
    string connectionString = "server=hello.com; database=db1; uid=user1; pwd=xxxxx;"; 
    connection = new SqlConnection(); 
    connection.ConnectionString = connectionString; 
    try 
    { 
     connection.Open(); 
     Console.WriteLine("Connected"); 
    } 
    catch (Exception e) 
    { 
     Console.WriteLine(e.Message.ToString()); 
    } 
} 

這是給我的錯誤信息:

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 connections. (provider: Named Pipes Provider, error: 40 - Could not open a connection to SQL Server) 

我已經檢查了所有的連接字符串,我被允許遠程訪問,因爲我現在在同一臺計算機上有SQLWorkbench打開查詢數據庫。

任何想法?

+1

這是爲什麼標記爲mysql的,如果數據庫是SQL服務器? –

+0

用連接字符串中的名字檢查你的sqlInstance – Prasad

+0

這是一個MySQL服務器。對不起,如果我沒有說清楚。 – AllFallD0wn

回答

3

不能使用SqlConnection對象連接到MySQL數據庫,你應該使用MySqlConnection導入它的dll之後,而不是