Microsoft KB Archive/328908

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

Article ID: 328908

Article Last Modified on 10/11/2005

-

APPLIES TO


 * Microsoft Data Access Components 2.7
 * Microsoft SQL Server 2000 Service Pack 3a
 * Microsoft SQL Server 2000 Service Pack 1
 * Microsoft SQL Server 2000 Service Pack 2

-



This article was previously published under Q328908



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(&quot;Defer Prepare&quot;) = TRUE which is the default option and command.Prepared=TRUE).



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.



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:

http://support.microsoft.com/contactus/?ws=support

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(&quot;Defer Prepare&quot;) = False).



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



Steps to Reproduce the Behavior
  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  Create a new Standard EXE project in Microsoft Visual Basic 6.0. On the Project menu, click References, and then click to select the Microsoft ActiveX Data Objects 2.7 Library check box. Add a CommandButton to the main Form.  Double-click the Command button. Paste the following code in the Command1_Click event handler:

NoteYou must change the User Id and the 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 &quot;provider=sqloledb;data source=mysqlserver;User Id= ;Password= ;initial catalog=pubs&quot; cmd.ActiveConnection = cn cmd.CommandText = &quot;test_sp&quot; 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 &quot;p2&quot;, adInteger, adParamInput 'With cmd '   .Parameters.Append .CreateParameter(&quot;p1&quot;, adInteger, adParamInput) '   .Parameters.Append .CreateParameter(&quot;p2&quot;, adInteger, adParamInput) 'End With ' 'cn.BeginTrans 'For i = 1 To 2 '   cmd.Parameters.Item(&quot;p1&quot;) = 1 '   cmd.Parameters.Item(&quot;p2&quot;) = 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.

</li> Save and then run your project.</li></ol>

Additional query words: 8144 transaction SQLOLEDB REFRESH parameters stored procedure

Keywords: kbbug kbfix kbprovider kbqfe kbhotfixserver KB328908

-

[mailto:TECHNET@MICROSOFT.COM Send feedback to Microsoft]

© Microsoft Corporation. All rights reserved.