RE: Security exception while opening an OleDBConnection



steps to grant rights

1.Select Excel file.
2.Rigth click and click property.
3.Select Security tab.
4. Add ASPNET user

ASPNET user will have access to excel file.

"CyberLotus" wrote:

Hi Narendra,

I'm using windows authentication.
Also, I'm using ASPNET account. But, how to check whether it has access to
excel or not?

Please let me know.

Thanks.


"Narendra" wrote:

Couple of questions to understand your configuration......

which authentication are you using?

Which user process is making a database connection? And this user process
should have access to Excel File. For example by default, ASP.NET account is
used to access database. Are you using ASP.NET or some other account? Make
sure it has access to Excel File.

regards,
narendra

"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: Attach to open Excel process
    ... should set wb = Nothing to release the reference. ... As for the question of checking whether a specific Excel file is open, ... we need to do is to try to open the specified file. ... Catch ex As Exception ...
    (microsoft.public.dotnet.framework.windowsforms)
  • Re: Upload/DownLoad from Excel
    ... Don't catch exception if you don't do anything else than ASP.NET do. ... information in my database by the page. ... this is the code I am using to Upload from sql to excel: ... this works perfectly and I have an excel file on my desktop. ...
    (microsoft.public.dotnet.framework.aspnet)
  • Re: OLE and excel on Windows 2003 server
    ... Opening an Excel file from Explorer invokes DDE. ... Your ERP app uses COM. ... server local security. ...
    (microsoft.public.excel.programming)
  • RE: Security exception while opening an OleDBConnection
    ... Which user process is making a database connection? ... should have access to Excel File. ... Security Exception. ...
    (microsoft.public.dotnet.security)
  • Re: Deploying Excel file created with VSTO
    ... It's just tightening up security. ... Macros can run with little security ... and when I click that button, it opens up a form. ... Excel file, no button appears. ...
    (microsoft.public.vsnet.vstools.office)