我的公司正在将数据库从SQL 2000移动到SQL 2008.我正在测试我们的一些旧应用程序并且遇到了一个VB6应用程序那正在遇到一个错误。该代码正试图对记录运行简单更新,并使用RecordsAffected参数检查Execute方法是否影响了多行。当移动到SQL Server 2008时,受影响的ADO命令对象记录破坏
VB6的代码
cmd.ActiveConnection = gcnADODE
cmd.CommandType = adCmdStoredProc
cmd.CommandText = "Wendy_OffshoreQC_UpdateQCRecord"
Set QCID = cmd.CreateParameter("@QCId", adInteger, adParamInput)
QCID.value = 1
cmd.Parameters.Append QCID
Set QCBatchFailurePercentage = cmd.CreateParameter("@QCBatchFailurePercentage", adDecimal, adParamInput)
QCBatchFailurePercentage.Precision = 18
QCBatchFailurePercentage.NumericScale = 2
QCBatchFailurePercentage.value = 1.11
cmd.Parameters.Append QCBatchFailurePercentage
Set QCBatchCompleteDate = cmd.CreateParameter("@QCBatchCompleteDate", adDate, adParamInput)
QCBatchCompleteDate.value = Format(Now, "yyyy-mm-dd hh:mm:ss")
cmd.Parameters.Append QCBatchCompleteDate
cmd.Execute numRecordsUpdate
success = numRecordsUpdate > 0
存储过程创建代码
ALTER proc [dbo].[Wendy_OffshoreQC_UpdateQCRecord]
@QCId int
,@QCBatchFailurePercentage decimal (18,2)
,@QCBatchCompleteDate smalldatetime
AS
UPDATEtblQC
SET
[email protected]
,[email protected]
WHERE
[email protected]
我不知道这ADO连接结束使用。外部提供程序是SQL Server OLE DB提供程序,但在扩展属性中,驱动器表示SQL Server。我将尝试修复一些代码以与使用的驱动程序保持一致。
Provider=SQLOLEDB.1;Password=1234;Extended
Properties="driver={SQL Server};uid=username;database=db;
server=server";Use Procedure for Prepare=1;Auto Translate=True;Packet Size=4096;
Workstation ID=PICASWS186;Use Encryption for Data=False;Tag with column collation when
possible=False
然而numRecordsUpdate
总是返回-1,而不是1就像它在2000年的SQL我知道我可以改变存储过程返回@@rowcount
或只是删除了成功的支票,但也有代码的其他部分这种模式有类似的问题。
我正在使用SQL Server本机客户端。 – Gariig 2010-01-12 13:34:09
所以你有没有试过改变存储过程以包含SET NOCOUNT ON;在执行更新之前?这看起来很不直观,但我认为可能是“1行受影响”信息干扰的情况。 – 2010-01-13 03:51:36