Connect to MySQL with .NET 2.0

Scott, can you utilize OLEDB to connect? It is enabled in the custom policy I setup the other day when a customer pointed out that only one connection method was allowed.

OLEDb would look like this:
"Provider=MySQLProv;Data Source=mydb;User Id=UserName;Password=asdasd;"
 
Stephen, I tried changing it to OLEDB but now I get this:

The 'MySQLProv' provider is not registered on the local machine.

I tried the connection string you provided, and also tried it with the Location={MySql I.P.Address}. No luck.

Isn't ODBC needed to connect to the other databases like Postgre, Foxpro, etc.?
 
Also, do you know where I can download the OLEDB drivers for MySql? I thought they used to have them on their downloads page, but now there is just ODBC, Java, and .NET drivers. Did they phase out OLEDB support in lieu of the .NET drivers?

Stephen, you were able to turn on OLEDB support. Is there something about ODBC that is more of a security risk where you cannot just enable it like you did OLEDB?

Thanks,
Sam
 
Yes please add OdbcPermission and OraclePermission to the custom policy file in the same way as OleDbPermission has been added.

I have to set up test asp.net 2.0 apps for several databases. I can connect to SQL Server through SqlClient and Access through OleDb, but would need Odbc for MySQL and PostgreSQL and Oracle (or OracleClient) for Oracle 10g.

I'd imagine every jodohost customer using asp.net 2.0 and either MySQL, PostgreSQL or Oracle 10g will be affected by the SecurityException issue.
 
I am not to fond of ODBC, and did not realize MySQL and Oracle could not use OLEDB in 2.0, as they could in 1.1.

I will work on extending permissions again.
 
I just tried MySQL with OLEDB. I received an error saying that the MySQLProv isn't on the server.

I also tried Oracle with OLEDB using Provider=MSDAORA and Provider=OraOLEDB, separately. Both threw errors saying the necessary components aren't on the server.

In any case, I think ODBC is necessary because of PostgreSQL. There is something called PostgreSQLDirect but that is a proprietary data provider.

The other thing is with Oracle 10g, it would be good to connect using OracleClient, since that is the data provider that Oracle recommends.
 
It is still not working. I am under a lot of pressure to get my stuff up and running.

As far as I know, there is no security issue. In .net 1.1 everything had to run on full trust so almost every host provided full trust. With .net 2.0, the recommendation from Microsoft is to go to high or medium trust and so most hosts have gone to this level. I see no reason why OleDbPermission, OdbcPermission and OraclePermission can't be in the medium and/or high trust files by default. According to Microsoft, they certainly can be put into the files or in a custom trust file. It is only a matter of copying the XML elements for SqlClientPermission and putting the equivalent for OleDbPermission, OdbcPermission and OraclePermission near SqlClientPermission's. Putting these permissions in does not interfere with the other security settings in medium or high trust.
 
ASP.net 2.0 now has OLE and ODBC drivers enabled, and installed for Oracle, MySQL, and PgSQL(ODBC only)
 
scottsprize said:
Stephen, everything works correctly now. Thank you for setting this up.


