Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

oracle connection

Status
Not open for further replies.

HrvojeVd

Programmer
Jun 22, 2008
36
HR
I'm using this code to enter data into table, but error uppear.
void getTextData(string oConn, int ID, string Ime, string Prezime)
{
try
{

using (OracleConnection connection = new OracleConnection(oConn))
{
OracleCommand command = new OracleCommand("HRVOJE_INSERT");
command.Connection = connection;
try
{
connection.Open();
}
catch (Exception ex)
{

}

if (command.Connection.State == ConnectionState.Open)
{
command.CommandText = "HRVOJE_INSERT";
command.Parameters.Add(ID.ToString(), OracleDbType.Int32, 16);
command.Parameters.Add(Ime, OracleDbType.Varchar2);
command.Parameters.Add(Prezime, OracleDbType.Varchar2);
command.ExecuteReader();
}
}

saved = true;
}

catch (Exception x)
{
errorM = x.Message + x.StackTrace;
}
}

store procedure:

PROCEDURE HRVOJE_INSERT
(
ID number,
Ime varchar,
Prezime varchar
)

AS

BEGIN
INSERT INTO HRVOJE_TEST (ID,IME,PREZIME) VALUES(ID,Ime,Prezime);
END;

COMMIT;
 
you must supply the exception, because that is telling you what the problem is.

1. your swallowing the opening of the connection. you don't need to do this.
2. you shouldn't catch 'Exception' as this point in you code. it's too general. you should only catch exceptions if you expect them to occur. in this case the most you want to catch is OracleExpection (or DbException, something like that)
3. just log Exception.ToString() this will give you the type, message and stack trace.
Code:
try
{
   using (OracleConnection connection = new OracleConnection(oConn))
   using(OracleCommand command = new OracleCommand("HRVOJE_INSERT", connection))
   {
      command.Parameters.Add(ID, OracleDbType.Int32, 16);
      command.Parameters.Add(Ime, OracleDbType.Varchar2);
      command.Parameters.Add(Prezime, OracleDbType.Varchar2);

      connection.Open();
      command.ExecuteReader();
   }
}
catch(DatabaseException ex)
{
   //you need to create the Log object
   Log.For(this).Error(ex.ToString());
   throw;
}

Jason Meckley
Programmer
Specialty Bakers, Inc.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top