ASP.NET : the connection is closed

时间:2016-04-15 11:12:40

标签: c# asp.net oracle

I want to execute a query but we are facing the problem of connection string

This is my code:

OracleCommand _commandInvoice = new OracleCommand();
_commandInvoice.CommandType = CommandType.StoredProcedure;

_commandInvoice.Parameters.AddWithValue("I_INVOICE_ID", strInvoiceID);
_commandInvoice.Parameters.AddWithValue("I_ORG_ID", ORG_ID);
_commandInvoice.Parameters.AddWithValue("I_ORG_NAME", strOrg_name);
_commandInvoice.Parameters.AddWithValue("I_PROJECT", strProject);
_commandInvoice.Parameters.AddWithValue("I_VENDOR_NAME", strVendor_name);
_commandInvoice.Parameters.AddWithValue("I_VENDOR_TYPE_LOOKUP_CODE", strVendorType_lookup_Code);
_commandInvoice.Parameters.AddWithValue("I_INVOICE_NUMBER", strInvoice_number);
_commandInvoice.Parameters.AddWithValue("I_INVOICE_DATE", strInvoice_date);
_commandInvoice.Parameters.AddWithValue("I_INVOICE_AMT", strInvoice_Amt);
_commandInvoice.Parameters.AddWithValue("I_OUTSTANDING_AMT", strOutstanding_Amt);
_commandInvoice.Parameters.AddWithValue("I_OUTSTANDING_REQ_AMT", strOutstanding_req_amt);

if (obj_Conn.State == ConnectionState.Closed)
{
    obj_Conn.Open();
    _commandInvoice.ExecuteNonQuery();
}

We are getting am error:

Invalid operation. The connection is closed.

1 个答案:

答案 0 :(得分:4)

您需要在OracleCommand上设置Connection属性以使用您的obj_Conn连接,或使用相关的constructor

_commandInvoice.Connection = obj_Conn;