Notice: This website is an unofficial Microsoft Knowledge Base (hereinafter KB) archive and is intended to provide a reliable access to deleted content from Microsoft KB. All KB articles are owned by Microsoft Corporation. Read full disclaimer for more details.

FIX: Transaction Rolls Back Automatically with Error 8144 on a Prepared Command


View products that this article applies to.

This article was previously published under Q328908

↑ Back to the top


Symptoms

When you use an OLE DB application, or an ActiveX Data Objects (ADO) application, and you execute a stored procedure against SQL Server 2000, Error 8144 occurs and Microsoft SQL OLE DB Provider (SQLOLEDB) rolls back the transaction automatically without notifying the application. Error 8144 from SQL Server appears in the SQL Profiler Trace log as follows:
Error: 8144, Severity: 16, State: 2
This error occurs when the following conditions are true:
  • You use Microsoft SQL OLE DB Provider (SQLOLEDB).
  • You execute the stored procedure in the scope of a transaction more than one time.
  • You do not set the parameters manually (for example, you populate the parameter collection by using the Parameters.Refresh method in ADO).
  • You perform a deferred prepare on the command (for example, command.Properties("Defer Prepare") = TRUE which is the default option and command.Prepared=TRUE).

↑ Back to the top


Cause

This occurs because of a bug in Microsoft SQL OLE DB provider. In the case of a deferred prepare, SQLOLEDB sends incorrect parameters to Microsoft SQL Server 2000 which causes SQL Server to throw error 8144.

↑ Back to the top


Resolution

A supported hotfix is now available from Microsoft, but it is only intended to correct the problem that is described in this article. Only apply it to systems that are experiencing this specific problem. This hotfix may receive additional testing. Therefore, if you are not severely affected by this problem, we recommend that you wait for the next Microsoft Data Access Components service pack that contains this hotfix.

To resolve this problem immediately, contact Microsoft Product Support Services to obtain the hotfix. For a complete list of Microsoft Product Support Services telephone numbers and information about support costs, visit the following Microsoft Web site:Note In special cases, charges that are ordinarily incurred for support calls may be canceled if a Microsoft Support Professional determines that a specific update will resolve your problem. The usual support costs will apply to additional support questions and issues that do not qualify for the specific update in question.
The English version of this fix should have the following file attributes or later.
    Date           Version           Size              File name     
    ------------------------------------------------------------
    11-Sep-2002    2000.81.9031.3    471,040 bytes     Sqloledb.dll
				

WORKAROUND

To work around this problem, use one of the following methods:
  • Manually set the parameter information.
  • Do not prepare the command on which the stored procedure is executed.
  • Set the Defer Prepare property to False on the command object (for example: command.Properties("Defer Prepare") = False).

↑ Back to the top


Status

Microsoft has confirmed that this is a bug in the Microsoft products that are listed at the beginning of this article.

↑ Back to the top


More information

Steps to Reproduce the Behavior

  1. Execute the following script to create stored procedure that is named test_sp:
    'Stored Procedure definition
    create procedure test_sp @p1 int, @p2 int
    as
    set nocount on
    return 1
    					
  2. Create a new Standard EXE project in Microsoft Visual Basic 6.0.
  3. On the Project menu, click References, and then click to select the Microsoft ActiveX Data Objects 2.7 Library check box.
  4. Add a CommandButton to the main Form.
  5. Double-click the Command button. Paste the following code in the Command1_Click() event handler:

    NoteYou must change the User Id <user name> and the password <strong password> to the correct values. Make sure that User ID has the appropriate permissions to perform these operations on the database.
    Private Sub Command1_Click()
    Dim cn As New ADODB.Connection
    Dim cmd As New ADODB.Command
    
    cn.Open "provider=sqloledb;data source=mysqlserver;User Id=<username>;Password=<strong password>;initial catalog=pubs"
    cmd.ActiveConnection = cn
    cmd.CommandText = "test_sp"
    cmd.CommandType = adCmdStoredProc
    cmd.Prepared = True
    
    cmd.Parameters.Refresh
    cn.BeginTrans
    For i = 1 To 2
       cmd(1) = 1
       cmd(2) = 2
     cmd.Execute
    Next
    
    ' Manually setting the param values works
    'cmd.CreateParameter "p2", adInteger, adParamInput
    'With cmd
    '    .Parameters.Append .CreateParameter("p1", adInteger, adParamInput)
    '    .Parameters.Append .CreateParameter("p2", adInteger, adParamInput)
    'End With
    '
    'cn.BeginTrans
    'For i = 1 To 2
    '    cmd.Parameters.Item("p1") = 1
    '    cmd.Parameters.Item("p2") = 2
    '    cmd.Execute
    'Next
    
    Set cmd = Nothing
    cn.CommitTrans
    cn.Close
    Set cn = Nothing
    
    End Sub
    					
    NOTE: Change the connection string as appropriate for your environment.

  6. Save and then run your project.

↑ Back to the top


Keywords: KB328908, kbhotfixserver, kbqfe, kbprovider, kbfix, kbbug

↑ Back to the top

Article Info
Article ID : 328908
Revision : 6
Created on : 10/11/2005
Published on : 10/11/2005
Exists online : False
Views : 482