One command causes another to fail
Posted: Mon 04 Apr 2016 10:31
Hi,
When I run 3 UniCommands and the second one fails, the third will also fail silently eventho its a correct command.
For example
UPDATE AANHEF SET CONDITIONAL = CONDITIONAL;
UPDATE DOES_NOT_EXIST SET CONDITIONAL = CONDITIONAL;
UPDATE AANHEF SET CONDITIONAL = CONDITIONAL;
The rows affected of the first statement is 8
The second statement will fail
The rows affected of the third statmeent (which is identical to the first) is -1
What does that mean?
If I run the statments a second time I get a different error:
prepared statement "PRSTMT2864046221016346609" does not exist
Which goes away when I turn off connection pooling
But I cant fix the fact that rows affect is -1 instead of 8 for the third statement
The code I use is:
Regards,
Jan
When I run 3 UniCommands and the second one fails, the third will also fail silently eventho its a correct command.
For example
UPDATE AANHEF SET CONDITIONAL = CONDITIONAL;
UPDATE DOES_NOT_EXIST SET CONDITIONAL = CONDITIONAL;
UPDATE AANHEF SET CONDITIONAL = CONDITIONAL;
The rows affected of the first statement is 8
The second statement will fail
The rows affected of the third statmeent (which is identical to the first) is -1
What does that mean?
If I run the statments a second time I get a different error:
prepared statement "PRSTMT2864046221016346609" does not exist
Which goes away when I turn off connection pooling
But I cant fix the fact that rows affect is -1 instead of 8 for the third statement
The code I use is:
Code: Select all
using (UniConnection connection = new UniConnection(connectionString))
{
connection.Open();
int max = lines.Count();
int percent = max / 100;
if (percent == 0)
percent = 1;
int i = 1;
int errorCount = 0;
try
{
foreach (string line in lines)
{
if (!string.IsNullOrEmpty(line))
{
using (UniCommand command = connection.CreateCommand())
{
command.CommandText = line;
try
{
command.Prepare();
int modified = command.ExecuteNonQuery();
if (modified > 0)
Trace.TraceWarning(string.Format(@"{0}
Records aangepast: {1}",
line, modified));
}
catch (Exception ex)
{
Trace.TraceError(string.Format(@"{0}
ERROR: {1}", line, ex.Message));
errorCount++;
}
}
}
if (worker != null && i % percent == 0)
worker.ReportProgress(i * 100 / max, string.Format("[{0}/{1}] {2}", i, max, line));
i++;
}
if (errorCount > 0)
throw new Exception(string.Format("Er zijn fouten opgetreden ({0})", errorCount));
if (worker != null)
worker.ReportProgress(100, "Script executed succesfully.");
}
catch (Exception ex)
{
if (worker != null)
{
worker.ReportProgress(0, string.Format("ERROR: {0}", ex.Message));
}
}
}
Jan