Artikel ini merujuk pada ruang nama Microsoft .NET Framework Pustaka Kelas berikut:
-
System.Data
-
System.Data.OleDb
-
System.Data.SqlClient
Gejala
Saat Anda menggunakan Penyedia Microsoft OLE DB untuk SQL Server (OLEDBSQL) di ADO.NET, jika Anda mencoba memulai lebih dari satu transaksi dalam satu sesi, Anda menerima pesan kesalahan berikut:
System.Data.OleDb.OleDbException: Tidak dapat memulai transaksi lainnya dalam sesi ini
Penyebab
Sesuai desain, Penyedia OLE DB untuk SQL Server tidak mengizinkan transaksi bertumpuk.
Informasi Selengkapnya
Langkah-langkah untuk Mereproduksi Perilaku
-
Mulai Microsoft Visual Studio .NET.
-
Buat proyek Windows Application di Visual Basic .NET. Formulir1 dibuat secara default.
-
Klik formulir1 dua kali untuk membuka jendela Kode.
-
Ganti kode di Form1 dengan kode berikut:
Imports System.DataImports System.Data.OleDbImports System.Data.SqlClientPublic Class Form1 Inherits System.Windows.Forms.Form Dim cn As New OleDb.OleDbConnection() Dim cmd As New OleDb.OleDbCommand() Dim mycmd As New OleDb.OleDbCommand()#Region " Windows Form Designer generated code " Public Sub New() MyBase.New() 'This call is required by the Windows Form Designer. InitializeComponent() 'Add any initialization after the InitializeComponent() call End Sub 'Form overrides dispose to clean up the component list. Protected Overloads Overrides Sub Dispose(ByVal disposing As Boolean) If disposing Then If Not (components Is Nothing) Then components.Dispose() End If End If MyBase.Dispose(disposing) End Sub 'Required by the Windows Form Designer Private components As System.ComponentModel.Container 'NOTE: The following procedure is required by the Windows Form Designer 'It can be modified using the Windows Form Designer. 'Do not modify it using the code editor. <System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent() ' 'Form1 ' Me.AutoScaleBaseSize = New System.Drawing.Size(5, 13) Me.ClientSize = New System.Drawing.Size(292, 273) Me.Name = "Form1" Me.Text = "Form1" End Sub#End Region Private Sub Form1_Load(ByVal sender As System.Object, _ ByVal e As System.EventArgs) Handles MyBase.Load cn.ConnectionString = "Provider=SQLOLEDB;Data Source=YourServer;" & _ "Initial Catalog=pubs;User ID=YourUserID;Password=YourPassword" cn.Open() cmd.Connection = cn mycmd.Connection = cn cmd.CommandText = "Insert into stores (stor_id) values('9876')" Dim myTrans As OleDb.OleDbTransaction myTrans = cn.BeginTransaction(IsolationLevel.ReadCommitted) cmd.Transaction = myTrans Try cmd.ExecuteNonQuery() myTrans.Begin() myTrans.Commit() Catch ex As Exception MessageBox.Show(ex.ToString) End Try End SubEnd Class
-
Ubah string koneksi yang sesuai dengan lingkungan Anda.
-
Jalankan aplikasi. Perhatikan bahwa Anda menerima kesalahan yang tercantum di bagian "Gejala".
Referensi
Untuk informasi tambahan, klik nomor artikel di bawah ini untuk melihat artikel dalam Basis Pengetahuan Microsoft:
306649 PRB: Kesalahan Ketika Anda Mengimplementasikan Transaksi Bertum tersedia dengan Penyedia OLE DB untuk SQL Ini