Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 1132
  • Last Modified:

Getting permissions error when using a embedded window user control in web page

I created a windows usercontrol that works fine when i use it with windows application, but when I try to embed it within a web page i get this error:  Request for the permission of type 'System.Data.OracleClient.OraclePermission, System.Data.OracleClient, Version=2.0.0.0, Culture=neutral,.  All the controls show up fine but when i click the button to bind the dataset to the datagrid the error happens
private void button1_Click(object sender, System.EventArgs e)
		{
			this.textBox1.Text = "test";
			DataSet ds = new DataSet(); 
			System.Data.OracleClient.OracleConnection oracle_conn;
			System.Data.OracleClient.OracleDataAdapter orad; 
			string ssql = null; 
			try 
			{ 
				oracle_conn = new OracleConnection("Data Source=databasename; User ID=xxx; Password=xxxxx;"); 
				ssql = "select * from emp_test_number"; 
				orad = new OracleDataAdapter(ssql, oracle_conn); 
				orad.Fill(ds);
				this.dataGrid1.DataSource = ds;
			} 
			catch (Exception ex) 
			{ 
				textBox1.Text = ex.Message; 
			} 
			finally 
			{ 
			
//Request for the permission of type 'System.Data.OracleClient.OraclePermission, System.Data.OracleClient, Version=2.0.0.0, Culture=neutral,
			}
		}

Open in new window

0
tentavarious
Asked:
tentavarious
  • 11
  • 5
  • 3
1 Solution
 
Bob LearnedCommented:
When a Windows application runs on a local machine, the default is to run the Local zone with Full Trust.  Web applications run in a partially trusted environment.   What line are you getting that exception on?  Do you have the full stack trace for the exception?
0
 
tentavariousAuthor Commented:
How do i get the full stack trace?  The code I showed you above, gets executed within a windows user control via my web page.  The only error I display comes from the exception message.  How do I show the full stack trace?

I changed this line of code textBox1.Text = ex.Message;
to this  textBox1.Text = ex.ToString();

System.Security.SecurityException: Request for the permission of type 'System.Data.OracleClient.OraclePermission, System.Data.OracleClient, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089' failed.
   at System.Security.CodeAccessSecurityEngine.Check(Object demand, StackCrawlMark& stackMark, Boolean isPermSet)
0
 
Anurag ThakurCommented:
i think that you are using oracle 8 or higher as your database and when you connect to the database using the windows application you are permitted to do that because the application runs under the credientials of the logged in user but for a web site the permissions are hightly restrictive
while serarching on the net i stumbled wpon the fhe following it might be helpful to you
System.Data.OracleClient requires Oracle client software version 8.1.7 or greater.

Problem
When usign System.Data.OracleClient with Oracle9i client, i got the following message while connecting to the Oracle database from and ASP.NET application. 

System.Data.OracleClient requires Oracle client software version 8.1.7 or greater.

Cause
Security permissions were not properly set when the Oracle 9i Release 2 client was installed on Windows with NTFS. The result of this is that content of the ORACLE_HOME directory is not visible to Authenticated Users on the machine; this again causes an error while the System.Data.OracleClient is communicating with the Oracle Connectivity software from an ASP.NET using Authenticated User privileges. 

Solution
To fix the problem you have to give the Authenticated Users group privilege to the Oracle Home directory. 
  • Log on to Windwos as a user with Administrator privileges.
  • Start Window Explorer and navigate to the ORACLE_HOME folder.
  • Choose properties on the ORACLE_HOME folder.
  • Click the Security tab of the Properties window.
  • Click on Authenticated Users item in the Name list.
  • Uncheck the Read and Execute box in the Permissions list under the Allow column.
  • Re-check the Read and Execute box under the Allow column
  • Click the Advanced button and in the Permission Entries verify that Authenticated Users are listed with permission = Read & Execute, and Apply To = This folder, subfolders and files. If not, edit that line and make sure that Apply To drop-down box is set to This folder, subfolders and files. This should already be set properly but it is important that you verify it.
  • Click the Ok button until you close out all of the security properties windows. The cursor may present the hour glass for a few seconds as it applies the permissions you just changed to all subfolders and files.
  • Reboot, to assure that the changes have taken effect.

0
Prepare for your VMware VCP6-DCV exam.

Josh Coen and Jason Langer have prepared the latest edition of VCP study guide. Both authors have been working in the IT field for more than a decade, and both hold VMware certifications. This 163-page guide covers all 10 of the exam blueprint sections.

 
tentavariousAuthor Commented:
Ok, I did everything you listed and still doesnt work.  I added a Everyone group and get the same responsibilities and no go on that.

