Link to home
Start Free TrialLog in
Avatar of Chris Jones
Chris JonesFlag for United States of America

asked on

.NET oracle error

i get this error when i execute a query in .NET

The type initializer for 'Oracle.DataAccess.Client.OracleCommand' threw an exception.

I have the oracle client installed
i have plsql installed and it working with no issues
i have all of the server connects in the tnsnames file
Avatar of HainKurt
HainKurt
Flag of Canada image

on which line do you get that error? post the code and full error message...
Avatar of slightwv (䄆 Netminder)
slightwv (䄆 Netminder)

What is the rest of the stack trace?
Avatar of Chris Jones

ASKER

  Dim ORACLE As New Oracle.DataAccess.Client.OracleCommand


HERE IIS THE FUNC
' gets the current term that the student is in.
    Function SPRIDEN_Get_Term()
        Dim ORACLE As New Oracle.DataAccess.Client.OracleCommand
        Dim conn As Oracle.DataAccess.Client.OracleConnection
        Dim dr As Oracle.DataAccess.Client.OracleDataReader
        Dim term As String
        Dim Description As String

        conn = NewOracleConnectionWebApp()
        ORACLE.Connection = conn

        ' *****
        ' ***** Get Current Term
        ' *****
        ORACLE.CommandText = "select saturn.tamuc_get_current_term, stvterm_desc from stvterm where saturn.tamuc_get_current_term = stvterm_code"""
        dr = ORACLE.ExecuteReader

        term = dr("tamuc_get_current_term")
        Description = dr("STVTERM_DESC")


        dr.Close()
        ORACLE.Dispose()
        conn.Close()

        Return term
    End Function

Open in new window

post the full error message... the one you posted is too generic to comment...
--------------------------------------------------------------------------------

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 for the permission of type 'System.Security.Permissions.SecurityPermission, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089' 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 for the permission of type 'System.Security.Permissions.SecurityPermission, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089' failed.]
   System.StubHelpers.StubHelpers.DemandPermission(IntPtr pNMD) +0
   Oracle.DataAccess.Client.IThreadPool.CorGetMaxThreads(UInt32& MaxWorkerThreads, UInt32& MaxIOCompletionThreads) +0
   Oracle.DataAccess.Client.CThreadPool.GetMaxThreads(UInt32& MaxWorkerThreads, UInt32& MaxIOCompletionThreads) +61
   Oracle.DataAccess.Client.OraTrace.GetConfigInfo() +7172
   Oracle.DataAccess.Client.OracleInit.Initialize() +749
   Oracle.DataAccess.Client.OracleCommand..cctor() +65

 


--------------------------------------------------------------------------------
Version Information: Microsoft .NET Framework Version:4.0.30319; ASP.NET Version:4.0.30319.1
I've not see code that extracts code from a datareader without doing a dr.Read().

Check out the example at:
http://www.exforsys.com/tutorials/odp.net/odp-net-retrieving-data-using-oracledatareader.html
"The application attempted to perform an operation not allowed by the security policy."

This does not appear to be an Oracle issue.

I know enough .Net to be dangerous but not that specific error.  

Are you using Mapped network drives?

Google came across this:
http://social.msdn.microsoft.com/forums/en-US/csharpgeneral/thread/e91bfb53-5148-4122-894c-56dc0d0b6a29/

this is the error when i try to add a sql data source ORA-12541
An ORA-12541 error occurs when the listener for the destination server is down or unreachable when you try to connect. This can be due to the listener not being started or being incorrectly configured, or it can be due to a network connection problem.

copy tnsnames.ora file into oracle client network\admin folder
you may have multiple clients which one of them is not configured properly
and all other applications are using the client which is set properly...

so copy tnsnames.ora from one client to the other

everything is set  and i can ping the server
ping is a network tool not an Oracle tool.

tnsping is an Oracle Tool to see if the listener knows about the database.  I don't think tnsping is installed with the ODAC.

What does your tnsnames.ora file look like?
DWTEST =
  (DESCRIPTION =
    (ADDRESS_LIST =
      (ADDRESS = (PROTOCOL = TCP)(HOST = degreeworks1.tamu-commerce.edu)(PORT =

1521))
    )
    (CONNECT_DATA =
      (SERVICE_NAME = DWTEST)
    )
  )


B803 =
  (DESCRIPTION =
    (ADDRESS_LIST =
      (ADDRESS = (PROTOCOL = TCP)(HOST = leodb2)(PORT = 1521))
    )
    (CONNECT_DATA =
      (SERVICE_NAME = B803)
    )
  )

T803 =
  (DESCRIPTION =
    (ADDRESS_LIST =
      (ADDRESS = (PROTOCOL = TCP)(HOST = leodb2)(PORT = 1521))
    )
    (CONNECT_DATA =
      (SERVICE_NAME = T803)
    )
  )

