如何解决错误System.Data.OleDb.OleDbPermission,System.Data,Version = 4.0.0.0,Culture = neutral,PublicKeyToken = b77a5c561934e089'失败

时间:2015-10-28 10:12:52

标签: c# .net oledb

我在将我的网站上传到服务器时遇到此错误,但在本地主机上工作正常如何解决此错误

Server Error in '/' Application.
    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.Data.OleDb.OleDbPermission, System.Data, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089' failed.

Source Error:


Line 32:         //con = new SqlConnection(constr);
Line 33:         con = new OleDbConnection(constr);
Line 34:         con.Open();
Line 35: 
Line 36: 

我的网络配置文件

<?xml version="1.0" encoding="utf-8"?>

<configuration>
  <configSections>

    <section name="entityFramework" type="System.Data.Entity.Internal.ConfigFile.EntityFrameworkSection, EntityFramework, Version=6.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" requirePermission="false" />
  </configSections>
  <connectionStrings>
    <add name="air" connectionString="Provider=Microsoft.Jet.OLEDB.4.0;Data Source=|DataDirectory|\ICPSIndia.mdb;"/>
    <add name="libraryconnection" connectionString="Data Source=11.11.11.11;Initial Catalog=library;Persist Security Info=True;User ID=myid;Password=mypass;"/>
  </connectionStrings>
  <appSettings>
    <add key="webpages:Version" value="3.0.0.0" />
    <add key="webpages:Enabled" value="false" />
    <add key="ClientValidationEnabled" value="true" />
    <add key="UnobtrusiveJavaScriptEnabled" value="true" />
  </appSettings>


  <system.web>

    <customErrors mode="Off"/>

    <authentication mode="Windows"/>

<httpRuntime requestValidationMode="2.0" /> 

    <compilation debug="true" targetFramework="4.5.1" />

  </system.web>

  <system.webServer>
    <validation validateIntegratedModeConfiguration="false"/>
    <modules>
      <remove name="FormsAuthenticationModule" />
    </modules>
    <handlers>
      <add name="AjaxFileUploadHandler" verb="POST" path="AjaxFileUploadHandler.axd" type="AjaxControlToolkit.AjaxFileUploadHandler, AjaxControlToolkit"/>
    </handlers>


  </system.webServer>
  <runtime>
    <assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
      <dependentAssembly>
        <assemblyIdentity name="System.Web.Helpers" publicKeyToken="31bf3856ad364e35" />
        <bindingRedirect oldVersion="1.0.0.0-3.0.0.0" newVersion="3.0.0.0" />
      </dependentAssembly>
      <dependentAssembly>
        <assemblyIdentity name="System.Web.Mvc" publicKeyToken="31bf3856ad364e35" />
        <bindingRedirect oldVersion="1.0.0.0-5.1.0.0" newVersion="5.1.0.0" />
      </dependentAssembly>
      <dependentAssembly>
        <assemblyIdentity name="System.Web.Optimization" publicKeyToken="31bf3856ad364e35" />
        <bindingRedirect oldVersion="1.0.0.0-1.1.0.0" newVersion="1.1.0.0" />
      </dependentAssembly>
      <dependentAssembly>
        <assemblyIdentity name="System.Web.WebPages" publicKeyToken="31bf3856ad364e35" />
        <bindingRedirect oldVersion="1.0.0.0-3.0.0.0" newVersion="3.0.0.0" />
      </dependentAssembly>
      <dependentAssembly>
        <assemblyIdentity name="WebGrease" publicKeyToken="31bf3856ad364e35" />
        <bindingRedirect oldVersion="1.0.0.0-1.5.2.14234" newVersion="1.5.2.14234" />
      </dependentAssembly>
    </assemblyBinding>
  </runtime>
  <entityFramework>
    <defaultConnectionFactory type="System.Data.Entity.Infrastructure.LocalDbConnectionFactory, EntityFramework">
      <parameters>
        <parameter value="v11.0" />
      </parameters>
    </defaultConnectionFactory>
    <providers>
      <provider invariantName="System.Data.SqlClient" type="System.Data.Entity.SqlServer.SqlProviderServices, EntityFramework.SqlServer" />
    </providers>
  </entityFramework>
</configuration>

用于连接的我的类文件

using System;
using System.Data;
//using System.Data.SqlClient;
using System.Data.OleDb;
//using System.Data.SqlClient;
using System.Configuration;

using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;


/// <summary>
/// Summary description for Class1
/// </summary>
public class Class1
{
    public OleDbConnection con;
    public OleDbCommand cmd;
    public OleDbDataReader dr;

    String constr;
    public Class1()
    {
        constr = ConfigurationManager.ConnectionStrings["air"].ToString();
    }
    public void conopen()
    {
        //con = new SqlConnection(constr);
        con = new OleDbConnection(constr);
        con.Open();


    }
    public void conclose()
    {
        con.Close();
    }

我已经读过有信任级别,但我无法使用每次我在线服务器上打开网页时int给了我同样的错误

0 个答案:

没有答案