RE: Security exception while opening an OleDBConnection

Tech-Archive recommends: Repair Windows Errors & Optimize Windows Performance



Hi Peter,

I tried with the quick test that you mentioned and there's no anomaly in the
connection string.
Please let me know what could be the issue.

Thanks.


"Peter Bromberg [C# MVP]" wrote:

Lotus,
You can start out by ensuring the windows identity your ASP.NET app is
running under has full permissions on the folder the Excel workbook resides
in. If you want a quick test,
add an
<identity impersonate="true" userName="AdminAccount" password="pass" />
element to your web.config to make the app run under an Administrator
account temporarily. Normally this account would have full permissions so
it's a quick way to test if that's the issue.

Otherwise, it could be some anomalies in your connection string.

Peter

--
Co-founder, Eggheadcafe.com developer portal:
http://www.eggheadcafe.com
UnBlog:
http://petesbloggerama.blogspot.com




"CyberLotus" wrote:

Hi,

I've created a web application and through this I want to import Excel data
to database.
Following is the code that I've written,

*******************************************************************
string fileLocation = txtboxFileName.Text.ToString();
string sheetName = "Import";
string connectionString = @"Provider=Microsoft.Jet.OLEDB.4.0;Data
Source="+fileLocation+";Extended Properties=Excel 8.0";
string strSQL = "select * from ["+sheetName+"$]";

OleDbConnection cn = new OleDbConnection(connectionString); // It's failing
here

cn.Open();
OleDbCommand cm = new OleDbCommand(strSQL,cn);
OleDbDataAdapter da = new OleDbDataAdapter(cm);
DataSet excelDS = new DataSet();
da.Fill(excelDS);
.....................
.....................
.....................
*******************************************************************

I've used OleDBConnection for reading the excel, but it's giving me a
Security Exception.
Here's the exception:

####################################################################
Server Error in '/PreSa' 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 failed.

Source Error:

An unhandled exception was generated during the execution of the current web
request. Information regarding the origin and location of the exception can
be identified using the exception stack trace below.

Stack Trace:

[SecurityException: Request failed.]
Try2.WebUserControl2.btnSend_Click(Object sender, EventArgs e) +0
System.Web.UI.WebControls.Button.OnClick(EventArgs e) +108

System.Web.UI.WebControls.Button.System.Web.UI.IPostBackEventHandler.RaisePostBackEvent(String eventArgument) +57
System.Web.UI.Page.RaisePostBackEvent(IPostBackEventHandler
sourceControl, String eventArgument) +18
System.Web.UI.Page.RaisePostBackEvent(NameValueCollection postData) +33
System.Web.UI.Page.ProcessRequestMain() +2112
System.Web.UI.Page.ProcessRequest() +217
System.Web.UI.Page.ProcessRequest(HttpContext context) +18

System.Web.CallHandlerExecutionStep.System.Web.HttpApplication+IExecutionStep.Execute() +179
System.Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean&
completedSynchronously) +87




--------------------------------------------------------------------------------
Version Information: Microsoft .NET Framework Version:1.1.4322.2300; ASP.NET
Version:1.1.4322.2300

####################################################################

Please help me as it's very urgent.

Thanks a ton.


Regards,
Lotus

.



Relevant Pages

  • Re: Still unable to connect to SQL database on non-development machine
    ... the exception class has numerous properties that will return ... So, as the client machine is within the IT department, it has ... you need to have a DSN created on the machine that will be using ... Let's simplify it and stick with your original connection string. ...
    (microsoft.public.dotnet.framework.adonet)
  • Re: Connection state open even without a server or database?
    ... But, as you found out, you'll always get a dial tone. ... allowing the user to point the connection wherever they like). ... That would just mean you get an exception a little earlier. ... instantiating and passing the connection string are like ...
    (microsoft.public.dotnet.framework.adonet)
  • RE: Security exception while opening an OleDBConnection
    ... Normally this account would have full permissions so ... I've created a web application and through this I want to import Excel data ... Security Exception. ...
    (microsoft.public.dotnet.languages.csharp)
  • Re: slow ADO refresh, ending in error message
    ... ...also, when I used the OLE connection string, I get an exception with ... >>I don't know the error code because the exception is in the debugger, ... >>Debugger Exception Notification ...
    (borland.public.delphi.database.ado)
  • Re: slow ADO refresh, ending in error message
    ... with that connection string I no longer get the error ... >>I don't know the error code because the exception is in the debugger, ... There's no place to trap the exception in the code since ... >>Debugger Exception Notification ...
    (borland.public.delphi.database.ado)