Microsoft Knowledge Base Article
This article contents is Microsoft Copyrighted material.
©2005-©2007 Microsoft Corporation. All rights reserved.
Terms
of Use |
Trademarks
Article ID: 269412 - Last Review: October 3, 2003 - Revision: 5.2
FIX: Access Violation Occurs When You Call SQL Server Stored Procedure That Contains PRINT Statement
This article was previously published under Q269412
An access violation occurs when you call a SQL Server stored procedure that contains a PRINT statement that displays a string containing approximately 700 characters.
This occurs with the Microsoft OLE DB Provider for SQL Server (SQLOLEDB).
Microsoft has confirmed that this is a problem in the Microsoft products that are listed at the beginning of this article.
This problem was corrected in MDAC 2.6.
You can download MDAC 2.6 or later from the following Web address:
Steps to Reproduce Behavior
- Use the following SQL script to create a stored procedure that returns 700 bytes in a PRINT statement:
CREATE PROCEDURE sp_Test2
AS
set nocount on
declare @HTMLoutputx varchar(1000)
select @HTMLoutputx = ''
/* Create a text string containing more than 700 bytes. */
WHILE LEN(@HTMLoutputx) <= 700
BEGIN
select @HTMLoutputx = @HTMLoutputx + 'TOO MUCH TEXT IS BAD!'
END
PRINT @HTMLoutputx
- Create a new Standard EXE project in Visual Basic.
- Set a Project Reference to the Microsoft ActiveX Data Objects 2.5 Library.
- Add a command button named Command1 and insert the following code for the Click event handler:
Private Sub Command1_Click()
On Error GoTo MAIN_ERROR
Dim adocnn As ADODB.Connection
Dim adocmd As ADODB.Command
Dim adorst As ADODB.Recordset
Set adocnn = New ADODB.Connection
adocnn.CursorLocation = adUseClient
adocnn.Open "Provider=SQLOLEDB;Data Source=myServer;Database=northwind;uid=sa;pwd=;"
Set adocmd = New ADODB.Command
With adocmd
.CommandText = "sp_Test2"
.CommandType = adCmdStoredProc
.ActiveConnection = adocnn
End With
' Execute the command
adocmd.Execute , , adExecuteNoRecords
Set adocmd = Nothing
adocnn.Close
Set adocnn = Nothing
Exit Sub
MAIN_ERROR:
MsgBox Err & " - " & Error$, vbCritical, "Error!"
Exit Sub
End Sub
- Run the application. Click Command1 to see the access violation occur.
For additional information about using PRINT statements and ADO, click the article number below
to view the article in the Microsoft Knowledge Base:
194792Â
(http://kbalertz.com/Feedback.aspx?kbNumber=194792/EN-US/
)
HOWTO: Retrieve Values in SQL Server Stored Procedures w/ ADO
APPLIES TO
- Microsoft OLE DB Provider for SQL Server 7.0
- Microsoft OLE DB Provider for SQL Server 7.01
- Microsoft Data Access Components 2.5
- Microsoft Data Access Components 2.5 Service Pack 1
- Microsoft Data Access Components 2.5 Service Pack 2
- Microsoft Data Access Components 2.5 Service Pack 3
| kbbug kbfix kbmdac260fix kbprovider KB269412 |
Community Feedback System
Very often, it takes hours to solve a problem. Very often, you've looked high
and low, and have tried a lot of solutions. When you finally found it, chances
are, it was because someone else helped you. Here's your chance to give back.
Use our community feedback tool to let others know what worked for you and what
didn't.
Please also understand that the community feedback system is not warranted to be
correct, it's simply a system that we've built to let people try and help each
other. If something in a feedback response doesn't make sense to you, or you're
not comfortable making changes that the feedback talks about (like registry
edits), please consult a professional.
Thank you for using kbAlertz.com Feedback System.
-- Scott Cate