Einzelnen Beitrag anzeigen

Benutzerbild von Neutral General
Neutral General

Registriert seit: 16. Jan 2004
Ort: Bendorf
5.219 Beiträge
 
Delphi 10.2 Tokyo Professional
 
#1

Firebird - Mehrere abhängige SQLs in einer Transaktion

  Alt 25. Jan 2016, 16:17
Hallo,

Ich verzweifel hier langsam
Ich möchte eine Liste von SQL-Befehlen hintereinander in der gleichen Transaktion ausführen.
Wenn ich allerdings ein CREATE TABLE ausführe (erfolgreich) und danach ein INSERT in diese Tabelle machen will,
schlägt das INSERT fehl weil die vorher erstellte Tabelle angeblich nicht existiert:

Code:
FbTransaction trans = connection.BeginTransaction(); // connection ist eine aktive Verbindung
try
{
  for (int i=0; i < SqlStatements.Count; i++) // List<string> SqlStatements
  {
    FbCommand cmd = new FbCommand(SqlStatements[i], connection, trans);
    cmd.ExecuteNonQuery();
  }

  trans.Commit();
}
catch(FbException ex)
{
  trans.Rollback();
}

Kann mir jemand sagen was ich falsch mache?

(PS: Ich weiß, dass es FbBatchExecution gibt, aber das reicht für meine Zwecke nicht, ich muss es von Hand machen)

Crosspost: http://www.entwickler-ecke.de/viewtopic.php?p=698278#
Michael
"Programmers talk about software development on weekends, vacations, and over meals not because they lack imagination,
but because their imagination reveals worlds that others cannot see."
  Mit Zitat antworten Zitat