473,378 Members | 1,317 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,378 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
3 1173
On Fri, 3 Feb 2006 04:30:40 -0800, "CyberLotus"
<Cy********@discussions.microsoft.com> wrote:

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


Someone has configured your application (or all web applications on
the machine) to run at less than full trust.

I'd start by looking in machine.config
(%WindowsDir%\Microsoft.NET\Framework\v1.1.4322\CO NFIG)
for an element like: <trust level="Medium" ... />.

If not in machine.config, you might find it in your own web.config, or
a web.config in a higher directory.

See Using Code Access Security with ASP.NET [1] for more information.

[1]
http://msdn.microsoft.com/library/de...l/THCMCh09.asp
--
Scott
http://www.OdeToCode.com/blogs/scott/
Feb 3 '06 #2
No Scott,
It's still in "Full"...Even though am getting the error.
Please help me.

Thanks.

"Scott Allen" wrote:
On Fri, 3 Feb 2006 04:30:40 -0800, "CyberLotus"
<Cy********@discussions.microsoft.com> wrote:

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


Someone has configured your application (or all web applications on
the machine) to run at less than full trust.

I'd start by looking in machine.config
(%WindowsDir%\Microsoft.NET\Framework\v1.1.4322\CO NFIG)
for an element like: <trust level="Medium" ... />.

If not in machine.config, you might find it in your own web.config, or
a web.config in a higher directory.

See Using Code Access Security with ASP.NET [1] for more information.

[1]
http://msdn.microsoft.com/library/de...l/THCMCh09.asp
--
Scott
http://www.OdeToCode.com/blogs/scott/

Feb 7 '06 #3
On Mon, 6 Feb 2006 21:10:27 -0800, "CyberLotus"
<Cy********@discussions.microsoft.com> wrote:
No Scott,
It's still in "Full"...Even though am getting the error.
Please help me.

Thanks.


What operating system? Is this a server you own or is it hosted?

--
Scott
http://www.OdeToCode.com/blogs/scott/
Feb 7 '06 #4

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. ...
16
by: Mr. B | last post by:
VB.net 2003; MS Access db; Netframe 1.1 I wrote an Windows app for my last place of employment that opened and modified a couple of MS Access db files. I did most of my programming at home on...
5
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...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
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...

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.