PROD =
  (DESCRIPTION =
    (ADDRESS_LIST =
      (ADDRESS = (PROTOCOL = TCP)(HOST = leodb3)(PORT = 1521))
    )
    (CONNECT_DATA =
      (SERVICE_NAME = PROD)
    )
  )

PPRD2 =
  (DESCRIPTION =
    (ADDRESS_LIST =
      (ADDRESS = (PROTOCOL = TCP)(HOST = leodb2)(PORT = 1521))
    )
    (CONNECT_DATA =
      (SERVICE_NAME = PPRD2)
    )
  )

PPRD =
  (DESCRIPTION =
    (ADDRESS_LIST =
      (ADDRESS = (PROTOCOL = TCP)(HOST = leodb2)(PORT = 1521))
    )
    (CONNECT_DATA =
      (SERVICE_NAME = PPRD)
    )
  )

TEXR =
  (DESCRIPTION =
    (ADDRESS_LIST =
      (ADDRESS = (PROTOCOL = TCP)(HOST = leodb2)(PORT = 1521))
    )
    (CONNECT_DATA =
      (SERVICE_NAME = TEXR)
    )
  )

TEXQ =
  (DESCRIPTION =
    (ADDRESS_LIST =
      (ADDRESS = (PROTOCOL = TCP)(HOST = leodb2)(PORT = 1521))
    )
    (CONNECT_DATA =
      (SERVICE_NAME = TEXQ)
    )
  )

TEXP =
  (DESCRIPTION =
    (ADDRESS_LIST =
      (ADDRESS = (PROTOCOL = TCP)(HOST = leodb3)(PORT = 1521))
    )
    (CONNECT_DATA =
      (SERVICE_NAME = TEXP)
    )
  )

CONV =
  (DESCRIPTION =
    (ADDRESS_LIST =
      (ADDRESS = (PROTOCOL = TCP)(HOST = eagledb)(PORT = 1521))
    )
    (CONNECT_DATA =
      (SERVICE_NAME = CONV)
    )
  )

BBTS =
  (DESCRIPTION =
    (ADDRESS_LIST =
      (ADDRESS = (PROTOCOL = TCP)(HOST = lioncard)(PORT = 1521))
    )
    (CONNECT_DATA =
      (SERVICE_NAME = BBTS)
    )
  )
OK, which database are you trying to use when you get the ORA-12541?
leodb3
sorry i mean PROD
what is the full path of that tnsnames.ora you posted?
are you sure you are using this client? as I said before, yo may have different clients installed and the app may use the one which is not configured properly...
Assuming the tnsnames.ora file is in the correct location:

Log into leodb3 as oracle and make sure PROD is being listened for.  From a command prompt: lsnrctl status
prod is listening its our production srever for our campus
If the tnsnames.ora has the correct entries and is in the correct location for the client you are using and the database is being listened for, you will not get a ORA-12541.

Per the other Expert participating:  Make sure the tnsnames.ora file for your ODAC version is in the correct location.
tnsnames.ora file location

C:\oracle\product\10.2.0\client_1\NETWORK\ADMIN
Is that the only Oracle product/tool you have installed on this machine?

For example, if you downloaded and installed the ODAC separately, there is another Oracle Home.
check your registry to find oracle homes

HKEY_LOCAL_MACHINE\SOFTWARE\ORACLE

and all sub directories to find different homes and then copy tnsnames.ora to the appropriate folders...
>>check your registry to find oracle homes

Not all installs write to the registry.  The Instant Client for example.  Not sure about the ODAC XCopy install.
slightwv, if home is not in registry, how does an app will find the client files, from path variebles?
>>from path variebles?
Could be.  Might be the environment: TNS_ADMIN for example.

In the example of the Instant Client if the network\admin folder does not exist, it looks for TNS_ADMIN.  the network\admin folder is likely hard-coded into the binaries.
the network/admin folders do exist ?
Please confirm you only have one Oracle product installed.
how would you like me to confirm ?
i restarted my computer now i get an error like this


Operation is not valid due to the current state of the object.
ok i have 2 installs and my PLSQL developer works just fine.
you need to properly configure the Oracle install .Net is trying to use.  The one where the ODAC is installed.
how do i config it the install went through with no errors for oracle ?
ASKER CERTIFIED SOLUTION
Avatar of slightwv (䄆 Netminder)
slightwv (䄆 Netminder)

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
i used the tns file way of connecting and it has no issues.
If it has no issues is this question solved?

If you are still getting the error:
Again:  for which client install?

The ORA-12154 is a pretty simple error message.  There isn't a lot that can cause this.  I'm still thinking you have more than one Oracle product installed and the ODP.Net install your .Net app is using doesn't have a correct tnsnames.ora file.
The issue is solved i just pointed my connection string in my web config to the oracle TNS names
I've requested that this question be deleted for the following reason:

This issue has been resolved and is very old to continue the conversation
I'm afraid I have to object.  You stated yourself the issue is solved.  Just deleting it to get around the new question lock is not the correct use of the site.