error reading excel using OleDb

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Abel

    error reading excel using OleDb

    Hi
    I try to execute an sample how to read and write excel sheets using OleDb
    When opens the connection, the objConn.Open gave me this error:
    "Request for the permission of type 'System.Data.Ol eDb.OleDbPermis sion,
    System.Data, Version=2.0.0.0 , Culture=neutral ,
    PublicKeyToken= b77a5c561934e08 9' failed."
    And appears the following message:
    System.Exceptio n {System.Securit y.SecurityExcep tion}
    Any idea to solve this error?
    I work with VS 2005, using C#
    TIA
    Abel
  • Nicholas Paldino [.NET/C# MVP]

    #2
    Re: error reading excel using OleDb

    Are you doing this in ASP.NET perhaps, and trying to access an Excel
    sheet on a network share, or on a part of the drive that ASPNET doesn't have
    access to?


    --
    - Nicholas Paldino [.NET/C# MVP]
    - mvp@spam.guard. caspershouse.co m

    "Abel" <Abel@discussio ns.microsoft.co mwrote in message
    news:89662F65-D332-49B4-80A9-2B496A27860B@mi crosoft.com...
    Hi
    I try to execute an sample how to read and write excel sheets using OleDb
    When opens the connection, the objConn.Open gave me this error:
    "Request for the permission of type 'System.Data.Ol eDb.OleDbPermis sion,
    System.Data, Version=2.0.0.0 , Culture=neutral ,
    PublicKeyToken= b77a5c561934e08 9' failed."
    And appears the following message:
    System.Exceptio n {System.Securit y.SecurityExcep tion}
    Any idea to solve this error?
    I work with VS 2005, using C#
    TIA
    Abel

    Comment

    • sloan

      #3
      Re: error reading excel using OleDb

      I'd concur.

      Permissions on the file, usually because of an asp.net environment.

      Also, you have to be very anal with the connection string with excel. Every
      space and ; matters.



      "Abel" <Abel@discussio ns.microsoft.co mwrote in message
      news:89662F65-D332-49B4-80A9-2B496A27860B@mi crosoft.com...
      Hi
      I try to execute an sample how to read and write excel sheets using OleDb
      When opens the connection, the objConn.Open gave me this error:
      "Request for the permission of type 'System.Data.Ol eDb.OleDbPermis sion,
      System.Data, Version=2.0.0.0 , Culture=neutral ,
      PublicKeyToken= b77a5c561934e08 9' failed."
      And appears the following message:
      System.Exceptio n {System.Securit y.SecurityExcep tion}
      Any idea to solve this error?
      I work with VS 2005, using C#
      TIA
      Abel

      Comment

      • Abel

        #4
        Re: error reading excel using OleDb

        Nicholas
        This is my code:
        Is a class program, to process in backoffice

        public System.Data.Dat aSet GetDataFromExce lFile(String File_name) {
        try {
        string strConn = "Provider=Micro soft.Jet.OLEDB. 4.0;";
        strConn += "Data Source= " + File_name + "; Extended Properties=Exce l
        8.0;HDR=Yes;IME X=1";
        OleDbConnection ObjConn = new OleDbConnection (strConn);
        ====here fails => ObjConn.Open();
        OleDbCommand ObjCmd = new OleDbCommand("S ELECT * FROM [ExcelFileTest$]",
        ObjConn);
        OleDbDataAdapte r objDA = new OleDbDataAdapte r();
        objDA.SelectCom mand = ObjCmd;
        DataSet ObjDataSet = new DataSet();
        objDA.Fill(ObjD ataSet);
        ObjConn.Close() ;
        return ObjDataSet;
        } catch(Exception excepcion) {
        return null;
        }
        }

        "Nicholas Paldino [.NET/C# MVP]" wrote:
        Are you doing this in ASP.NET perhaps, and trying to access an Excel
        sheet on a network share, or on a part of the drive that ASPNET doesn't have
        access to?
        >
        >
        --
        - Nicholas Paldino [.NET/C# MVP]
        - mvp@spam.guard. caspershouse.co m
        >
        "Abel" <Abel@discussio ns.microsoft.co mwrote in message
        news:89662F65-D332-49B4-80A9-2B496A27860B@mi crosoft.com...
        Hi
        I try to execute an sample how to read and write excel sheets using OleDb
        When opens the connection, the objConn.Open gave me this error:
        "Request for the permission of type 'System.Data.Ol eDb.OleDbPermis sion,
        System.Data, Version=2.0.0.0 , Culture=neutral ,
        PublicKeyToken= b77a5c561934e08 9' failed."
        And appears the following message:
        System.Exceptio n {System.Securit y.SecurityExcep tion}
        Any idea to solve this error?
        I work with VS 2005, using C#
        TIA
        Abel
        >
        >
        >

        Comment

        • Abel

          #5
          Re: error reading excel using OleDb

          Sloan
          See my answer to Nicholas, this isnt an ASP Program, is winforms
          Yo can see my code
          This is an environment problem
          You can see on the stacktrace:

          StackTrace " at System.Security .CodeAccessSecu rityEngine.Chec k(Object
          demand, StackCrawlMark& stackMark, Boolean isPermSet)\r\n at
          System.Security .PermissionSet. Demand()\r\n at
          System.Data.Com mon.DbConnectio nOptions.Demand Permission()\r\ n at
          System.Data.Ole Db.OleDbConnect ion.PermissionD emand()\r\n at
          System.Data.Ole Db.OleDbConnect ionFactory.Perm issionDemand(Db Connection
          outerConnection )\r\n at
          System.Data.Pro viderBase.DbCon nectionClosed.O penConnection(D bConnection
          outerConnection , DbConnectionFac tory connectionFacto ry)\r\n at
          System.Data.Ole Db.OleDbConnect ion.Open()\r\n at
          ProcessExcelFil e.Form1.GetData FromExcelFile(S tring File_name)"
          Understand?
          Regards
          Abel

          "sloan" wrote:
          I'd concur.
          >
          Permissions on the file, usually because of an asp.net environment.
          >
          Also, you have to be very anal with the connection string with excel. Every
          space and ; matters.
          >
          >
          >
          "Abel" <Abel@discussio ns.microsoft.co mwrote in message
          news:89662F65-D332-49B4-80A9-2B496A27860B@mi crosoft.com...
          Hi
          I try to execute an sample how to read and write excel sheets using OleDb
          When opens the connection, the objConn.Open gave me this error:
          "Request for the permission of type 'System.Data.Ol eDb.OleDbPermis sion,
          System.Data, Version=2.0.0.0 , Culture=neutral ,
          PublicKeyToken= b77a5c561934e08 9' failed."
          And appears the following message:
          System.Exceptio n {System.Securit y.SecurityExcep tion}
          Any idea to solve this error?
          I work with VS 2005, using C#
          TIA
          Abel
          >
          >
          >

          Comment

          Working...