我已将此连接信息添加到与views文件夹相同的文件级别的Webconfig中,以及视图文件夹中的一个。它也在Web.Debug.config中。如何将asp.net mvc连接到非本地mySQL数据库?
<connectionStrings>
<add name="MySqlServer"
connectionString="Datasource=foo.bar.net;Database=testasp;uid=Slendy;pwd=istall;"
providerName="MySql.Data.MySqlClient"/>
</connectionStrings>
后来才知道有这个功能,我复制从如何做的崩溃对adapter.Fill(DS),因为个MySqlException的粘贴“无法连接到任何指定的MySQL主机。”当我打开/数据/信息/ 1
//
// GET: /Data/Details
public string Details()
{
// Get the MySQL connection string stored in the Web.config
string cnnString = ConfigurationSettings.AppSettings["ConnectionString"];
// Create a connection object and data adapter
MySqlConnection cnx = new MySqlConnection(cnnString);
MySqlDataAdapter adapter = new MySqlDataAdapter();
// Create a SQL command object
string cmdText = "select '3232' as ah;";
MySqlCommand cmd = new MySqlCommand(cmdText, cnx);
// Set the command type to StoredProcedure
cmd.CommandType = CommandType.StoredProcedure;
// Create and fill a DataSet
DataSet ds = new DataSet();
adapter.SelectCommand = cmd;
adapter.Fill(ds);
return "::::";
}
我的测试SQL表是在我的网站,而不是本地主机,并且是如下
a b c
1 2013-02-02 14:08:53 324
2 2013-02-02 14:08:53 342234
我曾在这里跟随指南:http://dev.mysql.com/doc/refman/5.1/en/connector-net-tutorials-asp-roles.html但我不当然,如果我找到了正确的文件进行编辑。我还为我的电脑设置了访问dreamhost的权限。
更新:cnnString快到了NULL
它不应该是任何比这更难:\ –
这就是我的想法。也许我没有编辑正确的machine.config文件。在我的电脑上搜索了86个结果。 –
oy。在web.config和web.debug.config之间,这些东西可能会很痛苦。在解决方案资源管理器中找到它否则,我希望我有什么补充。这是一个例行的问题,而且你没有做任何明显错误的事情。 –