MediumTrust - Problem to accessing MySQL Database

MediumTrust - Problem to accessing MySQL Database

Postby 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:





























class="NamedPermissionSet"
version="1"
Unrestricted="true"
Name="FullTrust"
Description="Allows full access to all resources"
/>
class="NamedPermissionSet"
version="1"
Name="Nothing"
Description="Denies all resources, including the right to execute"
/>
class="NamedPermissionSet"
version="1"
Name="ASP.Net">
class="AspNetHostingPermission"
version="1"
Level="Medium"
/>
class="DnsPermission"
version="1"
Unrestricted="true"
/>
class="EnvironmentPermission"
version="1"
Read="TEMP;TMP;USERNAME;OS;COMPUTERNAME"
/>
class="FileIOPermission"
version="1"
Read="$AppDir$"
Write="$AppDir$"
Append="$AppDir$"
PathDiscovery="$AppDir$"
/>
class="IsolatedStorageFilePermission"
version="1"
Allowed="AssemblyIsolationByUser"
UserQuota="9223372036854775807"
/>
class="PrintingPermission"
version="1"
Level="DefaultPrinting"
/>
class="SecurityPermission"
version="1"
Flags="Assertion, Execution, ControlThread, ControlPrincipal, RemotingConfiguration"
/>
class="SmtpPermission"
version="1"
Access="Connect"
/>
class="SqlClientPermission"
version="1"
Unrestricted="true"
/>





class="FirstMatchCodeGroup"
version="1"
PermissionSetName="Nothing">
class="AllMembershipCondition"
version="1"
/>
class="UnionCodeGroup"
version="1"
PermissionSetName="ASP.Net">
class="UrlMembershipCondition"
version="1"
Url="$AppDirUrl$/*"
/>

class="UnionCodeGroup"
version="1"
PermissionSetName="ASP.Net">
class="UrlMembershipCondition"
version="1"
Url="$CodeGen$/*"
/>


class="ZoneMembershipCondition"
version="1"
Zone="MyComputer" />
class="UnionCodeGroup"
version="1"
PermissionSetName="FullTrust"
Name="Microsoft_Strong_Name"
Description="This code group grants code signed with the Microsoft strong name full trust. ">
class="StrongNameMembershipCondition"
version="1"
PublicKeyBlob="002400000480000094000000060200000024000052534131000400000100010007D1FA57C4AED9F0A32E84AA0FAEFD0DE9E8FD6AEC8F87FB03766C834C99921EB23BE79AD9D5DCC1DD9AD236132102900B723CF980957FC4E177108FC607774F29E8320E92EA05ECE4E821C0A5EFE8F1645C4C0C93C1AB99285D622CAA652C1DFAD63D745D6F2DE5F17E5EAF0FC4963D261C8A12436518206DC093344D5AD293"
/>

class="UnionCodeGroup"
version="1"
PermissionSetName="FullTrust"
Name="Ecma_Strong_Name"
Description="This code group grants code signed with the ECMA strong name full trust. ">
class="StrongNameMembershipCondition"
version="1"
PublicKeyBlob="00000000000000000400000000000000"
/>









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
Marco Beyer
 
Posts: 5
Joined: Fri 05 Oct 2007 11:38

Postby 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.
Alexey
 
Posts: 2756
Joined: Mon 13 Mar 2006 07:43

Postby 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

Postby 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
Marco Beyer
 
Posts: 5
Joined: Fri 05 Oct 2007 11:38

Postby 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.
Alexey
 
Posts: 2756
Joined: Mon 13 Mar 2006 07:43

Postby Marco Beyer » Fri 05 Oct 2007 12:54

Hallo Alexey!

I have mailed the project!

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

Postby Alexey » Fri 05 Oct 2007 13:02

OK, look forward to my reply.
Alexey
 
Posts: 2756
Joined: Mon 13 Mar 2006 07:43

Postby 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).
Alexey
 
Posts: 2756
Joined: Mon 13 Mar 2006 07:43

Postby Marco Beyer » Fri 05 Oct 2007 14:06

Hallo!

Thanks Alexey! I'll contact them.

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

Postby Alexey » Fri 05 Oct 2007 14:39

Good luck :)
Alexey
 
Posts: 2756
Joined: Mon 13 Mar 2006 07:43


Return to dotConnect for MySQL