473,388 Members | 1,426 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,388 software developers and data experts.

Security exception while opening an OleDBConnection

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
5 2436
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

"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

"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
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
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
by: Anja | last post by:
I have installed the new Visual Studio 2003 and implemented the FolderBrowserDialog. Everything works fine, if I open the FolderBrowserDialog before opening a Database Connection. If I open...
0
by: ecowalker | last post by:
Hello, I've try the following code in the ASPX and it throw a Security Exception in the runtime, but I've try to run on my colleagues machine without any problem. I am using XP Pro and IIS5.1...
1
by: Mech | last post by:
I am trying to connect to a simple Access Database on my c drive. I am using Windows 2000 pro; nothing special. the following code produces a security exception error. Why? string ConnStr =...
12
by: Mark | last post by:
Hello, in a simple console application I try to create a file with some code like: FileStream file = new FileStream("test.txt", FileMode.OpenOrCreate, FileAccess.Write); StreamWriter sw = new...
2
by: Daniel Conlon | last post by:
I wish to allow ASP.NET pages to make connections to Access databases using OleDBConnection. The only way I have been able to make this functionality work has been to set: Unrestricted="true"...
0
by: Petemo94 | last post by:
Folks, I am getting a "sporadic" exception that contains the following stack trace. I say sporadic b/c my DB connection usually works fine, but occasionally it fails. *** I also noted that...
1
by: spicyz | last post by:
I'm receiving an exception when my webmethod exits after opening/closing an Access database. I can reproduce this easily enough by creating a new default ASP .NET Web Service in VS.NET 2003. ...
0
by: CyberLotus | last post by:
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, ...
2
by: John Kotuby | last post by:
Hello all, Note: This is the full version of a Post that I inadvertently sent before it was complete. About a year ago I wrote a VB.NET 2003 solution that consists of a number of assemblies...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.