By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
455,566 Members | 1,734 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 455,566 IT Pros & Developers. It's quick & easy.

Security exception while opening an OleDBConnection

P: n/a
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.IPo stBackEventHandler.RaisePostBackEvent(String eventArgument) +57
System.Web.UI.Page.RaisePostBackEvent(IPostBackEve ntHandler
sourceControl, String eventArgument) +18
System.Web.UI.Page.RaisePostBackEvent(NameValueCol lection 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.Htt pApplication+IExecutionStep.Execute() +179
System.Web.HttpApplication.ExecuteStep(IExecutionS tep 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

Feb 3 '06 #1
Share this Question
Share on Google+
5 Replies


P: n/a
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.IPo stBackEventHandler.RaisePostBackEvent(String eventArgument) +57
System.Web.UI.Page.RaisePostBackEvent(IPostBackEve ntHandler
sourceControl, String eventArgument) +18
System.Web.UI.Page.RaisePostBackEvent(NameValueCol lection 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.Htt pApplication+IExecutionStep.Execute() +179
System.Web.HttpApplication.ExecuteStep(IExecutionS tep 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

Feb 3 '06 #2

P: n/a

"CyberLotus" <Cy********@discussions.microsoft.com> wrote in message
news:D6**********************************@microsof t.com...
| 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.IPo stBackEventHandler.RaisePostBackEvent(String
eventArgument) +57
| System.Web.UI.Page.RaisePostBackEvent(IPostBackEve ntHandler
| sourceControl, String eventArgument) +18
| System.Web.UI.Page.RaisePostBackEvent(NameValueCol lection 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.Htt pApplication+IExecutionStep.Execute()
+179
| System.Web.HttpApplication.ExecuteStep(IExecutionS tep 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
|

Seems like you are loading and running this from a network share, right?
In that case you need to adjust your security policy settings, search MSDN
for details about caspol.exe, this utility can be used to set the correct
policy for your scenario.

Willy.

Feb 3 '06 #3

P: n/a

"Willy Denoyette [MVP]" <wi*************@telenet.be> wrote in message
news:u3*************@TK2MSFTNGP14.phx.gbl...
|
||
|
| Seems like you are loading and running this from a network share, right?
| In that case you need to adjust your security policy settings, search MSDN
| for details about caspol.exe, this utility can be used to set the correct
| policy for your scenario.
|
| Willy.
|

Sorry should be "running this from an internet site". But the same policy
applies, your web service doesn't have sufficient trust to access the
(local/remote?) file (excel).

Willy.


Feb 3 '06 #4

P: n/a
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.IPo stBackEventHandler.RaisePostBackEvent(String eventArgument) +57
System.Web.UI.Page.RaisePostBackEvent(IPostBackEve ntHandler
sourceControl, String eventArgument) +18
System.Web.UI.Page.RaisePostBackEvent(NameValueCol lection 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.Htt pApplication+IExecutionStep.Execute() +179
System.Web.HttpApplication.ExecuteStep(IExecutionS tep 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

Feb 7 '06 #5

P: n/a
System.Security.SecurityException has nothing to do with your
connectionstring, these kind of exceptions are code access security (CAS)
related. That is "where do you load" the executing asssembly from (e.i from
a network share/mapped drive) and what do you expect this code to do with
respect to security policy privileges. Please read all about CAS and the
Caspol utility in the framework dosc.
Willy.

"CyberLotus" <Cy********@discussions.microsoft.com> wrote in message
news:69**********************************@microsof t.com...
| 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.IPo stBackEventHandler.RaisePostBackEvent(String
eventArgument) +57
| > > System.Web.UI.Page.RaisePostBackEvent(IPostBackEve ntHandler
| > > sourceControl, String eventArgument) +18
| > > System.Web.UI.Page.RaisePostBackEvent(NameValueCol lection 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.Htt pApplication+IExecutionStep.Execute()
+179
| > > System.Web.HttpApplication.ExecuteStep(IExecutionS tep 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
| > >
Feb 7 '06 #6

This discussion thread is closed

Replies have been disabled for this discussion.