Home All Groups Group Topic Archive Search About

Problem with transaction error

Author
3 Nov 2006 3:00 PM
Chukkalove
{"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." }

I am noob sqlserver user of 2 days. We're migrating to sql server server
from mySQL and i'm using code that was used for mySQL with no problems
When the line "Command.ExecuteNonQuery" is run, I receive the error message
shown above.
What does this mean and how do i fix it please?




// Set up database
string sql = string.Format("INSERT INTO LOGINS (fk_Users_RecID,
fk_Sites_RecID, LogDate, InOrOut) VALUES ({0},{1},{2},{3})",
ParseParam("FK_USERS_RECID", "FK_SITES_RECID", "LOGDATE", "INOROUT"));
// Grab a connection and create a command
IDbTransaction transaction;
IDbConnection Connection = GetConnection();
IDbCommand command = Command(sql, Connection);
tableLogins table = new tableLogins();
table.CreateParam(ref command, "FK_USERS_RECID",RecID);
table.CreateParam(ref command, "FK_SITES_RECID", CurrentSite.RecID);
table.CreateParam(ref command, "LOGDATE",Now);
if (LoggingIn)
table.CreateParam(ref command,"INOROUT",1);
else
table.CreateParam(ref command,"INOROUT",0);
Connection.Open();
try
{
transaction = Connection.BeginTransaction();
try
{
command.ExecuteNonQuery();
fobar........

Author
3 Nov 2006 5:48 PM
Miha Markic [MVP C#]
Assign transaction to command before execution, i.e.:
command.Transaction = transaction;

--
Miha Markic [MVP C#, INETA Country Leader for Slovenia]
RightHand .NET consulting & development www.rthand.com
Blog: http://cs.rthand.com/blogs/blog_with_righthand/

Show quote
"Chukkalove" <some***@microsoft.com> wrote in message
news:%23%234$Hj1$GHA.3396@TK2MSFTNGP02.phx.gbl...
> {"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." }
>
> I am noob sqlserver user of 2 days. We're migrating to sql server server
> from mySQL and i'm using code that was used for mySQL with no problems
> When the line "Command.ExecuteNonQuery" is run, I receive the error
> message shown above.
> What does this mean and how do i fix it please?
>
>
>
>
> // Set up database
> string sql = string.Format("INSERT INTO LOGINS (fk_Users_RecID,
> fk_Sites_RecID, LogDate, InOrOut) VALUES ({0},{1},{2},{3})",
> ParseParam("FK_USERS_RECID", "FK_SITES_RECID", "LOGDATE", "INOROUT"));
> // Grab a connection and create a command
> IDbTransaction transaction;
> IDbConnection Connection = GetConnection();
> IDbCommand command = Command(sql, Connection);
> tableLogins table = new tableLogins();
> table.CreateParam(ref command, "FK_USERS_RECID",RecID);
> table.CreateParam(ref command, "FK_SITES_RECID", CurrentSite.RecID);
> table.CreateParam(ref command, "LOGDATE",Now);
> if (LoggingIn)
> table.CreateParam(ref command,"INOROUT",1);
> else
> table.CreateParam(ref command,"INOROUT",0);
> Connection.Open();
> try
> {
> transaction = Connection.BeginTransaction();
> try
> {
> command.ExecuteNonQuery();
> fobar........
>

AddThis Social Bookmark Button