|
dev
newsgroups
|
|||||||||||||||||||||||
|
|||||||||||||||||||||||
Problem with transaction errorconnection 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........ Assign transaction to command before execution, i.e.:
command.Transaction = transaction; -- Show quoteMiha Markic [MVP C#, INETA Country Leader for Slovenia] RightHand .NET consulting & development www.rthand.com Blog: http://cs.rthand.com/blogs/blog_with_righthand/ "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........ > |
|||||||||||||||||||||||