mysql connector on .net 4

Discussion in 'Microsoft Development' started by carpe-diem, Jan 16, 2011.

  1. carpe-diem

    carpe-diem Perch

    Hi, I was wondering if it is possible to use .net connector in .net 4.

    I tried using it but got ->inmscorlib . Reason: Request for the permission of type 'System.Net.SocketPermission, System, Version=, Culture=neutral, PublicKeyToken=b77a5c561934e089' failed.

    Is this meant to be this way?
  2. Stephen

    Stephen US Operations Staff Member

    we grant socket permissions, there is possibly a missing line in config file or some other issue, do you have a ticket reference?
  3. carpe-diem

    carpe-diem Perch

    I just tried .net 4 for test if I can change versions. Since mysql didn't work I had to revert back to 2.0 before going to bed.

    Since you say it should work, I will try again later (but not today) and on a less important site :)

    Thanks for info, have fun.
  4. rvhost

    rvhost Guppy

    I'm also having some problems with the mysql connection from my 4 application on one of my client accounts I setup under my resellers control panel.

    My error is very generic and happens in an inner exception of my code.. Basically it is along the lines of "Unable to connect to host server."

    It is ASP.NET 4.0 app and I'm using the latest MySQL net connector (6.3.6) and I'm trying to connect to a database I also setup under the client account control panel.

    Locally I can connect to my local setup of MySQL. After lots of google searches many responses were that the MySQL server doesn't allow remote connections but I don't believe that is true in my situation because I see that there are several Windows users connecting to MySQL databases with you guys (JodoHost). So it has to be something else. I've verified my connection string several times by both using the domain and IP address of the MySQL Server. It is just not connecting... what could be the problem.. could it be that it thinks my connection is coming from an outside remote source?

    Here is my connection string in web.config:

    <add name="MySQLDataConn" connectionString="Server=mysql3.g********.com;Database=[database i'm using];Uid=[username im using];Pwd=[password im using];" providerName="MySql.Data.MySqlClient"/>

    (i'm not putting in the brackets you see above.. just replaced my real info so it wasn't all on the forum)

    It takes a while for the app to decide it can't find the server so I believe it isn't even getting a communication from the server at all since it hangs so long, its not like it connects and mysql returns back some problem; it is just not connecting at all.

    Hope I have given enough detail, just looking to solve the problem with the mysql connection so I can move on. Thanks!!
  5. tanmaya

    tanmaya APAC Operations Staff Member

    Are you trying to connect from your end?
  6. rvhost

    rvhost Guppy

    if you are talking about connecting from my localhost. I did to test my connection string but of course I didn't expect that to work depending if JodoHost isn't allowing remote connections. When I change my connection string to my localhost mysql server then of course it works.

    But also the deployed app to JodoHost's windows server is also throwing this generic error and seems to not be connecting to the JodoHost's mysql server.
  7. tanmaya

    tanmaya APAC Operations Staff Member

    can you try to get the real exception mysql server/driver is throwing, unless you meant 'System.Net.SocketPermission' error?
  8. rvhost

    rvhost Guppy

    no i don't think i'm getting that same error as the original poster, carpe-diem.

    The location I'm at I can't get to the code to check the exception. I'll post it a bit later and maybe we can continue solving it later today or tomorrow. I have it in a try catch block and its hiding the exception. So I can't get it remotely either right now.

    Thanks for standing by.
  9. rvhost

    rvhost Guppy

    Sorry for the long wait. Just getting back to development. here is the exception and inner exception coming from the server. Looks like a permissions problem but how do I solve? Now I was able to make it give me more detail:

    The type initializer for 'MySql.Data.MySqlClient.MySqlTrace' threw an exception.

    Inner Exception:
    System.Security.SecurityException: Request for the permission of type 'System.Security.Permissions.SecurityPermission, mscorlib, Version=, Culture=neutral, PublicKeyToken=b77a5c561934e089' failed. at MySql.Data.MySqlClient.MySqlTrace..cctor() The action that failed was: LinkDemand The type of the first permission that failed was: System.Security.Permissions.SecurityPermission The Zone of the assembly that failed was: MyComputer
  10. rvhost

    rvhost Guppy

    by the way i'm using mysql net connector version 6.3.6. I put the dll file in my bin folder. Not sure if mysql net connector is installed on the servers and if so what version. If it is on the server I can try to reference that one if you can tell me how.
  11. rvhost

    rvhost Guppy

    SOLVED my problem! Wheeeeww. For whatever reason after doing some research version 6.3.6 of mysql net connector only works in a Full trust environment which is obviously not how the servers are setup in a shared environment. So I locally uninstalled my 6.3.6 version, installed a previous version, and loaded that DLL file to the server for my web app and ta-da! Worked.

    For anyone else that may come across this problem, until newer versions of mysql net connector work in medium and lower trust environments (i'm sure they can now with some tweaking but this is hard when you don't have access to the server in a shared environment) work with a lower version such as: 6.2.4

    Haven't noticed any syntax difference and my code works the same, so i'm ok with it!

    :D :D :D :D :D
  12. carpe-diem

    carpe-diem Perch

    Stephen, today I tried again and even with latest mysql connector 6.5.4 I still get the following error:
    [SecurityException: Request for the permission of type 'System.Security.Permissions.SecurityPermission, mscorlib, Version=, Culture=neutral, PublicKeyToken=b77a5c561934e089' failed.]
    MySql.Data.MySqlClient.MySqlConnectionStringBuilder.CreatePermissionSet() +0
    MySql.Data.MySqlClient.MySqlConnectionStringBuilder.DemandPermissions() +38
    MySql.Data.MySqlClient.MySqlConnection.PermissionDemand() +94
    MySql.Data.MySqlClient.MySqlConnection.Open() +196
    NHibernate.Connection.DriverConnectionProvider.GetConnection() +104
    NHibernate.Tool.hbm2ddl.SuppliedConnectionProviderConnectionHelper.Prepare() +15
    NHibernate.Tool.hbm2ddl.SchemaMetadataUpdater.GetReservedWords(Dialect dialect, IConnectionHelper connectionHelper) +89
    NHibernate.Tool.hbm2ddl.SchemaMetadataUpdater.Update(ISessionFactory sessionFactory) +80
    NHibernate.Impl.SessionFactoryImpl..ctor(Configuration cfg, IMapping mapping, Settings settings, EventListeners listeners) +602
    NHibernate.Cfg.Configuration.BuildSessionFactory() +104
    FluentNHibernate.Cfg.FluentConfiguration.BuildSessionFactory() +49

    I tried adding the allowpartiallytrustedcallers attribute as rvhost did but it did not solve the exception (it did solve the exception if i use .NET 3.5, but then I can't use razor).
    I tried several mysql connector versions but neither worked.

    ticket #FHN-38150-303
  13. Stephen

    Stephen US Operations Staff Member

    We generally have the MySQL.Data.DLL in the GAC, but it all depends on the version you are using, I think Pratik installed on your server the one you used.
  14. carpe-diem

    carpe-diem Perch

    Yes, support installed 6.5.4 in GAC but it seems mysql developers changed the required permissions so it still does not work, requesting mysqlclientpermission (Exception Details: System.Security.SecurityException: Request for the permission of type 'MySql.Data.MySqlClient.MySqlClientPermission, MySql.Data, Version=, Culture=neutral, PublicKeyToken=c5687fc88969c44d' failed.)

    There is a solution at but requires modification of web_mediumtrust.config
  15. Stephen

    Stephen US Operations Staff Member

    This was done, did not realize the most recent version needed a change from the prior revisions until this, sometimes it is hard to keep up with every new requirement thrown out there!
  16. carpe-diem

    carpe-diem Perch

    I appreciate your effort. Now I can use razor with fluent-nhibernate and mysql. If anyone wants to do that here's a hint: set reflection-optimizer usage to false in web.config's nhibernate configuration section:
    <section name="hibernate-configuration" requirePermission="false" type="NHibernate.Cfg.ConfigurationSectionHandler, NHibernate" />

    <hibernate-configuration xmlns="urn:nhibernate-configuration-2.2">
    <reflection-optimizer use="true" />

Share This Page

JodoHost - 26,000 hosting end-users in 100 countries
Plesk Web Hosting
VPS Hosting
H-Sphere Web Hosting
Other Services