MediumTrust - Problem to accessing MySQL Database
-
- Posts: 5
- Joined: Fri 05 Oct 2007 11:38
MediumTrust - Problem to accessing MySQL Database
Dear CoreLAB-Community!
First of, I should say that I use version 4 professional.
I have some problems connecting a MySQL database which is running on my ISP. I have a webspace which allows me to run .aspx-Sites and in this package I can also access a MySQL database.
I made a testwebsite which should connect to the MySQL-Server. It contains a simple site which displays the content of the one and only table in my database. On my local machine it works just fine, but when I change the connection string in order to access the database from the webserver and upload my site, I get the following error:
Can't connect to MySQL server on 'xxx' (10061)
I checked my data, the setup, etc. but I can’t get it running. I contacted my ISP and got the following answer (I gave them the code-files that they could check, if I made a mistake):
“You are using a third-party MySQL-Client. I assume that this one does not work correctly in ASP.NET 2.0 medium-trust, because of the use of system-relating methods. These methods are disabled by security reasons.”
I have read that – when I use direct-access (which I do) – I have to add some SocketPermissions. First, I don’t really know, if this is possible with my ISP. Therefore, I want to list the important parts of the web-config file of my ISP. Could you please check that for me?
Here it is:
I know what to do, if my ISP does not support it, because I have read the thread on http://crlab.com/forums/viewtopic.php?p=11014.
If it is already possible could you give me some tips of how to set these SocketPermissions up? Do I have to do this in my web.config file? To make things easier, here is the code that connects to database and gathers data:
private MySqlConnection mySqlConnection = null;
private MySqlDataAdapter dataAdapter = null;
private DataSet dataSet = new DataSet();
protected void Page_Load(object sender, EventArgs e)
{
try
{
DataSet ds = FetchData();
GridView1.DataSource = ds.Tables[0];
GridView1.DataBind();
}
catch (Exception ex)
{
GridView1.DataSource = null;
Response.Write(ex.Message);
}
}
public DataSet FetchData()
{
try
{
mySqlConnection = new MySqlConnection();
mySqlConnection.Direct = true;
mySqlConnection.ConnectionString = ConfigurationManager.ConnectionStrings["MySqlServices"].ConnectionString;
dataAdapter = new MySqlDataAdapter("", mySqlConnection);
dataAdapter.SelectCommand.CommandText = "SELECT * FROM mytable";
dataAdapter.Fill(dataSet);
}
catch (Exception ex)
{
throw new Exception(ex.Message);
}
finally
{
if (mySqlConnection != null)
mySqlConnection.Close();
}
return dataSet;
}
This is mainly the code that I copied from the samples which are shipped with MyDirect.NET and I just customized it for my needs.
Thanks for your help,
Marco Beyer
First of, I should say that I use version 4 professional.
I have some problems connecting a MySQL database which is running on my ISP. I have a webspace which allows me to run .aspx-Sites and in this package I can also access a MySQL database.
I made a testwebsite which should connect to the MySQL-Server. It contains a simple site which displays the content of the one and only table in my database. On my local machine it works just fine, but when I change the connection string in order to access the database from the webserver and upload my site, I get the following error:
Can't connect to MySQL server on 'xxx' (10061)
I checked my data, the setup, etc. but I can’t get it running. I contacted my ISP and got the following answer (I gave them the code-files that they could check, if I made a mistake):
“You are using a third-party MySQL-Client. I assume that this one does not work correctly in ASP.NET 2.0 medium-trust, because of the use of system-relating methods. These methods are disabled by security reasons.”
I have read that – when I use direct-access (which I do) – I have to add some SocketPermissions. First, I don’t really know, if this is possible with my ISP. Therefore, I want to list the important parts of the web-config file of my ISP. Could you please check that for me?
Here it is:
I know what to do, if my ISP does not support it, because I have read the thread on http://crlab.com/forums/viewtopic.php?p=11014.
If it is already possible could you give me some tips of how to set these SocketPermissions up? Do I have to do this in my web.config file? To make things easier, here is the code that connects to database and gathers data:
private MySqlConnection mySqlConnection = null;
private MySqlDataAdapter dataAdapter = null;
private DataSet dataSet = new DataSet();
protected void Page_Load(object sender, EventArgs e)
{
try
{
DataSet ds = FetchData();
GridView1.DataSource = ds.Tables[0];
GridView1.DataBind();
}
catch (Exception ex)
{
GridView1.DataSource = null;
Response.Write(ex.Message);
}
}
public DataSet FetchData()
{
try
{
mySqlConnection = new MySqlConnection();
mySqlConnection.Direct = true;
mySqlConnection.ConnectionString = ConfigurationManager.ConnectionStrings["MySqlServices"].ConnectionString;
dataAdapter = new MySqlDataAdapter("", mySqlConnection);
dataAdapter.SelectCommand.CommandText = "SELECT * FROM mytable";
dataAdapter.Fill(dataSet);
}
catch (Exception ex)
{
throw new Exception(ex.Message);
}
finally
{
if (mySqlConnection != null)
mySqlConnection.Close();
}
return dataSet;
}
This is mainly the code that I copied from the samples which are shipped with MyDirect.NET and I just customized it for my needs.
Thanks for your help,
Marco Beyer
-
- Posts: 5
- Joined: Fri 05 Oct 2007 11:38
Hallo Alexey!
Yes, this is my exact problem. My ISP administrates the MySQL server. And I got the reply I listed in my original post! Here again:
"You are using a third-party MySQL-Client. I assume that this one does not work correctly in ASP.NET 2.0 medium-trust, because of the use of system-relating methods. These methods are disabled by security reasons.”
What can I do?
Best regards,
Marco
Yes, this is my exact problem. My ISP administrates the MySQL server. And I got the reply I listed in my original post! Here again:
"You are using a third-party MySQL-Client. I assume that this one does not work correctly in ASP.NET 2.0 medium-trust, because of the use of system-relating methods. These methods are disabled by security reasons.”
What can I do?
Best regards,
Marco
-
- Posts: 5
- Joined: Fri 05 Oct 2007 11:38
-
- Posts: 5
- Joined: Fri 05 Oct 2007 11:38
I've reproduced the problem. It is indeed in SocketPermission which is missed.
You need to change web.config file used by your ISP. Instructions are described in the forum topic you mentioned(http://crlab.com/forums/viewtopic.php?p=11014).
You need to change web.config file used by your ISP. Instructions are described in the forum topic you mentioned(http://crlab.com/forums/viewtopic.php?p=11014).
-
- Posts: 5
- Joined: Fri 05 Oct 2007 11:38