0

我们有一个 C# 应用程序,它发布到一个数据库,该数据库被复制到另一个数据库(使用合并复制),并且有一个自定义解析器,它是一个存储过程。

这在 SQL Server 2000 下工作正常,但是在 SQL Server 2005 下测试时,自定义解析器试图将任何空的 varchar 列更改为空值(并且失败,因为这个特定列不允许空值)。

请注意,这些 varchar 字段不是导致冲突的字段,因为它们在两个数据库上都是空的并且没有被更改并且存储过程不会更改它们(它所做的只是尝试设置另一个货币列的值) .

有没有人遇到过这个问题,或者有一个存储过程的例子,它会留下空字符串?

实际的存储过程相当简单,并在发生冲突时重新计算客户余额。

ALTER procedure [dbo].[ReCalculateCustomerBalance]
    @tableowner sysname,
    @tablename sysname,
    @rowguid varchar(36),
    @subscriber sysname,
    @subscriber_db sysname,
    @log_conflict INT OUTPUT,
    @conflict_message nvarchar(512) OUTPUT
AS
    set nocount on
DECLARE
    @CustomerID  bigint,
    @SysBalance money,
    @CurBalance money,
    @SQL_TEXT nvarchar(2000)

    Select @CustomerID = customer.id from customer where rowguid=  @rowguid

    Select @SysBalance = Sum(SystemTotal), @CurBalance = Sum(CurrencyTotal)  From CustomerTransaction Where CustomerTransaction.CustomerID = @CustomerID

    Update Customer Set SystemBalance = IsNull(@SysBalance, 0), CurrencyBalance = IsNull(@CurBalance, 0) Where id = @CustomerID

    Select * From Customer Where rowguid= @rowguid

    Select @log_conflict =0
    Select @conflict_message ='successful'
    Return(0)
4

1 回答 1

0

您在这里有几个选项,根据我的研究似乎表明 SQL Server 存在问题,每个选项都是一种解决方法。

1-更改此语句:Select * From Customer Where rowguid= @rowguid明确提及每一列,并对有问题的字段使用“isNull”

2-更改表中的列以添加“”的默认约束。这将做的是,如果您尝试插入“null”,它将用空字符串替换它

3-添加一个“插入前”触发器,它将在插入之前更改数据,不再包含“空”

PS:您确定复制系统将该列标记为“必需”吗?我认为如果不需要,如果不存在数据,它将插入“null”。

于 2009-10-05T17:27:14.013 回答