Security Exception ( System.Security.SecurityException: Request for the permission of type 'System.Security.Permissions)

Discussion of open issues, suggestions and bugs regarding ADO.NET provider for MySQL
Post Reply
cesarvegamx
Posts: 37
Joined: Tue 30 Jan 2007 07:43

Security Exception ( System.Security.SecurityException: Request for the permission of type 'System.Security.Permissions)

Post by cesarvegamx » Fri 09 Mar 2007 01:42

So, I'm getting this error:
Security Exception
Description: The application attempted to perform an operation not allowed by the security policy. To grant this application the required permission please contact your system administrator or change the application's trust level in the configuration file.

Exception Details: System.Security.SecurityException: Request for the permission of type 'System.Security.Permissions.SecurityPermission, mscorlib, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089' failed.
The error happen just when deploying the application to a shared host with medium trust level. It does not happen when there's full trust.

You can see the error here:
http://desktopdatabases.com/default2.aspx

aukinfo
Posts: 1
Joined: Thu 08 Mar 2007 00:03

Workaround

Post by aukinfo » Fri 09 Mar 2007 16:26

Hi, I have had the very same problem.

I am also in a medium trust env, running Version=3.55.20.0.

My login page was giving me the security error. But then I found that after I accessed a different page which permed a db connection, I was able to log on.
So I have put the following in the global.asax file application_start event and now all is fine again...apart from my other bugs

/* For some reason, this stops the security error seen in Medium Trust Environment */
CoreLab.MySql.MySqlConnection connection =
new CoreLab.MySql.MySqlConnection(ConfigurationManager.ConnectionStrings["cocConnectionString"].ConnectionString);
connection.Open();

CoreLab.MySql.MySqlCommand command = new CoreLab.MySql.MySqlCommand("Select '' from aspnet_profiles;", connection);
command.ExecuteNonQuery();

cesarvegamx
Posts: 37
Joined: Tue 30 Jan 2007 07:43

Post by cesarvegamx » Sat 10 Mar 2007 03:38

Well, in my case, I'm not even using asp.net membership!.

It is a simple query to a test table.

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

Post by Alexey » Mon 12 Mar 2007 08:21

cesarvegamx, are you granted SocketPermissions by your hosting parties?

cesarvegamx
Posts: 37
Joined: Tue 30 Jan 2007 07:43

Post by cesarvegamx » Mon 12 Mar 2007 15:52

Yes, see the web_mediumtrust.config on my provider:

Code: Select all


    
        
            
                
                    
                        
                        
                        
                        
                        
                        
                        
                        
                        
                        
                        
                        
                        
                        
                        
                        
                        
                        
                        
                        
                        
			
			
			
                    
                    
                        
                        
                        
                            
                            
                            
                            
                            
                            
                            
                            
                            
                            
                            
                            
                            
                            
			    

			    

			    
                        
                    
                    
                        
                        
                            
                        
                        
                            
                        
                        
                        	
                            
                                
                            
                            
                                
                            
                        
                    
                
            
        
    

cesarvegamx
Posts: 37
Joined: Tue 30 Jan 2007 07:43

Post by cesarvegamx » Mon 12 Mar 2007 15:57

Code: Select all

Is MySQLDirect .NET installed on the target machine (or at least CoreLab.*.dll assemblies are registered in the GAC)?
No, it is a shared hosting.

Code: Select all

Do you use direct mode?
Yes.
When exactly that error occurs? On Connection.Open() call?
It seems it is originated here: CoreLab.MySql.MySqlDirectFactory.CreateConnection()
You can see the stack trace in this sample site:
http://desktopdatabases.com/default2.aspx
Could you provide me with your web.config file and medium trust config file on the shared host?
The medium trust config file is in the post above.
The web.config was already sent by email on friday, together with the whole repro application.

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

Post by Alexey » Tue 13 Mar 2007 13:10

Your project is received and is being investigated.

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

Post by Alexey » Wed 14 Mar 2007 09:37

We have fixed the problem in MySQLDirect .NET beta. Look forward to the release, which is gonna be available this month.

Post Reply