2015-09-27 51 views
0

我試圖在AppHarbor上啓動並運行應用程序。大部分情況一直很順利,但今天我無法連接到我的MySQL數據庫。AppHarbor:通過ASP.NET MVC連接到MySQL數據庫5 + Dapper

使用AppHarbor爲我提供的憑據,使用dbForge Studio Express成功連接到mySQL數據庫實例,創建了必需的SQL模式,並使用數據填充表格。現在,我嘗試使用下面的C#代碼中使用精緻小巧做一個簡單的查詢:

var sqlConnStringBuilder = new SqlConnectionStringBuilder(ConfigurationManager.ConnectionStrings["AppHarborMySql"].ConnectionString); 

using (var db = new SqlConnection(sqlConnStringBuilder.ConnectionString)) 
{ 
    db.Open(); 
    // Do database query stuff 

    return result; 
} 

但是,這是我遇到的錯誤,當我嘗試打開數據庫連接:

An exception of type 'System.Data.SqlClient.SqlException' occurred in System.Data.dll but was not handled in user code

Additional information: 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)

這是怎麼了,我宣佈在Web.config中的連接字符串:

<connectionStrings> 
    <add name="AppHarborMySql" connectionString="server=MYDOMAIN.mysql.sequelizer.com;database=MYDBNAME;uid=MYUSERNAME;pwd=MYPASSWORD" providerName="System.Data.SqlClient" /> 
</connectionStrings> 

我失去了一些東西明顯?我正在使用ASP.NET MVC 5.x和Dapper的最新版本......提前致謝!

回答

0

當然,儘管我花了一個小時的時間調查了一小時,但發現問題後我立即發現了答案。

對於別人誰可以在同樣的問題上運行:我加入了MySql.Web NuGet package到我的MVC項目,添加using MySql.Data.MySqlClient;我網頁的頂部,然後改變了我的代碼,以從SqlConnectionMySqlConnection。以下是我的工作代碼塊現在的樣子:

using (var db = new MySqlConnection(ConfigurationManager.ConnectionStrings["AppHarborMySql"].ConnectionString)) 
{ 
    db.Open(); 
    // Do database query stuff 

    return result; 
}