M
Markus Freitag
Guest
Hello,
When I during the using get an exception, my application can't close it.
I think in this case the using close not the connection.
How can I solve it?
Reason, sometimes I close the app and inside the taskmanager i see the app. Well I'm Looking for a solution.
How do I close an OracleConnection in .NET
try
{
using (OracleConnection connection = new OracleConnection(DataBase.ConnectionString))
{
OracleCommand cmd = new OracleCommand("NUMBERS.GET_N_UNPROCESSED", connection);
cmd.CommandType = CommandType.StoredProcedure;
cmd.Parameters.Add("p_in_batch_id", OracleDbType.Varchar2, CurrentOrder.BatchID, ParameterDirection.Input);
connection.Open();
OracleDataAdapter da = new OracleDataAdapter(cmd);
cmd.ExecuteNonQuery();
if (cmd.Parameters["p_out_error_message"].Value.ToString() != "null")
{
throw new Exception
}
}
}
catch (Exception e)
{
throw new Extension
}
finally
{
}
return ret;
}
I found this, is it right?
using (SqlConnection sqlConn = new SqlConnection("connectionstring"))
{
sqlConn.Open();
...
}
The compiler will convert this code as below.
try
{
SqlConnection sqlConn = new SqlConnection("connectionstring");
sqlConn.Open();
...
}
finally
{
sqlConn.Close();
}
With best regards Markus
Continue reading...
When I during the using get an exception, my application can't close it.
I think in this case the using close not the connection.
How can I solve it?
Reason, sometimes I close the app and inside the taskmanager i see the app. Well I'm Looking for a solution.
How do I close an OracleConnection in .NET
try
{
using (OracleConnection connection = new OracleConnection(DataBase.ConnectionString))
{
OracleCommand cmd = new OracleCommand("NUMBERS.GET_N_UNPROCESSED", connection);
cmd.CommandType = CommandType.StoredProcedure;
cmd.Parameters.Add("p_in_batch_id", OracleDbType.Varchar2, CurrentOrder.BatchID, ParameterDirection.Input);
connection.Open();
OracleDataAdapter da = new OracleDataAdapter(cmd);
cmd.ExecuteNonQuery();
if (cmd.Parameters["p_out_error_message"].Value.ToString() != "null")
{
throw new Exception
}
}
}
catch (Exception e)
{
throw new Extension
}
finally
{
}
return ret;
}
I found this, is it right?
using (SqlConnection sqlConn = new SqlConnection("connectionstring"))
{
sqlConn.Open();
...
}
The compiler will convert this code as below.
try
{
SqlConnection sqlConn = new SqlConnection("connectionstring");
sqlConn.Open();
...
}
finally
{
sqlConn.Close();
}
With best regards Markus
Continue reading...