Request for the permission of type 'System.Data.SqlClient.SqlClientPermission failed
I have an ASP.NET application, using LINQ to connec to a SQL Server 2008 R2 databse.
My connection string:
Data Source=[SqlServerIp];Initi开发者_如何转开发al Catalog=[databaseName]User Id=newLogin;Password=newPassword;
When I deploy the application on my local IIS (which is not the same machine as database server) it works fine, but when I deploy application on other IIS (the same machine as SQL Server) it throws an exception:
System.Security.SecurityException: Request for the permission of type 'System.Data.SqlClient.SqlClientPermission, System.Data, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089' failed.
Anyone knows how to fix it? Maybe it is due to some bad configuration of IIS?
I would get this error when trying to run a Web Service in debug mode. I found that it was because code was on a network drive (in my case my documents was on the home drive).
I would suggest checking that the code in not a network drive.
I had faced the same problem, and I resolved this way:
Changing the app pool identity that my application uses in IIS to pre-built account NetworkService.
The default identity is ApplicationPoolIdentity, and looks like it doesn't have enough privileges to access network resources.
The security context under which your ASP.net application is running does not have permissions to load that sql client assembly. The out of the box context, ASPNET, does, so there's problem been some custom configuration that has broken it...it's difficult to say what without being able to look at the box.
But the bottom line is that the security context of the application doesn't have perms to that assembly. The following steps should get you working:
- Write a page that outputs the security context of the application:
Response.Write(System.Security.Principal.Current().WindowsIdentity.Name);
Add the user named on that page to the administrators group. This should allow the assembly to load.
Reduce the permissions of the specified user to a minimum downward from administrator.
精彩评论