I have added this connection information into both the Webconfig in the same file level as the views folder, and the one in the views folder. It is also in the Web.Debug.config.
<connectionStrings>
<add name="MySqlServer"
connectionString="Datasource=foo.bar.net;Database=testasp;uid=Slendy;pwd=istall;"
providerName="MySql.Data.MySqlClient"/>
</connectionStrings>
And then I have this function I copy pasted from a how-to that crashes on adapter.Fill(ds) because of a MySqlException “Unable to connect to any of the specified MySQL hosts.” when I open /data/details/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 "::::";
}
My test sql table is on my website rather than localhost, and is as follows
a b c
1 2013-02-02 14:08:53 324
2 2013-02-02 14:08:53 342234
I had followed a guide here: http://dev.mysql.com/doc/refman/5.1/en/connector-net-tutorials-asp-roles.html but am not sure if I found the right file to edit. I also set permission on dreamhost for my computer to access it.
Update: cnnString is coming up NULL
Found out that ConfigurationSettings should be ConfigurationManager and set the line of code to be
where “MySqlServer” matches the connectionstring name in the config file.
This was a good help:
C# Configuration Manager . ConnectionStrings