Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Reuse connection after Fill
Message
 
À
27/05/2006 00:33:22
Information générale
Forum:
ASP.NET
Catégorie:
ADO.NET
Versions des environnements
Environment:
C# 2.0
Divers
Thread ID:
01125464
Message ID:
01125503
Vues:
15
This message is not nessesarily to Bonnie, since she will not be replying for another 6 weeks <s>

I took Bonnies' advice and used a transaction, but it isn't working like I would expect. In order to test this I put in a break point after the Fill() and then quickly added another record to the table before the delete executed. This resulted in a selected and deleted row count mismatch and a rollback was issued on the transaction. Now I went back into the table and found that there were no rows in the table!! They should still be there because I did a rollback!!
Anywho is it possible that the database server does not supprt this rollback feature or is this rollback feature a pure ADO.NET feature and the backend database does not matter?

I posted the code I am using, just in case I made some crazy mistakes.

Any information on transactions in 2.0 is welcome.

Thanks,
Einar
using (OleDbConnection connection = new OleDbConnection(@"Provider=Advantage OLE DB Provider; Data Source=" + this._DataPath))
{
	OleDbCommand command = new OleDbCommand();
	OleDbTransaction transaction = null;

	try
	{
		connection.Open();

		transaction = connection.BeginTransaction(IsolationLevel.ReadCommitted);

		command.Connection = connection;
		command.Transaction = transaction;

		command.CommandText = "SELECT * FROM Commands";
		OleDbDataAdapter adapter = new OleDbDataAdapter(command);
		adapter.Fill(this.commandsTable);

		command.CommandText = "DELETE FROM Commands";
		int deletedRows = command.ExecuteNonQuery();

		System.Windows.Forms.MessageBox.Show("deletedRows: " + deletedRows.ToString() + Environment.NewLine + "this.commandsTable.Rows.Count() : " + this.commandsTable.Rows.Count.ToString());
		if (deletedRows == this.commandsTable.Rows.Count)
		{
			transaction.Commit();
		}
		else
		{
			transaction.Rollback();
		}
	}
	catch (Exception ex)
	{
		try
		{
			transaction.Rollback();
		}
		catch{ //don't worry about it}
	}
}
Semper ubi sub ubi.
Précédent
Suivant
Répondre
Fil
Voir

Click here to load this message in the networking platform