迁移到 SQL Server 2008 时受影响的 ADO 命令对象记录被破坏

发布于 2024-08-17 16:02:28 字数 1946 浏览 4 评论 0原文

我的公司正在将数据库从 SQL 2000 迁移到 SQL 2008。我正在测试一些遗留应用程序,并发现一个 VB6 应用程序遇到了错误。该代码尝试对记录运行简单的更新,并使用 RecordsAffected 参数检查 Execute 方法是否影响了不止一行。

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
  QCBatchFailurePercentage=@QCBatchFailurePercentage 
 ,QCBatchCompleteDate=@QCBatchCompleteDate
WHERE
 QCID=@QCId

我不确定 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,而不是像 SQL 2000 上那样的 1。我知道我可以更改存储过程以返回 @@rowcount 或者只是删除对成功的检查,但是具有此模式的代码的其他部分也存在类似的问题。

My company is in the process of moving a database from SQL 2000 to SQL 2008. I am in the process of testing some of our legacy applications and came across a VB6 app that is running into a bug. The code is attempting to run a simple update for a record and check that the Execute method has affected more then one row using the RecordsAffected parameter.

The VB6 code

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

The stored procedure create code

ALTER proc [dbo].[Wendy_OffshoreQC_UpdateQCRecord]
  @QCId int
 ,@QCBatchFailurePercentage decimal (18,2)
 ,@QCBatchCompleteDate smalldatetime

AS

UPDATEtblQC
SET
  QCBatchFailurePercentage=@QCBatchFailurePercentage 
 ,QCBatchCompleteDate=@QCBatchCompleteDate
WHERE
 QCID=@QCId

I'm not sure which the ADO connection ends up using. The outside provider is the SQL Server OLE DB provider, but in the extended properties the drive says the SQL Server. I'm going to try fixing some of the code to be consistent with the driver that is used.

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

However numRecordsUpdate always returns -1 instead of 1 like it did on SQL 2000. I know I can change the stored procedure to return @@rowcount or just remove the check for success, but there are other parts of the code with this pattern that are having a similar issue.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

維他命╮ 2024-08-24 16:02:28

我不知道有比在存储过程中使用 SET NOCOUNT ON 并使用 OUTPUT 参数返回 @@ROWCOUNT 更好的答案代码>.

也许您可以尝试使用不同的提供程序 - 您当前使用的是 ADO.net、OLEDB 或 SQL Native Client?更改提供程序可能会有所帮助,因为我知道 SET NOCOUNT ON 曾经导致 ADO.net 出现问题。

I don't know that there's a better answer than to use SET NOCOUNT ON in the stored procedure, and use an OUTPUT parameter to return @@ROWCOUNT.

Perhaps you could try using a different provider - are you currently using ADO.net, or OLEDB, or SQL Native Client? Changing the provider might help, as I know that SET NOCOUNT ON used to cause issues with ADO.net.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文