CommittableTransaction Constructors
Definitie
Belangrijk
Bepaalde informatie heeft betrekking op een voorlopige productversie die aanzienlijk kan worden gewijzigd voordat deze wordt uitgebracht. Microsoft biedt geen enkele expliciete of impliciete garanties met betrekking tot de informatie die hier wordt verstrekt.
Initialiseert een nieuw exemplaar van de CommittableTransaction klasse.
Overloads
| Name | Description |
|---|---|
| CommittableTransaction() |
Initialiseert een nieuw exemplaar van de CommittableTransaction klasse. |
| CommittableTransaction(TimeSpan) |
Initialiseert een nieuw exemplaar van de CommittableTransaction klasse met de opgegeven |
| CommittableTransaction(TransactionOptions) |
Initialiseert een nieuw exemplaar van de CommittableTransaction klasse met de opgegeven transactieopties. |
CommittableTransaction()
Initialiseert een nieuw exemplaar van de CommittableTransaction klasse.
public:
CommittableTransaction();
public CommittableTransaction();
Public Sub New ()
Voorbeelden
In het volgende voorbeeld wordt een nieuw exemplaar gemaakt van CommittableTransaction en doorgevoerd.
//Create a committable transaction
tx = new CommittableTransaction();
SqlConnection myConnection = new SqlConnection("server=(local)\\SQLExpress;Integrated Security=SSPI;database=northwind");
SqlCommand myCommand = new SqlCommand();
//Open the SQL connection
myConnection.Open();
//Give the transaction to SQL to enlist with
myConnection.EnlistTransaction(tx);
myCommand.Connection = myConnection;
// Restore database to near it's original condition so sample will work correctly.
myCommand.CommandText = "DELETE FROM Region WHERE (RegionID = 100) OR (RegionID = 101)";
myCommand.ExecuteNonQuery();
// Insert the first record.
myCommand.CommandText = "Insert into Region (RegionID, RegionDescription) VALUES (100, 'MidWestern')";
myCommand.ExecuteNonQuery();
// Insert the second record.
myCommand.CommandText = "Insert into Region (RegionID, RegionDescription) VALUES (101, 'MidEastern')";
myCommand.ExecuteNonQuery();
// Commit or rollback the transaction
while (true)
{
Console.Write("Commit or Rollback? [C|R] ");
ConsoleKeyInfo c = Console.ReadKey();
Console.WriteLine();
if ((c.KeyChar == 'C') || (c.KeyChar == 'c'))
{
tx.Commit();
break;
}
else if ((c.KeyChar == 'R') || (c.KeyChar == 'r'))
{
tx.Rollback();
break;
}
}
myConnection.Close();
tx = null;
tx = New CommittableTransaction
Dim myConnection As New SqlConnection("server=(local)\SQLExpress;Integrated Security=SSPI;database=northwind")
Dim myCommand As New SqlCommand()
'Open the SQL connection
myConnection.Open()
'Give the transaction to SQL to enlist with
myConnection.EnlistTransaction(tx)
myCommand.Connection = myConnection
'Restore database to near it's original condition so sample will work correctly.
myCommand.CommandText = "DELETE FROM Region WHERE (RegionID = 100) OR (RegionID = 101)"
myCommand.ExecuteNonQuery()
'Insert the first record.
myCommand.CommandText = "Insert into Region (RegionID, RegionDescription) VALUES (100, 'MidWestern')"
myCommand.ExecuteNonQuery()
'Insert the second record.
myCommand.CommandText = "Insert into Region (RegionID, RegionDescription) VALUES (101, 'MidEastern')"
myCommand.ExecuteNonQuery()
'Commit or rollback the transaction
Dim c As ConsoleKeyInfo
While (True)
Console.Write("Commit or Rollback? [C|R] ")
c = Console.ReadKey()
Console.WriteLine()
If (c.KeyChar = "C") Or (c.KeyChar = "c") Then
tx.Commit()
Exit While
ElseIf ((c.KeyChar = "R") Or (c.KeyChar = "r")) Then
tx.Rollback()
Exit While
End If
End While
myConnection.Close()
tx = Nothing
Van toepassing op
CommittableTransaction(TimeSpan)
Initialiseert een nieuw exemplaar van de CommittableTransaction klasse met de opgegeven timeout waarde.
public:
CommittableTransaction(TimeSpan timeout);
public CommittableTransaction(TimeSpan timeout);
new System.Transactions.CommittableTransaction : TimeSpan -> System.Transactions.CommittableTransaction
Public Sub New (timeout As TimeSpan)
Parameters
- timeout
- TimeSpan
De maximale hoeveelheid tijd die de transactie kan bestaan, voordat deze wordt afgebroken.
Van toepassing op
CommittableTransaction(TransactionOptions)
Initialiseert een nieuw exemplaar van de CommittableTransaction klasse met de opgegeven transactieopties.
public:
CommittableTransaction(System::Transactions::TransactionOptions options);
public CommittableTransaction(System.Transactions.TransactionOptions options);
new System.Transactions.CommittableTransaction : System.Transactions.TransactionOptions -> System.Transactions.CommittableTransaction
Public Sub New (options As TransactionOptions)
Parameters
- options
- TransactionOptions
Een TransactionOptions structuur die de transactieopties beschrijft die moeten worden gebruikt voor de nieuwe transactie.
Uitzonderingen
options is ongeldig.
Voorbeelden
In het volgende voorbeeld wordt een nieuw exemplaar met CommittableTransaction opties gemaakt en wordt het afgebroken.