I have the following code for connecting to my database on GoDaddy:
string connStr = "server=IP;" +
"user=user_name;database=database_name;" +
"port=3306;password=password;pooling=true;";
MySqlConnection conn = new MySqlConnection(connStr);
try
{
Response.Write("Connecting to MySQL database...<br/>");
conn.Open();
string sql = "show tables";
MySqlCommand cmd = new MySqlCommand(sql, conn);
MySqlDataReader rdr = cmd.ExecuteReader();
while (rdr.Read())
{
Response.Write(rdr[0] + "<br/>");
}
rdr.Close();
}
catch (Exception ex)
{
Response.Write(ex.ToString());
}
conn.Close();
Response.Write("All done!");
This is the response:
Connecting to MySQL database... System.Security.SecurityException: Request for the permission of type 'System.Security.Permissions.SecurityPermission, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089' failed. at MySql.Data.MySqlClient.MySqlConnection.AssertPermissions() at MySql.Data.MySqlClient.MySqlConnection.Open() at _Default.ConnectToDatabase() The action that failed was: InheritanceDemand The type of the first permission that failed was: System.Security.Permissions.SecurityPermission The Zone of the assembly that failed was: MyComputerAll done!
What am I doing wrong?
BTW: If i run it in debugging mode on my computer, there's no problem. Only when I publish it to my server on GoDaddy.