2013-03-11 102 views
1

我需要你的幫助。C#連接到mysql服務器

我這是說的錯誤消息:

"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)".

我試圖連接使用的IP其它本地計算機本地主機。 我的代碼:

public DbStudent() 
    { 
     UGIcon = new SqlConnection(); 
     UGIcon.ConnectionString = "server= IPAddress;user="id";password="pass";database=MyDB"; 
    } 
    public SqlConnection Open() 
    { 
     UGIcon.Open(); 
     return UGIcon; 
    } 

    public void Close() 
    { 
     UGIcon.Close(); 
    } 

請問有人能幫我嗎?

+4

你的標題具有的MySql而你的錯誤是關於SQL Server的,你想用'SqlConnection'連接到MySQL數據庫嗎? – Habib 2013-03-11 08:00:25

+0

是的,有可能嗎?或者你可以給我另一種方式來連接mysql? – Wiranata 2013-03-11 08:02:31

+0

我不明白你的代碼是如何編譯的:你的連接字符串包含未轉義引號...... – Kek 2013-03-11 08:03:08

回答

1

SqlConnection用於訪問SQL Server,另一個數據庫使用OleDbConnection。 因此,如果您想連接到MySQL,請改爲使用OleDbConnection

public DbStudent() 
    { 
     UGIcon = new OleDbConnection(); 
     UGIcon.ConnectionString = "Server=IPAddress;Database=MyDB;Uid=id;Pwd=pass;"; 
    } 

你可以看到here爲MySQL連接字符串

2

你需要從MySql

有下載安裝,你會得到一個司機爲MySQL數據庫