我有一个应该更新表的存储过程。当我直接运行它时,我得到“Command(s)成功完成。”但是当从C#调用时它不会改变表格。出了什么问题?
set ANSI_NULLS ON
set QUOTED_IDENTIFIER ON
go
-- =============================================
-- Author: Mohamamd Ibrahim Tasal
-- Create date: 29-Octobar-2009
-- Description: This procedure is releasing Numbers....
-- =============================================
ALTER PROCEDURE [dbo].[Release_MassMSISDN]
(
@Quantity int,
@_SCP int
)
AS
BEGIN
SET NOCOUNT ON;
set @Quantity=1;
set @_SCP=798000070;
DECLARE @_Filter nvarchar(1000)
DECLARE @sql nvarchar(4000)
IF @_SCP = 2
SET @_Filter = 'MSISDN LIKE ''799%'' OR MSISDN LIKE ''798%'''
IF @_SCP = 1
SET @_Filter = 'MSISDN LIKE ''797%'' OR MSISDN LIKE ''796%'' OR MSISDN LIKE ''7950%'' OR MSISDN LIKE ''7951%'' OR MSISDN LIKE ''7952'' OR MSISDN LIKE ''7953%'' OR MSISDN LIKE ''7954%'''
IF @_SCP = 3
SET @_Filter = 'MSISDN LIKE ''794%'''
IF @_SCP = 4
SET @_Filter = 'MSISDN LIKE ''793%''or MSISDN LIKE ''7955%'' OR MSISDN LIKE ''7956%'' OR MSISDN LIKE ''7957%'' or MSISDN LIKE ''7958%'' OR MSISDN LIKE ''7959%'''
UPDATE
MSISDN_Master
SET
IMSI_HLR=NULL,
IMSI_IN=NULL,
GoldNumber=0,
SERIAL=NULL,
FK_AllocationTypeID = NULL,
FK_ProfileTypeID = NULL,
FK_ModelTypeID = NULL,
FK_StatusID = NULL,
FK_BatchID = NULL,
Activation_Date = NULL,
Locked = 0,
ICBlocked = 0,
langcur = NULL,
Credit = NULL
WHERE msisdn in ('SELECT TOP '+ CAST(@quantity AS varchar(10)) + ' MSISDN,IMSI_HLR,IMSI_IN,Serial,FK_BatchID BatchID,FK_AllocationTypeID AllocationTypeID,FK_ProfileTypeID ProfileTypeID,FK_ModelTypeID ModelTypeID,Activation_Date FROM MSISDN_Master
where imsi_hlr not like ''412%'' and imsi_hlr not like ''GOL%'' and imsi_hlr is not null and imsi_in is not null AND ('+ @_Filter +') ORDER BY MSISDN')
END
答案 0 :(得分:1)
您应该查看可用的调试选项。我相信如果你设置正确,你可以直接从你的C#调试到你的SQL存储过程。从来没有必须自己做,但我被告知可以做到。
Alterantively设置一个等效的存储过程,它只执行UPDATE的WHERE子句的SELECT,看看你实际上是否正在获取任何记录,以及你希望更改的列是否与你希望更改它们的值不同。
当然检查连接字符串是否指向正确的数据库。那个人曾经抓过我一次(并且非常尴尬)。
否则,正如其他人所建议的那样,更多的上下文和C#代码将是有用的。是什么让你确保行被修改。 SQL提及行是否已被修改或仅执行了命令?
答案 1 :(得分:0)
您确定直接运行存储过程时表格是否已正确更新?
您的C#代码是否有可能在调用存储过程之前开始事务,但之后从未提交过它?