BUG: ExecuteWithResultsAndMessages2 Does Not Return Results (279514)



The information in this article applies to:

  • Microsoft SQL Server 6.5
  • Microsoft SQL Server 7.0
  • Microsoft SQL Server 2000 (all editions)

This article was previously published under Q279514
BUG #: 17969 (SQLBUG_65)
BUG #: 39552 (SQLBUG_70)
BUG #: 235353 (SHILOH)

SYMPTOMS

When called from Microsoft Visual Basic Script (VBScript), the ExecuteWithResultsAndMessages2 method does not return results. Instead, it generates a run-time error similar to the following:
Windows Script Host
Error: Type mismatch: 'db.ExecuteWithResultsAndMessages2'
Code: 800A000D
Source: Microsoft VBScript runtime error
The ExecuteWithResultsAndMessages2 method works correctly within Visual Basic when the variable is defined as a string.

CAUSE

The ExecuteWithResultsAndMessages2 method executes a Transact-SQL command batch, returns batch result sets in a QueryResults object, and captures messages raised as part of command batch execution. A string is used to return the message output, but the VB script uses a variant data type. The mismatch between the string and variant data types causes the type mismatch error.

STATUS

Microsoft has confirmed this to be a problem in SQL Server 6.5.
Microsoft has confirmed this to be a problem in SQL Server 7.0.
Microsoft has confirmed this to be a problem in SQL Server 2000.

MORE INFORMATION

To reproduce the problem, use the following code, replacing the server name, login id, and password appropriately:
Option Explicit
Dim objSqlServer
Dim objDatabase
Dim objTable
Dim objQueryResults
Dim strMessages
Set objSqlServer = WScript.CreateObject("SQLDMO.SQLServer")
Call objSqlServer.Connect("server name","login id","password")
Set objDatabase = objSqlServer("pubs")
WScript.Echo("Enter Call ExecuteWithResultsAndMessage2")
strMessages = ""
Set objQueryResults = objDatabase.ExecuteWithResultsAndMessages2("DBCC CHECKALLOC('pubs')",strMessages)
WScript.Echo(strMessages)
Set objTable = objDatabase.Tables("titles")
strMessages = objTable.CheckTable
WScript.Echo("*" & strMessages)
WScript.Echo("Exit Call ExecuteWithResultsAndMessages2")
WScript.Quit(1)
				

Modification Type:MajorLast Reviewed:11/17/2003
Keywords:kbbug kbpending KB279514