Sql – ASP.NET 2.0 cannot open SqlConnection

asp.netiis-6sql-server-2005

Using:
IIS 6;
Anonymous Authentication (with a user that belongs to the administrators group);
SQL Server 2005;
.NET 2.0

Web.config:

<system.web>
    <securityPolicy>
      <trustLevel name="Full" policyFile="internal" />
    </securityPolicy>
  </system.web>

<identity impersonate="true"/>

I have this exception when I try to Open a SQLConnection:

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.Data.SqlClient.SqlClientPermission, System.Data, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089' failed.

What could it be?

Best Answer

Does xpto2 have the relevant access permissions for the database? Does the service account have the relevant access permissions for the database file, if its a file?

If you are writing an application, that requires that you write data to a database or a text file then you will need to check and if necessary change the permissions on the server so that you have write as well as read permissions on the directory, and database or text file, you wish to write too.(This is only possible if you have full control over these things of course)

CAS or Code Access Security on the .Net platform is a seperate concern. Code access security allows code to be trusted to varying degrees depending on where the code originates and on other aspects of the code's identity. Code access security also enforces the varying levels of trust on code, which minimizes the amount of code that must be fully trusted in order to run. Since you have given the code full access its not the problem.

Could you check this guide (since you are using II6).