2015-09-27 89 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; 
}