I try to connect from webpart to database server. Error happen in the line:


Request for the permission of type 'System.Data.SqlClient.SqlClientPermission, System.Data, Version=, Culture=neutral, PublicKeyToken=b77a5c561934e089' failed.

I'm using Sharepoint 2013 version.

1 Answer 1


You should deploy the assembly of the web part to the Global Assembly Cache (GAC), configure full trust for the application in the web config, or create a custom trust, that allows this kind of database interaction.

I suggest you to read the following articles to get a deeper insight into the Codes Access Security:

Microsoft Windows SharePoint Services and Code Access Security

Code Access Security and SharePoint 2007 Web Parts

  • I'm using Visual Webpart so there is no web config. What is the instead solution to trust for app.
    – tbbt
    Commented Mar 19, 2015 at 8:10
  • Web.config is always there in the root of the SharePoint web application in IIS.
    – pholpar
    Commented Mar 19, 2015 at 8:31
  • The typical path where you should find the web.config file is C:\inetpub\wwwroot\wss\VirtualDirectories[your web app name]
    – pholpar
    Commented Mar 19, 2015 at 8:41

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.