1

I am trying to connect to Oracle in a 32-bit Console Application. I am getting the following erorr. The code (with the exception of host, username, and password change) is below. It is a simple two function project.

Any help will be appreciated.

I am using C# in Visual Studion 2010 Premium and Oracle 10g. I can connect to the database with Oracle SQL Developer with the information set in the connection string.


---------------ToString-------------------------- --Oracle.DataAccess.Client.OracleException at Oracle.DataAccess.Client.OracleException.HandleErrorHelper(Int32 errCode, OracleConnection conn, IntPtr opsErrCtx, OpoSqlValCtx* pOpoSqlValCtx, Object src, String procedure) at Oracle.DataAccess.Client.OracleException.HandleError(Int32 errCode, Oracle Connection conn, IntPtr opsErrCtx, Object src) at Oracle.DataAccess.Client.OracleConnection.Open() at ConsoleApplication1.Program.GetConnection() in c:\users\maholt\documents\visual studio 2010\Projects\ConsoleApplication1\ConsoleApplication1\Program.cs:line 61

---------------Message---------------------------


using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data;
using Oracle.DataAccess.Client;

namespace ConsoleApplication1
{
    class Program
    {
        static OracleConnection conn;

        static void Main(string[] args)
        {
            OracleConnection connC = GetConnection();

            conn = connC;
            simpleQuery();
            Console.WriteLine("DONE");
        }

        public static void simpleQuery()
        {
            OracleCommand cmd = new OracleCommand("select count(*) as total from console.client");

            cmd.Connection = conn;
            cmd.CommandType = CommandType.Text;

            try
            {
                cmd.Connection.Open();
                OracleDataReader reader = cmd.ExecuteReader();

                while (reader.Read())
                {
                    Console.WriteLine(Convert.ToString(reader["total"]));
                }
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.Message);
            }
            finally
            {
                cmd.Dispose();
            }
        }

        public static OracleConnection GetConnection()
        {
            Oracle.DataAccess.Client.OracleConnection rtn = null;
            try
            {
                string connstr = "Data Source=//10.10.10.10:1521/PRD2_OLTP;User Id=user; Password=pass;";

                rtn = new Oracle.DataAccess.Client.OracleConnection(connstr);

                if (rtn.State != System.Data.ConnectionState.Open)
                {
                    rtn.Open();
                }
            }
            catch (Exception ee)
            {
                Console.WriteLine("-------------------------------------------------");
                Console.WriteLine("---------------ToString--------------------------");
                Console.WriteLine("--" + ee.ToString());
                Console.WriteLine("---------------Message---------------------------");
                Console.WriteLine("--" + ee.Message);
                Console.WriteLine("-------------------------------------------------");
            }

            return (rtn);
        }

    }
}
1
  • What is the exception message? You have a header for it but don't seem to have included the text. Is the message blank? Commented Aug 16, 2011 at 21:38

2 Answers 2

1

SQL Developer uses effectively JDBC connection... so it is not really comparable with what happens in .NET :-(

Regarding the Oracle versus .NET version compatibility - I found this rather problematic esp. since the clients don't have always the option to update according to Oracle roadmap...

After researching some I switched to using the Devart components - support everything from Oracle 7.3 up to 11gR2 in .NET 2 up with 32 and 64 bit and come with a "direct-mode option" which means if need be I can run my app without any Oracle client being installed on the machine... not affiliated, just a happy customer...

Sign up to request clarification or add additional context in comments.

Comments

0

First - Oracle doesn't support 10g with .net 4.0. You must use 11.2.0.2 or higher to be compliant with Oracle's supported versions.

Second - The problem is you probably don't have ODP.Net installed correctly. This can mean it isn't installed, it was installed to a second instance, or it failed to copy on or more files during installation.

I have some blog posts about these items along with a link to some connection testing applications I wrote. Feel free to use them.

https://tsells.wordpress.com/category/oracle/

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.