Click here to Skip to main content
15,885,985 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I am working on bulk upload functionality for that I have used Oracle.DataAccess and created connection, till last week it was working fine but now suddenly I am getting error "System.NullReferenceException: Object reference not set to an instance of an object." when i am trying to open connection using connection object. e.g. connObject.Open. I have copied code snippet below.

What I have tried:

public bool WriteToServer(string qualifiedDBName, DataTable dataTable)
    {
        OracleConnection objOracleCon = null;
        try
        {
            string connectionString = System.Configuration.ConfigurationManager.ConnectionStrings["OracleConnection"].ToString();
            objOracleCon = new OracleConnection(connectionString);
            if (objOracleCon != null)
            {
                if (objOracleCon.State == ConnectionState.Closed)
                {
                    objOracleCon.Open();
                }
                using (OracleBulkCopy bulkCopy = new OracleBulkCopy(objOracleCon))
                {
                    bulkCopy.BatchSize = 100000;
                    bulkCopy.BulkCopyTimeout = 20000;
                    bulkCopy.DestinationTableName = qualifiedDBName;
                    bulkCopy.WriteToServer(dataTable);
                    bulkCopy.Close();
                    bulkCopy.Dispose();
                    objOracleCon.Dispose();
                }
            }
        }
        catch (Exception exc)
        {
            return false;
        }
        finally
        {
            if (objOracleCon.State == ConnectionState.Open)
            {
                objOracleCon.Close();
            }
        }
        return true;
    }
Posted
Updated 11-Mar-18 22:53pm

1 solution

You are calling Close on your objOracleCon object in your finally block, but you have disposed this object in your using block above.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900