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

error reading excel using OleDb

P: n/a
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
Share this Question
Share on Google+
4 Replies


P: n/a
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

P: n/a
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

P: n/a
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

P: n/a
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 discussion thread is closed

Replies have been disabled for this discussion.