I'm not able to understand how did you solved the problem.
mysql connector is still not able to comunicate with MySQL server.
I'm tring to customize my Mediam Trust Level Policy with but with no result.
Will be very glad every kind of help:(
 

Attachments

  • Server.txt
    11.4 KB · Views: 81
Hello,

You added OLEDB in the top portion, but did not add the ipermission statement for OLEDB to work.
 
like you can see i wrote:

<NamedPermissionSets>
<PermissionSet
class="NamedPermissionSet"
version="1"
Unrestricted="true"
Name="FullTrust"
Description="Allows full access to all resources"
/>
<PermissionSet
class="NamedPermissionSet"
version="1"
Name="Nothing"
Description="Denies all resources, including the right to execute"
/>
<PermissionSet
class="NamedPermissionSet"
version="1"
Name="ASP.Net">
<IPermission
class="OleDbPermission"
version="1"
Unrestricted="true">
</IPermission>


.....
.....

is not enought to start it?
 
Here is my working config:
<configuration>
<mscorlib>
<security>
<policy>
<PolicyLevel version="1">
<SecurityClasses>
<SecurityClass Name="AllMembershipCondition" Description="System.Security.Policy.AllMembershipCondition, mscorlib, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089"/>
<SecurityClass Name="AspNetHostingPermission" Description="System.Web.AspNetHostingPermission, System, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089"/>
<SecurityClass Name="ConfigurationPermission" Description="System.Configuration.ConfigurationPermission, System.Configuration, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a"/>
<SecurityClass Name="DnsPermission" Description="System.Net.DnsPermission, System, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089"/>
<SecurityClass Name="EnvironmentPermission" Description="System.Security.Permissions.EnvironmentPermission, mscorlib, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089"/>
<SecurityClass Name="FileIOPermission" Description="System.Security.Permissions.FileIOPermission, mscorlib, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089"/>
<SecurityClass Name="FirstMatchCodeGroup" Description="System.Security.Policy.FirstMatchCodeGroup, mscorlib, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089"/>
<SecurityClass Name="IsolatedStorageFilePermission" Description="System.Security.Permissions.IsolatedStorageFilePermission, mscorlib, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089"/>
<SecurityClass Name="NamedPermissionSet" Description="System.Security.NamedPermissionSet"/>
<SecurityClass Name="PrintingPermission" Description="System.Drawing.Printing.PrintingPermission, System.Drawing, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a"/>
<SecurityClass Name="ReflectionPermission" Description="System.Security.Permissions.ReflectionPermission, mscorlib, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089"/>
<SecurityClass Name="RegistryPermission" Description="System.Security.Permissions.RegistryPermission, mscorlib, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089"/>
<SecurityClass Name="SecurityPermission" Description="System.Security.Permissions.SecurityPermission, mscorlib, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089"/>
<SecurityClass Name="SmtpPermission" Description="System.Net.Mail.SmtpPermission, System, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089"/>
<SecurityClass Name="SocketPermission" Description="System.Net.SocketPermission, System, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089"/>
<SecurityClass Name="SqlClientPermission" Description="System.Data.SqlClient.SqlClientPermission, System.Data, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089"/>
<SecurityClass Name="StrongNameMembershipCondition" Description="System.Security.Policy.StrongNameMembershipCondition, mscorlib, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089"/>
<SecurityClass Name="UnionCodeGroup" Description="System.Security.Policy.UnionCodeGroup, mscorlib, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089"/>
<SecurityClass Name="UrlMembershipCondition" Description="System.Security.Policy.UrlMembershipCondition, mscorlib, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089"/>
<SecurityClass Name="WebPermission" Description="System.Net.WebPermission, System, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089"/>
<SecurityClass Name="ZoneMembershipCondition" Description="System.Security.Policy.ZoneMembershipCondition, mscorlib, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089"/>
<SecurityClass Name="OleDbPermission" Description="System.Data.OleDb.OleDbPermission, System.Data, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089"/>
<SecurityClass Name="OdbcPermission" Description="System.Data.Odbc.OdbcPermission, System.Data, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089"/>
<SecurityClass Name="OraclePermission" Description="System.Data.OracleClient.OraclePermission, System.Data.OracleClient, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089"/>
</SecurityClasses>
<NamedPermissionSets>
<PermissionSet
class="NamedPermissionSet"
version="1"
Unrestricted="true"
Name="FullTrust"
Description="Allows full access to all resources"
/>
<PermissionSet
class="NamedPermissionSet"
version="1"
Name="Nothing"
Description="Denies all resources, including the right to execute"
/>
<PermissionSet
class="NamedPermissionSet"
version="1"
Name="ASP.Net">
<IPermission
class="AspNetHostingPermission"
version="1"
Level="High"
/>
<IPermission
class="ConfigurationPermission"
version="1"
Unrestricted="true"
/>
<IPermission
class="DnsPermission"
version="1"
Unrestricted="true"
/>
<IPermission
class="EnvironmentPermission"
version="1"
Unrestricted="true"
/>
<IPermission
class="FileIOPermission"
version="1"
Read="$AppDir$"
Write="$AppDir$"
Append="$AppDir$"
PathDiscovery="$AppDir$"
/>
<IPermission
class="IsolatedStorageFilePermission"
version="1"
Unrestricted="true"
/>
<IPermission
class="PrintingPermission"
version="1"
Level="DefaultPrinting"
/>
<IPermission
class="ReflectionPermission"
version="1"
Flags="ReflectionEmit"
/>
<IPermission
class="RegistryPermission"
version="1"
Unrestricted="true"
/>
<IPermission
class="SecurityPermission"
version="1"
Flags="Assertion, Execution, ControlThread, ControlPrincipal, RemotingConfiguration"
/>
<IPermission
class="SmtpPermission"
version="1"
Access="Connect"
/>
<IPermission
class="SocketPermission"
version="1"
Unrestricted="true"
/>
<IPermission
class="SqlClientPermission"
version="1"
Unrestricted="true"
/>
<IPermission
class="WebPermission"
version="1"
Unrestricted="true"
/>
<IPermission class="OleDbPermission"
version="1"
Unrestricted="true"
/>

<IPermission class="OdbcPermission"
version="1"
Unrestricted="true"
/>

<IPermission class="OraclePermission"
version="1"
Unrestricted="true"
/>
</PermissionSet>
</NamedPermissionSets>
<CodeGroup
class="FirstMatchCodeGroup"
version="1"
PermissionSetName="Nothing">
<IMembershipCondition
class="AllMembershipCondition"
version="1"
/>
<CodeGroup
class="UnionCodeGroup"
version="1"
PermissionSetName="ASP.Net">
<IMembershipCondition
class="UrlMembershipCondition"
version="1"
Url="$AppDirUrl$/*"
/>
</CodeGroup>
<CodeGroup
class="UnionCodeGroup"
version="1"
PermissionSetName="ASP.Net">
<IMembershipCondition
class="UrlMembershipCondition"
version="1"
Url="$CodeGen$/*"
/>
</CodeGroup>
<CodeGroup class="UnionCodeGroup" version="1" PermissionSetName="Nothing">
<IMembershipCondition
class="ZoneMembershipCondition"
version="1"
Zone="MyComputer" />
<CodeGroup
class="UnionCodeGroup"
version="1"
PermissionSetName="FullTrust"
Name="Microsoft_Strong_Name"
Description="This code group grants code signed with the Microsoft strong name full trust. ">
<IMembershipCondition
class="StrongNameMembershipCondition"
version="1"
PublicKeyBlob="002400000480000094000000060200000024000052534131000400000100010007D1FA57C4AED9F0A32E84AA0FAEFD0DE9E8FD6AEC8F87FB03766C834C99921EB23BE79AD9D5DCC1DD9AD236132102900B723CF980957FC4E177108FC607774F29E8320E92EA05ECE4E821C0A5EFE8F1645C4C0C93C1AB99285D622CAA652C1DFAD63D745D6F2DE5F17E5EAF0FC4963D261C8A12436518206DC093344D5AD293"
/>
</CodeGroup>
<CodeGroup
class="UnionCodeGroup"
version="1"
PermissionSetName="FullTrust"
Name="Ecma_Strong_Name"
Description="This code group grants code signed with the ECMA strong name full trust. ">
<IMembershipCondition
class="StrongNameMembershipCondition"
version="1"
PublicKeyBlob="00000000000000000400000000000000"
/>
</CodeGroup>
</CodeGroup>
</CodeGroup>
</PolicyLevel>
</policy>
</security>
</mscorlib>
</configuration>
 
i'm not able to solve this problem.:(
I continue to have the following message:
System.Security.SecurityException: That assembly does not allow partially trusted callers.

I tried to have a custom level making a copy of Medium and Hight files too.

I use the connector in BIN directory into my web site, need I put in SYSTEM32 or something like that on the server?

In Attach you'll find the config files, please someone can tell me whats wrong?
 

Attachments

  • web_highMySQLtrust.config.txt
    12.5 KB · Views: 61
  • web.config.txt
    1.9 KB · Views: 54
  • testPage.aspx.vb.txt
    338 bytes · Views: 71
I wanna specify that i'm tring to use MySQL Connector 1.7.
Could be that the problem ???? and if yes, there is some solution to use it??
 
That error means one of the files in your /bin folder is not set to allow anything but a fully trusted caller, it is a different error.

You need to make sure everything is set to allow partial callers.
 
Back
Top