使用 Microsoft 登入
登入或建立帳戶。
您好:
選取其他帳戶。
您有多個帳戶
選擇您要用來登入的帳戶。

本文參照下列 Microsoft .NET Framework文件庫命名空間:

  • System.Data

  • System.Data.OleDb

  • System.Data.SqlClient

徵兆

當您在 ADO.NET 中針對 SQL Server (OLEDBSQL) 使用 Microsoft OLE DB 提供者時,如果您嘗試在會話中啟動多個交易,您會收到下列錯誤訊息:

System.Data.OleDb.OleDbException:無法在此會話啟動更多交易

原因

根據設計,SQL Server OLE DB 提供者不允許巢式交易。

其他相關資訊

重現行為的步驟

  1. 啟動 Microsoft Visual Studio .NET。

  2. 在 Windows 中建立 Visual Basic 應用程式專案。 表單 1 預設為建立。

  3. 按兩下 [表單1》 以開啟 [程式碼> 視窗。

  4. 以下列程式碼取代 Form1 中的程式碼:

    Imports System.Data
    Imports System.Data.OleDb
    Imports System.Data.SqlClient

    Public 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 Sub
    End Class
  5. 請根據環境修改連接字串。

  6. 執行應用程式。 請注意,您收到「症狀」一節中所列的錯誤。

參考

若要瞭解詳細資訊,請按一下下方的文章編號,以在 Microsoft 知識庫中查看文章:

306649 PRB:當您使用 OLE DB 提供者為提供者套用巢SQL錯誤

需要更多協助嗎?

想要其他選項嗎?

探索訂閱權益、瀏覽訓練課程、瞭解如何保護您的裝置等等。

社群可協助您詢問並回答問題、提供意見反應,以及聆聽來自具有豐富知識的專家意見。

這項資訊有幫助嗎?

您對語言品質的滿意度如何?
以下何者是您會在意的事項?
按下 [提交] 後,您的意見反應將用來改善 Microsoft 產品與服務。 您的 IT 管理員將能夠收集這些資料。 隱私權聲明。

感謝您的意見反應!

×