The weird thing is, when I embed the user control within another windows form it works, but when I try to embed it, within a web page that is running on my computer the error shows up.  The folder should be open to everyone now, so i am not sure what is going on.
0
 
Anurag ThakurCommented:
there might be something which i might have missed out and if you google for the same problem on google you might find some more answers
0
 
Bob LearnedCommented:
What is the implication for the possibility of using Windows authentication with your web site?
0
 
tentavariousAuthor Commented:
I thought i was using Windows Authentication

Web.config

  <authentication mode="Windows" />

Is there a setting I am missing in IIS?

Another thing, what I am trying to do will work if I remove the ActiveX control and use a web datagrid, I don't get any permission issues when I do it that way on my web page.  I am testing the capabilities of using Active X controls on my webpage, I dont see why it should be any different then just binding a the same data to an asp.net datagrid.
0
 
Bob LearnedCommented:
IIS Authentication Methods dialog:

Uncheck "Allow Anonymous"
Check "Integrated Windows authentication"
IIS-Authentication-Methods.png
0
 
tentavariousAuthor Commented:
Yeah, i tried that same error
0
 
Bob LearnedCommented:
Is this an Intranet or Internet web site?  If you have internal users, then you might be able to adjust the Zone security for the Intranet zone to Full Trust.
0
 
tentavariousAuthor Commented:
This is intranet, for now I am still in debug testing within my localhost.
0
 
tentavariousAuthor Commented:
Here is the full error

System.Security.SecurityException: Request for the permission of type 'System.Data.OracleClient.OraclePermission, System.Data.OracleClient, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089' failed.
   at System.Security.CodeAccessSecurityEngine.Check(Object demand, StackCrawlMark& stackMark, Boolean isPermSet)
   at System.Security.PermissionSet.Demand()
   at System.Data.Common.DbConnectionOptions.DemandPermission()
   at System.Data.OracleClient.OracleConnection.PermissionDemand()
   at System.Data.OracleClient.OracleConnectionFactory.PermissionDemand(DbConnection outerConnection)
   at System.Data.ProviderBase.DbConnectionClosed.OpenConnection(DbConnection outerConnection, DbConnectionFactory connectionFactory)
   at System.Data.OracleClient.OracleConnection.Open()
   at System.Data.Common.DbDataAdapter.QuietOpen(IDbConnection connection, ConnectionState& originalState)
   at System.Data.Common.DbDataAdapter.FillInternal(DataSet dataset, DataTable[] datatables, Int32 startRecord, Int32 maxRecords, String srcTable, IDbCommand command, CommandBehavior behavior)
   at System.Data.Common.DbDataAdapter.Fill(DataSet dataSet, Int32 startRecord, Int32 maxRecords, String srcTable, IDbCommand command, CommandBehavior behavior)
   at System.Data.Common.DbDataAdapter.Fill(DataSet dataSet)
   at WinControls.WinTreeview.button1_Click(Object sender, EventArgs e)
The action that failed was:
Demand
The type of the first permission that failed was:
System.Data.OracleClient.OraclePermission
The Zone of the assembly that failed was:
Intranet
0
 
Anurag ThakurCommented:
0
 
tentavariousAuthor Commented:
I believe that is something similiar to what i tried,  I found this link http://support.microsoft.com/default.aspx?scid=kb;en-us;315682

Which explains how to generate a snk key and add the dll to the GAC.  I went through the page and everything went through.  I check c:\windows\assembly and my dll was there, but now when i open my page the control doesnt show up,  just a blank page with a icon.
webpage.gif
0
 
tentavariousAuthor Commented:
If i remove the key from the assembly and unistall the control shows up, but i get the same error
0
 
tentavariousAuthor Commented:
ragi007, those links seem to pertain to sql does oracle have the same Cas policy?
0
 
Bob LearnedCommented:
Try adjusting the Intranet zone to Full Trust, as shown in the attached .pdf file.
Microsoft-.NET-Framework-2.0-Con.pdf
0
 
tentavariousAuthor Commented:
I tried using oledb instead of oracle and got a simliar error dealing with Oledb instead of oracle, so I think its something on my machine and doesnt have anything to do with the database.
0
 
tentavariousAuthor Commented:
Oh man, thank you so much, that did it.  Been beating my head up against a wall for a couple days now, go figure it should be that simple.
0

Featured Post

Upgrade your Question Security!

Add Premium security features to your question to ensure its privacy or anonymity. Learn more about your ability to control Question Security today.

  • 11
  • 5
  • 3
Tackle projects and never again get stuck behind a technical roadblock.
Join Now