views:

59

answers:

0

Hello guys, i have multiple inserts to do so i want to do them in a transaction by calling a stored procedure on the iseries. I can't get it to work, it auto commits every insert i do so i figured i would try to do a transaction with just a simple file first and then go from there.

The file is productest/cepf05 and when i first did the code it failed because the file wasn't journaled, so i journaled it and tried again.

Here´s the code:

IBM.Data.DB2.iSeries.iDB2Connection As400Conexion = 
new IBM.Data.DB2.iSeries.iDB2Connection("DataSource=x.x.x.x; UserID=myuser; Password=mypass; 
ConnectionTimeout=125; DefaultCollection=MYLIB1; LibraryList=MYLIB1, MYLIB2, MYLIB3");
        As400Conexion.Open();
iDB2Transaction trans = As400Conexion.BeginTransaction(IsolationLevel.RepeatableRead);

iDB2Command cmd = As400Conexion.CreateCommand();
cmd.CommandText="insert into myfile values(@user,@pass)";
cmd.Parameters.Add("@user", iDB2DbType.iDB2Char, 10);
cmd.Parameters.Add("@pass", iDB2DbType.iDB2Char, 10);
cmd.Parameters["@user"].Direction = ParameterDirection.Input;
cmd.Parameters["@pass"].Direction = ParameterDirection.Input;
cmd.Parameters["@usuario"].Value = "USER1";
cmd.Parameters["@pass"].Value = "PASS1";
cmd.ExecuteNonQuery();
//second insert
cmd.Parameters["@usuario"].Value = "USER2";
cmd.Parameters["@pass"].Value = "PASS2";
cmd.ExecuteNonQuery();
trans.Commit();
trans.Dispose();
cmd.Dispose();
As400Conexion.Close();
As400Conexion.Dispose();        

The problem is that after the first ExecuteNonQuery() i can see the insert already being commited to the database.

I have tried with isolation levels: RepeatableRead and Serializable

Do i need to compile the file with special parameters? Maybe some special parameters to add the file to the journal?

Here's how i created the journal:

CRTJRNRCV JRNRCV(MYLIB/MYJRNRCV)
CRTJRN JRN(MYLIB/MYJOURNAL) JRNRCV(MYLIB/MYJRNRCV)
STRJRNPF FILE(MYLIB/MYFILE) JRN(MYLIB/MYJOURNAL) OMTJRNE(*OPNCLO)
STRCMTCTL LCKLVL(*ALL) DFTJRN(MYLIB/MYJOURNAL)

Thanks in advance!