Hi,
I had to make a couple of bracket corrections to get this to compile:
ActionQuery query = new ActionQuery((DB2Connection)transaction.Connection, new DB2Command("SET TRANSACTION READ ONLY"));
but I still received an exception...
"An exception was caught during the execution of an action query: Execute requires the command to have a transaction object when the connection assigned to the command is in a pending local transaction. The Transaction property of the command has not been initialized.. Check InnerException, QueryExecuted and Parameters of this exception to examine the cause of this exception."
With Inner Exception...
"Execute requires the command to have a transaction object when the connection assigned to the command is in a pending local transaction. The Transaction property of the command has not been initialized."}
[System.InvalidOperationException]: {"Execute requires the command to have a transaction object when the connection assigned to the command is in a pending local transaction. The Transaction property of the command has not been initialized."}
Data: {System.Collections.ListDictionaryInternal}
HelpLink: null
InnerException: null
Message: "Execute requires the command to have a transaction object when the connection assigned to the command is in a pending local transaction. The Transaction property of the command has not been initialized."
Source: "IBM.Data.DB2"
StackTrace: " at IBM.Data.DB2.DB2Connection.a(String A_0, DB2Transaction A_1)\r\n at IBM.Data.DB2.DB2Command.a(String A_0)\r\n at IBM.Data.DB2.DB2Command.g()\r\n at IBM.Data.DB2.DB2Command.ExecuteNonQuery()\r\n at SD.LLBLGen.Pro.ORMSupportClasses.ActionQuery.Execute()"
TargetSite: {IBM.Data.DB2.DB2Transaction a(System.String, IBM.Data.DB2.DB2Transaction)}
So from this I deduced that I needed to assign the transaction to the command as follows:
DB2Command cmd = new DB2Command("SET TRANSACTION ISOLATION LEVEL READ UNCOMMITTED READ ONLY");
cmd.Transaction = (DB2Transaction)transaction;
ActionQuery query = new ActionQuery((DB2Connection)transaction.Connection,cmd);
query.Execute();
This now does seem to get as far as the DB2 server but I now have a different (more DB2 specific) exception perhaps indicating that the SET command is incorrect or being executed in the wrong place ? ....
Exception:
"An exception was caught during the execution of an action query: ERROR [42601] [IBM][DB2/LINUX] SQL0104N An unexpected token \"TRANSACTION\" was found following \"SET \". Expected tokens may include: \"JOIN <joined_table>\". SQLSTATE=42601\r\n. Check InnerException, QueryExecuted and Parameters of this exception to examine the cause of this exception."
InnerException:
"ERROR [42601] [IBM][DB2/LINUX] SQL0104N An unexpected token \"TRANSACTION\" was found following \"SET \". Expected tokens may include: \"JOIN <joined_table>\". SQLSTATE=42601\r\n"}
[IBM.Data.DB2.DB2Exception]: {"ERROR [42601] [IBM][DB2/LINUX] SQL0104N An unexpected token \"TRANSACTION\" was found following \"SET \". Expected tokens may include: \"JOIN <joined_table>\". SQLSTATE=42601\r\n"}
Data: {System.Collections.ListDictionaryInternal}
HelpLink: null
InnerException: null
Message: "ERROR [42601] [IBM][DB2/LINUX] SQL0104N An unexpected token \"TRANSACTION\" was found following \"SET \". Expected tokens may include: \"JOIN <joined_table>\". SQLSTATE=42601\r\n"
Source: "IBM.Data.DB2"
StackTrace: " at IBM.Data.DB2.DB2Connection.a(IntPtr A_0, x A_1, s A_2)\r\n at IBM.Data.DB2.DB2Command.g()\r\n at IBM.Data.DB2.DB2Command.ExecuteNonQuery()\r\n at SD.LLBLGen.Pro.ORMSupportClasses.ActionQuery.Execute()"
TargetSite: {Void a(IntPtr, x, s)}
I also tried changing the DB2 command to:
"SET TRANSACTION ISOLATION LEVEL READ ONLY"
and also
"SET TRANSACTION ISOLATION LEVEL READ UNCOMMITTED READ ONLY"
but still got the same exception message!
pmax100