oracleCommand error  
Author Message
Xelestial





PostPosted: .NET Framework Data Access and Storage, oracleCommand error Top

someone..please tell me what is wrong with my code i get an error when trying to open the connection. but in my second form i could connect to the database. i just dont get what is my mistake in here...

OracleCommand insert1 = new OracleCommand("insert into customer(cusnum, cusdt, cusid, cusstatus, cuscode, cusname, cussex) values (:p1, :p2, :p3, :p4, :p5, :p6, :p7)");

insert1.Connection = new OracleConnection(oracle);

OracleCommand insert2 = new OracleCommand("insert into request(reqnum, reqcode, reqname) values(:p8, :p9, :p10)");

insert2.Connection = new OracleConnection(oracle);

OracleParameter p1 = new OracleParameter(":p1", OracleType.Number);

p1.Value = txt1.Text;

OracleParameter p2 = new OracleParameter(":p2", OracleType.DateTime);

p2.Value = txt2.Text;

OracleParameter p3 = new OracleParameter(":p3", OracleType.VarChar);

p3.Value = txt3.Text;

OracleParameter p4 = new OracleParameter(":p4", OracleType.VarChar);

p4.Value = txt4.Text;

OracleParameter p5 = new OracleParameter(":p5", OracleType.VarChar);

p5.Value = txt5.Text;

OracleParameter p6 = new OracleParameter(":p6", OracleType.VarChar);

p6.Value = txt6.Text;

OracleParameter p7 = new OracleParameter(":p7", OracleType.VarChar);

p7.Value = txt7.Text;

OracleParameter p8 = new OracleParameter(":p8", OracleType.Number);

p8.Value = txt8.Text;

OracleParameter p9 = new OracleParameter(":p9", OracleType.VarChar);

p9.Value = txt9.Text;

OracleParameter p10 = new OracleParameter(":p10", OracleType.VarChar);

p10.Value = txt10.Text;

insert1.Parameters.Add(p1);

insert1.Parameters.Add(p2);

insert1.Parameters.Add(p3);

insert1.Parameters.Add(p4);

insert1.Parameters.Add(p5);

insert1.Parameters.Add(p6);

insert1.Parameters.Add(p7);

insert2.Parameters.Add(p8);

insert2.Parameters.Add(p9);

insert2.Parameters.Add(p10);

try

{

insert1.Connection.Open();

insert1.ExecuteNonQuery();

insert2.Connection.Open();

insert2.ExecuteNonQuery();

}

catch

{

MessageBox.Show("There is no connection to the Oracle database.");

}

finally{}

insert1.Connection.Close();

insert2.Connection.Close();



.NET Development5  
 
 
Paul Domag





PostPosted: .NET Framework Data Access and Storage, oracleCommand error Top

Hi,

Can you please post the error message being generated. Also try using only a single connection. Since as I noticed in your code both insert1 and insert2 have the same configuration in its connection object. YOu can do this:

OracleConnection conn = new OracleConnection(oracle);

OracleCommand insert1 = new OracleCommand("insert into customer(cusnum, cusdt, cusid, cusstatus, cuscode, cusname, cussex) values (:p1, :p2, :p3, :p4, :p5, :p6, :p7)");

insert1.Connection = conn;

OracleCommand insert2 = new OracleCommand("insert into request(reqnum, reqcode, reqname) values(:p8, :p9, :p10)");

insert2.Connection = conn;

and also please verify that you have closed the conneciton before opening it again. My advise would be to close it immediately after the execute is finish...

cheers,

Paul June A. Domag



 
 
Xeleste





PostPosted: .NET Framework Data Access and Storage, oracleCommand error Top

the error is that it could not connect to the Oracle database.
 
 
Paul Domag





PostPosted: .NET Framework Data Access and Storage, oracleCommand error Top

Hi,

Have you tried using just a single connection just as I suggested above Also, try debugging the code and see if by omitting insert2 (and all codes dependent to it) would still generate the error.

cheers,

Paul June A. Domag



 
 
Xeleste





PostPosted: .NET Framework Data Access and Storage, oracleCommand error Top

yes i tried deleting the 2nd insert (insert2) still i get that problem. is it possible that im getting this error because the oracle database i am accessing is located on a different computer but i already did the net configuration for oracle and the odbc installation...
 
 
Paul P Clement IV





PostPosted: .NET Framework Data Access and Storage, oracleCommand error Top


Please post the exact error message including the ORA error message number.

 
 
Xeleste





PostPosted: .NET Framework Data Access and Storage, oracleCommand error Top

i cant remember the error message..i was doing the at another place.. anyway what i noticed was when i retrieve a field from sql (placed in a textbox) then when i want to insert that field to oracle i get the message that there is no connection to the oracle database.