Problem with transaction error

C

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........
 
M

Miha Markic [MVP C#]

Assign transaction to command before execution, i.e.:
command.Transaction = transaction;
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top