473,232 Members | 1,400 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,232 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 2428
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: jianzs | last post by:
Introduction Cloud-native applications are conventionally identified as those designed and nurtured on cloud infrastructure. Such applications, rooted in cloud technologies, skillfully benefit from...
2
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 7 Feb 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:30 (7.30PM). In this month's session, the creator of the excellent VBE...
0
by: fareedcanada | last post by:
Hello I am trying to split number on their count. suppose i have 121314151617 (12cnt) then number should be split like 12,13,14,15,16,17 and if 11314151617 (11cnt) then should be split like...
0
by: stefan129 | last post by:
Hey forum members, I'm exploring options for SSL certificates for multiple domains. Has anyone had experience with multi-domain SSL certificates? Any recommendations on reliable providers or specific...
0
Git
by: egorbl4 | last post by:
Скачал я git, хотел начать настройку, а там вылезло вот это Что это? Что мне с этим делать? ...
0
by: DolphinDB | last post by:
The formulas of 101 quantitative trading alphas used by WorldQuant were presented in the paper 101 Formulaic Alphas. However, some formulas are complex, leading to challenges in calculation. Take...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: Aftab Ahmad | last post by:
Hello Experts! I have written a code in MS Access for a cmd called "WhatsApp Message" to open WhatsApp using that very code but the problem is that it gives a popup message everytime I clicked on...
0
by: Aftab Ahmad | last post by:
So, I have written a code for a cmd called "Send WhatsApp Message" to open and send WhatsApp messaage. The code is given below. Dim IE As Object Set IE =...

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.