Improve company productivity with a Business Account.Sign Up

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

.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
0
Chris Jones
Asked:
Chris Jones
  • 17
  • 15
  • 7
1 Solution
 
HainKurtSr. System AnalystCommented:
on which line do you get that error? post the code and full error message...
0
 
slightwv (䄆 Netminder) Commented:
What is the rest of the stack trace?
0
 
Chris JonesLead Application Web DeveloperAuthor Commented:
  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

0
Upgrade your Question Security!

Your question, your audience. Choose who sees your identity—and your question—with question security.

 
HainKurtSr. System AnalystCommented:
post the full error message... the one you posted is too generic to comment...
0
 
Chris JonesLead Application Web DeveloperAuthor Commented:
--------------------------------------------------------------------------------

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
0
 
slightwv (䄆 Netminder) Commented:
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
0
 
slightwv (䄆 Netminder) Commented:
"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/

0
 
Chris JonesLead Application Web DeveloperAuthor Commented:
this is the error when i try to add a sql data source ORA-12541
0
 
HainKurtSr. System AnalystCommented:
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

0
 
HainKurtSr. System AnalystCommented:
0
 
Chris JonesLead Application Web DeveloperAuthor Commented:
everything is set  and i can ping the server
0
 
slightwv (䄆 Netminder) Commented:
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?
0
 
Chris JonesLead Application Web DeveloperAuthor Commented:
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)
    )
  )
0
 
slightwv (䄆 Netminder) Commented:
OK, which database are you trying to use when you get the ORA-12541?
0
 
Chris JonesLead Application Web DeveloperAuthor Commented:
leodb3
0
 
Chris JonesLead Application Web DeveloperAuthor Commented:
sorry i mean PROD
0
 
HainKurtSr. System AnalystCommented:
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...
0
 
slightwv (䄆 Netminder) Commented:
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
0
 
Chris JonesLead Application Web DeveloperAuthor Commented:
prod is listening its our production srever for our campus
0
 
slightwv (䄆 Netminder) Commented:
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.
0
 
Chris JonesLead Application Web DeveloperAuthor Commented:
tnsnames.ora file location

C:\oracle\product\10.2.0\client_1\NETWORK\ADMIN
0
 
slightwv (䄆 Netminder) Commented:
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.
0
 
HainKurtSr. System AnalystCommented:
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...
0
 
slightwv (䄆 Netminder) Commented:
>>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.
0
 
HainKurtSr. System AnalystCommented:
slightwv, if home is not in registry, how does an app will find the client files, from path variebles?
0
 
slightwv (䄆 Netminder) Commented:
>>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.
0
 
Chris JonesLead Application Web DeveloperAuthor Commented:
the network/admin folders do exist ?
0
 
slightwv (䄆 Netminder) Commented:
Please confirm you only have one Oracle product installed.
0
 
Chris JonesLead Application Web DeveloperAuthor Commented:
how would you like me to confirm ?
0
 
Chris JonesLead Application Web DeveloperAuthor Commented:
i restarted my computer now i get an error like this


Operation is not valid due to the current state of the object.
0
 
Chris JonesLead Application Web DeveloperAuthor Commented:
ok i have 2 installs and my PLSQL developer works just fine.
0
 
slightwv (䄆 Netminder) Commented:
you need to properly configure the Oracle install .Net is trying to use.  The one where the ODAC is installed.
0
 
Chris JonesLead Application Web DeveloperAuthor Commented:
how do i config it the install went through with no errors for oracle ?
0
 
slightwv (䄆 Netminder) Commented:
You can either copy a good configuration from a working install or manually edit the tnsnames.ora file for the specific Oracle install you need to configure.

As I posted in your other question:  Every Oracle client install needs it's own properly configured tnsnames.ora file.

If you wish to use just one common one you can set up an environment variable called TNS_ADMIN pointing to the folder that has it.

It seems like you are having a hard time with this concept.  Think of the tnsnames.ora file like a web.config file.  Every .Net app has an individual version of this config file.  It is no different for Oracle installs.  Each one has its own copy/version.
0
 
Chris JonesLead Application Web DeveloperAuthor Commented:
i used the tns file way of connecting and it has no issues.
0
 
slightwv (䄆 Netminder) Commented:
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.
0
 
Chris JonesLead Application Web DeveloperAuthor Commented:
The issue is solved i just pointed my connection string in my web config to the oracle TNS names
0
 
Chris JonesLead Application Web DeveloperAuthor Commented:
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
0
 
slightwv (䄆 Netminder) Commented:
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.
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Get your problem seen by more experts

Be seen. Boost your question’s priority for more expert views and faster solutions

  • 17
  • 15
  • 7
Tackle projects and never again get stuck behind a technical roadblock.
Join Now