static void UpgradePlayerTimeSpents() { using (SqlTransaction bulk = new SqlTransaction()) { for (int i = 0; i < playerIds.Count; i++) { bulk.Execute("UPDATE Players SET TimeSpent=@1 WHERE ID=@0", playerIds[i], playerSeconds[i]); } bulk.Commit(); } }
static void ImportBulk(StreamReader reader) { SqlTransaction bulk = null; List <string> buffer = new List <string>(); try { bulk = new SqlTransaction(); while (!reader.EndOfStream) { string cmd = NextStatement(reader, buffer); if (cmd == null || cmd.Length == 0) { continue; } int index = cmd.ToUpper().IndexOf("CREATE TABLE"); if (index >= 0) { cmd = cmd.Remove(0, index); cmd = cmd.Replace(" unsigned", " UNSIGNED"); Database.Backend.ParseCreate(ref cmd); } //Run the command in the transaction. if (bulk.Execute(cmd, null)) { continue; } // Something went wrong.. commit what we've imported so far. // We need to recreate connection otherwise every helper.Execute fails bulk.Commit(); bulk.Dispose(); bulk = new SqlTransaction(); } bulk.Commit(); } finally { if (bulk != null) { bulk.Dispose(); } } }