Solved

.NET oracle error

Posted on 2011-09-29
41
1,233 Views
Last Modified: 2012-05-12
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
Comment
Question by:Chris Jones
  • 17
  • 15
  • 7
41 Comments
 
LVL 51

Expert Comment

by:HainKurt
ID: 36815742
on which line do you get that error? post the code and full error message...
0
 
LVL 76

Expert Comment

by:slightwv (䄆 Netminder)
ID: 36815745
What is the rest of the stack trace?
0
 
LVL 1

Author Comment

by:Chris Jones
ID: 36815750
  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
 
LVL 51

Expert Comment

by:HainKurt
ID: 36815757
post the full error message... the one you posted is too generic to comment...
0
 
LVL 1

Author Comment

by:Chris Jones
ID: 36815832
--------------------------------------------------------------------------------

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
 
LVL 76

Expert Comment

by:slightwv (䄆 Netminder)
ID: 36815847
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
 
LVL 76

Expert Comment

by:slightwv (䄆 Netminder)
ID: 36815873
"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
 
LVL 1

Author Comment

by:Chris Jones
ID: 36815900
this is the error when i try to add a sql data source ORA-12541
0
 
LVL 51

Expert Comment

by:HainKurt
ID: 36815971
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
 
LVL 51

Expert Comment

by:HainKurt
ID: 36815998
0
 
LVL 1

Author Comment

by:Chris Jones
ID: 36816091
everything is set  and i can ping the server
0
 
LVL 76

Expert Comment

by:slightwv (䄆 Netminder)
ID: 36816121
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
 
LVL 1

Author Comment

by:Chris Jones
ID: 36816151
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
 
LVL 76

Expert Comment

by:slightwv (䄆 Netminder)
ID: 36816169
OK, which database are you trying to use when you get the ORA-12541?
0
 
LVL 1

Author Comment

by:Chris Jones
ID: 36816174
leodb3
0
 
LVL 1

Author Comment

by:Chris Jones
ID: 36816191
sorry i mean PROD
0
 
LVL 51

Expert Comment

by:HainKurt
ID: 36816488
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
 
LVL 76

Expert Comment

by:slightwv (䄆 Netminder)
ID: 36816508
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
 
LVL 1

Author Comment

by:Chris Jones
ID: 36816555
prod is listening its our production srever for our campus
0
How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

 
LVL 76

Expert Comment

by:slightwv (䄆 Netminder)
ID: 36816625
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
 
LVL 1

Author Comment

by:Chris Jones
ID: 36816749
tnsnames.ora file location

C:\oracle\product\10.2.0\client_1\NETWORK\ADMIN
0
 
LVL 76

Expert Comment

by:slightwv (䄆 Netminder)
ID: 36817104
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
 
LVL 51

Expert Comment

by:HainKurt
ID: 36817379
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
 
LVL 76

Expert Comment

by:slightwv (䄆 Netminder)
ID: 36817411
>>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
 
LVL 51

Expert Comment

by:HainKurt
ID: 36817514
slightwv, if home is not in registry, how does an app will find the client files, from path variebles?
0
 
LVL 76

Expert Comment

by:slightwv (䄆 Netminder)
ID: 36817534
>>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
 
LVL 1

Author Comment

by:Chris Jones
ID: 36891200
the network/admin folders do exist ?
0
 
LVL 76

Expert Comment

by:slightwv (䄆 Netminder)
ID: 36891340
Please confirm you only have one Oracle product installed.
0
 
LVL 1

Author Comment

by:Chris Jones
ID: 36891534
how would you like me to confirm ?
0
 
LVL 1

Author Comment

by:Chris Jones
ID: 36891716
i restarted my computer now i get an error like this


Operation is not valid due to the current state of the object.
0
 
LVL 1

Author Comment

by:Chris Jones
ID: 36893663
ok i have 2 installs and my PLSQL developer works just fine.
0
 
LVL 76

Expert Comment

by:slightwv (䄆 Netminder)
ID: 36893949
you need to properly configure the Oracle install .Net is trying to use.  The one where the ODAC is installed.
0
 
LVL 1

Author Comment

by:Chris Jones
ID: 36902914
how do i config it the install went through with no errors for oracle ?
0
 
LVL 76

Accepted Solution

by:
slightwv (䄆 Netminder) earned 500 total points
ID: 36903074
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
 
LVL 1

Author Comment

by:Chris Jones
ID: 36903299
i used the tns file way of connecting and it has no issues.
0
 
LVL 76

Expert Comment

by:slightwv (䄆 Netminder)
ID: 36903431
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
 
LVL 1

Author Comment

by:Chris Jones
ID: 36968151
The issue is solved i just pointed my connection string in my web config to the oracle TNS names
0
 
LVL 1

Author Comment

by:Chris Jones
ID: 37568138
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
 
LVL 76

Expert Comment

by:slightwv (䄆 Netminder)
ID: 37568139
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

Featured Post

Highfive Gives IT Their Time Back

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

Working with Network Access Control Lists in Oracle 11g (part 1) Part 2: http://www.e-e.com/A_9074.html So, you upgraded to a shiny new 11g database and all of a sudden every program that used UTL_MAIL, UTL_SMTP, UTL_TCP, UTL_HTTP or any oth…
Calculating holidays and working days is a function that is often needed yet it is not one found within the Framework. This article presents one approach to building a working-day calculator for use in .NET.
This video shows how to set up a shell script to accept a positional parameter when called, pass that to a SQL script, accept the output from the statement back and then manipulate it in the Shell.
This video shows how to Export data from an Oracle database using the Original Export Utility.  The corresponding Import utility, which works the same way is referenced, but not demonstrated.

707 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

17 Experts available now in Live!

Get 1:1 Help Now