Link to home
Create AccountLog in
Avatar of nushahid
nushahidFlag for Pakistan

asked on

Error: ORA-06413 Connection not Open

I am new in ORACLE 9i and need help resolving this problem. I am making a .NET application and use ORACLE 9i as a backend database. I am using "Microsoft .NET provider for Oracle" to connect to the ORACLE via my .NET application. Now the problem is that, the work which I have done in my office not work properly in my home. When I wants to make a connection to an ORACLE database, it gives an error that

"ORA-06413: Connection not open"

How can i fix this error so that my application will work properly in my office and my home.

The code of ClassConenction which is used for making connection to the ORACLE 9i database is given below.
using System;
using System.Collections.Generic;
using System.Text;
using System.Data.OracleClient;
using System.Data;
 
namespace ADT
{
    class ClassConnection
    {
        private OracleConnection myOracleConnection;
        private OracleCommand myCommand;
        private string connString;
 
        public void initConnection()
        {
            connString = "Data Source=(DESCRIPTION=(ADDRESS_LIST="
                    + "(ADDRESS=(PROTOCOL=TCP)(HOST=buddy)(PORT=1521)))"
                    + "(CONNECT_DATA=(SERVER=DEDICATED)(SERVICE_NAME=gusms)));"
                    + "User Id=adeel;Password=adeel;";
            try
            {
                myOracleConnection = new OracleConnection(connString);
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.ToString());
            }
        }//...
 
        public void connectDB()
        {
            try
            {
                if (myOracleConnection.State == System.Data.ConnectionState.Open) { return; }
 
                myOracleConnection.Open();
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.ToString());
            }
        }//...
 
        public void closeDB()
        {
            try
            {
                if (myOracleConnection.State == System.Data.ConnectionState.Open)
                    myOracleConnection.Close();
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.ToString());
            }
        }//...
 
        public DataTable selectRecord(string QRY)
        {
            try
            {
                if (myCommand == null)
                {
                    myCommand = myOracleConnection.CreateCommand();
                }
                myCommand.CommandText = QRY;
 
                OracleDataAdapter myOracleDataAdapter = new OracleDataAdapter();
                myOracleDataAdapter.SelectCommand = myCommand;
 
                DataSet myDataSet = new DataSet();
 
                myOracleDataAdapter.Fill(myDataSet, "myTable");
 
                return myDataSet.Tables["myTable"];
            }
            catch (OracleException ex)
            {
                Console.WriteLine(ex.ToString());
                return null;
            }
        }//...
 
        public bool insertRecord(string QRY)
        {
            try
            {
                if (myCommand == null)
                {
                    myCommand = myOracleConnection.CreateCommand();
                }
                myCommand.CommandText = QRY;
                myCommand.ExecuteNonQuery();
                return true;
            }
            catch (OracleException ex)
            {
                Console.WriteLine(ex.ToString());
                return false;
            }
        }//...
 
        public bool updateRecord(string QRY)
        {
            try
            {
                if (myCommand == null)
                {
                    myCommand = myOracleConnection.CreateCommand();
                }
                myCommand.CommandText = QRY;
                myCommand.ExecuteNonQuery();
                return true;
            }
            catch (OracleException ex)
            {
                Console.WriteLine(ex.ToString());
                return false;
            }
        }//...
    }
}

Open in new window

ASKER CERTIFIED SOLUTION
Avatar of Devinder Singh Virdi
Devinder Singh Virdi
Flag of United States of America image

Link to home
membership
Create a free account to see this answer
Signing up is free and takes 30 seconds. No credit card required.
See answer
Avatar of nushahid

ASKER

I have done all this but it is not working