473,396 Members | 2,011 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,396 software developers and data experts.

error reading excel using OleDb

Hi
I try to execute an sample how to read and write excel sheets using OleDb
When opens the connection, the objConn.Open gave me this error:
"Request for the permission of type 'System.Data.OleDb.OleDbPermission,
System.Data, Version=2.0.0.0, Culture=neutral,
PublicKeyToken=b77a5c561934e089' failed."
And appears the following message:
System.Exception {System.Security.SecurityException}
Any idea to solve this error?
I work with VS 2005, using C#
TIA
Abel
Sep 6 '06 #1
4 6393
Are you doing this in ASP.NET perhaps, and trying to access an Excel
sheet on a network share, or on a part of the drive that ASPNET doesn't have
access to?
--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard.caspershouse.com

"Abel" <Ab**@discussions.microsoft.comwrote in message
news:89**********************************@microsof t.com...
Hi
I try to execute an sample how to read and write excel sheets using OleDb
When opens the connection, the objConn.Open gave me this error:
"Request for the permission of type 'System.Data.OleDb.OleDbPermission,
System.Data, Version=2.0.0.0, Culture=neutral,
PublicKeyToken=b77a5c561934e089' failed."
And appears the following message:
System.Exception {System.Security.SecurityException}
Any idea to solve this error?
I work with VS 2005, using C#
TIA
Abel

Sep 6 '06 #2
I'd concur.

Permissions on the file, usually because of an asp.net environment.

Also, you have to be very anal with the connection string with excel. Every
space and ; matters.

"Abel" <Ab**@discussions.microsoft.comwrote in message
news:89**********************************@microsof t.com...
Hi
I try to execute an sample how to read and write excel sheets using OleDb
When opens the connection, the objConn.Open gave me this error:
"Request for the permission of type 'System.Data.OleDb.OleDbPermission,
System.Data, Version=2.0.0.0, Culture=neutral,
PublicKeyToken=b77a5c561934e089' failed."
And appears the following message:
System.Exception {System.Security.SecurityException}
Any idea to solve this error?
I work with VS 2005, using C#
TIA
Abel

Sep 6 '06 #3
Nicholas
This is my code:
Is a class program, to process in backoffice

public System.Data.DataSet GetDataFromExcelFile(String File_name) {
try {
string strConn = "Provider=Microsoft.Jet.OLEDB.4.0;";
strConn += "Data Source= " + File_name + "; Extended Properties=Excel
8.0;HDR=Yes;IMEX=1";
OleDbConnection ObjConn = new OleDbConnection(strConn);
====here fails => ObjConn.Open();
OleDbCommand ObjCmd = new OleDbCommand("SELECT * FROM [ExcelFileTest$]",
ObjConn);
OleDbDataAdapter objDA = new OleDbDataAdapter();
objDA.SelectCommand = ObjCmd;
DataSet ObjDataSet = new DataSet();
objDA.Fill(ObjDataSet);
ObjConn.Close();
return ObjDataSet;
} catch(Exception excepcion) {
return null;
}
}

"Nicholas Paldino [.NET/C# MVP]" wrote:
Are you doing this in ASP.NET perhaps, and trying to access an Excel
sheet on a network share, or on a part of the drive that ASPNET doesn't have
access to?
--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard.caspershouse.com

"Abel" <Ab**@discussions.microsoft.comwrote in message
news:89**********************************@microsof t.com...
Hi
I try to execute an sample how to read and write excel sheets using OleDb
When opens the connection, the objConn.Open gave me this error:
"Request for the permission of type 'System.Data.OleDb.OleDbPermission,
System.Data, Version=2.0.0.0, Culture=neutral,
PublicKeyToken=b77a5c561934e089' failed."
And appears the following message:
System.Exception {System.Security.SecurityException}
Any idea to solve this error?
I work with VS 2005, using C#
TIA
Abel


Sep 7 '06 #4
Sloan
See my answer to Nicholas, this isnt an ASP Program, is winforms
Yo can see my code
This is an environment problem
You can see on the stacktrace:

StackTrace " at System.Security.CodeAccessSecurityEngine.Check(Obj ect
demand, StackCrawlMark& stackMark, Boolean isPermSet)\r\n at
System.Security.PermissionSet.Demand()\r\n at
System.Data.Common.DbConnectionOptions.DemandPermi ssion()\r\n at
System.Data.OleDb.OleDbConnection.PermissionDemand ()\r\n at
System.Data.OleDb.OleDbConnectionFactory.Permissio nDemand(DbConnection
outerConnection)\r\n at
System.Data.ProviderBase.DbConnectionClosed.OpenCo nnection(DbConnection
outerConnection, DbConnectionFactory connectionFactory)\r\n at
System.Data.OleDb.OleDbConnection.Open()\r\n at
ProcessExcelFile.Form1.GetDataFromExcelFile(String File_name)"
Understand?
Regards
Abel

"sloan" wrote:
I'd concur.

Permissions on the file, usually because of an asp.net environment.

Also, you have to be very anal with the connection string with excel. Every
space and ; matters.

"Abel" <Ab**@discussions.microsoft.comwrote in message
news:89**********************************@microsof t.com...
Hi
I try to execute an sample how to read and write excel sheets using OleDb
When opens the connection, the objConn.Open gave me this error:
"Request for the permission of type 'System.Data.OleDb.OleDbPermission,
System.Data, Version=2.0.0.0, Culture=neutral,
PublicKeyToken=b77a5c561934e089' failed."
And appears the following message:
System.Exception {System.Security.SecurityException}
Any idea to solve this error?
I work with VS 2005, using C#
TIA
Abel


Sep 7 '06 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: Roland Hall | last post by:
I have two(2) issues. I'm experiencing a little difficulty and having to resort to a work around. I already found one bug, although stated the bug was only in ODBC, which I'm not using. It...
3
by: hkappleorange | last post by:
I connect to mdb file using the following codes. How should I modify it if I want to connect to Excel instead ? <%@ Import Namespace="System.Data.OleDb" %> <% Dim conAuthors As...
4
by: Phoebe. | last post by:
Hi, Good Day! Reading 1 excel file into a dataset is fine. How can I read multiple excel with the same data structure into 1 dataset? How can I append those data? Can someone help? Thanks in...
3
by: RJN | last post by:
Hi I've a template excel file which has all the calculations defined. There are certain input values to be entered which gives a lot of output to the user. I don't want to expose the excel sheet...
9
by: dba123 | last post by:
I need some help and direction on what classes and an example or two (article) on how to read an Excel Worksheet and insert one column into a database table column. I am using .NET 2.0 only. What...
1
by: Chris Yan | last post by:
Hi All I have an excel sheet with Chinese characters in them. I'm using the OLEBE 4.0 Jet Driver in C# Microsoft Visual Studio 2005 to read from the Excel sheet and then enter into mySQL...
1
by: Ahmd | last post by:
Error: - the process cannot access the file. XXXXX.xls becuase it is being used by another process. I used OLE DB for opening EXCEL File ; - ' Connect to the Excel Spreadsheet Dim xConnStr As...
1
by: =?Utf-8?B?U2hlZXMgQWJpZGk=?= | last post by:
I read an article on the link: http://support.microsoft.com/default.aspx?scid=kb;en-us;306572 related to reading data from Excel using OLEDB The topic's heading is: How to query and display excel...
9
by: gerryR | last post by:
Hi All I've a simple web app that pulls data from an excel sheet into a small aspx page. When I browse the site through VS2005 everything works fine. When I copy the project to IIS wwwroot...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
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...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

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.