Solved

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

Posted on 2009-05-14
19
1,077 Views
Last Modified: 2013-12-17
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
Comment
Question by:tentavarious
  • 11
  • 5
  • 3
19 Comments
 
LVL 96

Expert Comment

by:Bob Learned
ID: 24394479
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
 

Author Comment

by:tentavarious
ID: 24395048
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
 
LVL 26

Expert Comment

by:Anurag Thakur
ID: 24395232
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
 

Author Comment

by:tentavarious
ID: 24395863
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
 
LVL 26

Expert Comment

by:Anurag Thakur
ID: 24396082
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
 
LVL 96

Expert Comment

by:Bob Learned
ID: 24396126
What is the implication for the possibility of using Windows authentication with your web site?
0
 

Author Comment

by:tentavarious
ID: 24396322
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
 
LVL 96

Expert Comment

by:Bob Learned
ID: 24396440
IIS Authentication Methods dialog:

Uncheck "Allow Anonymous"
Check "Integrated Windows authentication"
IIS-Authentication-Methods.png
0
 

Author Comment

by:tentavarious
ID: 24396473
Yeah, i tried that same error
0
How to improve team productivity

Quip adds documents, spreadsheets, and tasklists to your Slack experience
- Elevate ideas to Quip docs
- Share Quip docs in Slack
- Get notified of changes to your docs
- Available on iOS/Android/Desktop/Web
- Online/Offline

 
LVL 96

Expert Comment

by:Bob Learned
ID: 24396500
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
 

Author Comment

by:tentavarious
ID: 24396542
This is intranet, for now I am still in debug testing within my localhost.
0
 

Author Comment

by:tentavarious
ID: 24396579
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
 
LVL 26

Expert Comment

by:Anurag Thakur
ID: 24397266
0
 

Author Comment

by:tentavarious
ID: 24397513
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
 

Author Comment

by:tentavarious
ID: 24397519
If i remove the key from the assembly and unistall the control shows up, but i get the same error
0
 

Author Comment

by:tentavarious
ID: 24398220
ragi007, those links seem to pertain to sql does oracle have the same Cas policy?
0
 
LVL 96

Accepted Solution

by:
Bob Learned earned 250 total points
ID: 24398305
Try adjusting the Intranet zone to Full Trust, as shown in the attached .pdf file.
Microsoft-.NET-Framework-2.0-Con.pdf
0
 

Author Comment

by:tentavarious
ID: 24398376
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
 

Author Comment

by:tentavarious
ID: 24398425
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

Threat Intelligence Starter Resources

Integrating threat intelligence can be challenging, and not all companies are ready. These resources can help you build awareness and prepare for defense.

Join & Write a Comment

A basic question.. “What is the Garbage Collector?” The usual answer given back: “Garbage collector is a background thread run by the CLR for freeing up the memory space used by the objects which are no longer used by the program.” I wondered …
Today I had a very interesting conundrum that had to get solved quickly. Needless to say, it wasn't resolved quickly because when we needed it we were very rushed, but as soon as the conference call was over and I took a step back I saw the correct …
Access reports are powerful and flexible. Learn how to create a query and then a grouped report using the wizard. Modify the report design after the wizard is done to make it look better. There will be another video to explain how to put the final p…
This video shows how to remove a single email address from the Outlook 2010 Auto Suggestion memory. NOTE: For Outlook 2016 and 2013 perform the exact same steps. Open a new email: Click the New email button in Outlook. Start typing the address: …

758 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

18 Experts available now in Live!

Get 1:1 Help Now