MediumTrust - Problem to accessing MySQL Database

Discussion of open issues, suggestions and bugs regarding ADO.NET provider for MySQL
Post Reply
Marco Beyer
Posts: 5
Joined: Fri 05 Oct 2007 11:38

MediumTrust - Problem to accessing MySQL Database

Post by Marco Beyer » Fri 05 Oct 2007 11:47

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

Alexey
Posts: 2756
Joined: Mon 13 Mar 2006 07:43

Post by Alexey » Fri 05 Oct 2007 12:16

The error message you get doesn't say that there is any security restrictions. It says that your MySQL server cannot be reached from the remote host. Please check carefully your MySQL server settings.

Marco Beyer
Posts: 5
Joined: Fri 05 Oct 2007 11:38

Post by Marco Beyer » Fri 05 Oct 2007 12:32

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

Marco Beyer
Posts: 5
Joined: Fri 05 Oct 2007 11:38

Post by Marco Beyer » Fri 05 Oct 2007 12:40

Hallo again!

By the way: I'm not trying to connect from my local machine. I have uploaded my site and try to connect from the webserver.

Regards,
Marco

Alexey
Posts: 2756
Joined: Mon 13 Mar 2006 07:43

Post by Alexey » Fri 05 Oct 2007 12:40

Please send you web project to the address provided in the Readme file.
I will investigate this more detailed.

Marco Beyer
Posts: 5
Joined: Fri 05 Oct 2007 11:38

Post by Marco Beyer » Fri 05 Oct 2007 12:54

Hallo Alexey!

I have mailed the project!

Regards,
Marco

Alexey
Posts: 2756
Joined: Mon 13 Mar 2006 07:43

Post by Alexey » Fri 05 Oct 2007 13:02

OK, look forward to my reply.

Alexey
Posts: 2756
Joined: Mon 13 Mar 2006 07:43

Post by Alexey » Fri 05 Oct 2007 13:56

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).

Marco Beyer
Posts: 5
Joined: Fri 05 Oct 2007 11:38

Post by Marco Beyer » Fri 05 Oct 2007 14:06

Hallo!

Thanks Alexey! I'll contact them.

Regards,
Marco

Alexey
Posts: 2756
Joined: Mon 13 Mar 2006 07:43

Post by Alexey » Fri 05 Oct 2007 14:39

Good luck :)

Post Reply