2015-04-16 61 views
0

當我執行下面的存儲過程,我得到這個錯誤:事務計數後EXECUTE指示BEGIN和COMMIT語句的不匹配數

System.Data.SqlClient.SqlException: Transaction count after EXECUTE indicates a mismatching number of BEGIN and COMMIT statements. Previous count = 0, current count = 1.

代碼:

create procedure [dbo].[sp_crm_diler_master] 
(
      @Fullname varchar(100), 
      @Email varchar(50), 
      @Mobile varchar(12), 
      @qualification varchar(50), 
      @presentaddress varchar(250), 
      @permanentaddress varchar(250), 
      @location varchar(50), 
      @skills varchar(100), 
      @Dob varchar(15), 
      @myphoto varbinary(Max), 
      @uniqueid varchar(25), 
      @Message varchar(150) output 
) 
AS 
BEGIN 
if not exists (select emailid,phone from crm_masterdata where [email protected] And [email protected]) 
    begin 
begin transaction 
declare @small smalldatetime = (select CAST(@Dob as smalldatetime)) 
declare @todaydate datetime=(select getdate()) 
    insert into crm_masterdata(uniqueid,fullname,phone,dob,photo,emailid,qualification,location,present_address,permanent_address,skillsets,datasource,entrydate,active) 
values(@uniqueid,@Fullname,@Mobile,@small,@myphoto,@Email,@qualification,@location,@presentaddress,@permanentaddress,@skills,'reception',@todaydate,1) 
Set @Message=' Registration Successfull,Please Login' 
end 
else 
begin 
    set @Message='This User Already Registered' 
    end 
    end 

哪裏是我的錯誤?

+0

您的C#和asp.net代碼不相關。你的問題很嚴重在你的SP上。 – Claudio

+0

我已刪除問題的不相關部分 –

+0

您是否閱讀過錯誤?你是否在代碼中搜索提交語句? –

回答

1
create procedure [dbo].[sp_crm_diler_master] 
(
@Fullname  varchar(100), 
@Email   varchar(50), 
@Mobile   varchar(12), 
@qualification varchar(50), 
@presentaddress varchar(250), 
@permanentaddress varchar(250), 
@location  varchar(50), 
@skills   varchar(100), 
@Dob   varchar(15), 
@myphoto  varbinary(Max), 
@uniqueid  varchar(25), 
@Message  varchar(150) output 
) 
AS 
BEGIN 
    SET NOCOUNT ON; 

    declare @small smalldatetime = (select CAST(@Dob as smalldatetime)); 
    declare @todaydate datetime=getdate(); 
    declare @Error INT; 

BEGIN TRANSACTION; --<-- You need to commit it 
    IF not exists (select 1 from crm_masterdata where [email protected] And [email protected]) 
     BEGIN 
      insert into crm_masterdata(uniqueid,fullname,phone,dob,photo,emailid 
        ,qualification,location,present_address,permanent_address,skillsets,datasource,entrydate,active) 
      values(@uniqueid,@Fullname,@Mobile,@small,@myphoto,@Email,@qualification 
         ,@location,@presentaddress,@permanentaddress,@skills,'reception',@todaydate,1) 

      SET @Error = @@ERROR; 
      Set @Message =' Registration Successfull,Please Login' 
     END 
    ELSE 
     BEGIN 
      SET @Message='This User Already Registered' 
     END 

    IF (@Error = 0) 
     COMMIT TRANSACTION; --<-- Commit tran 
    ELSE 
     ROLLBACK TRANSACTION; 

END 
0

我沒有看到與您的BEGIN TRANSACTION匹配的COMMIT TRANSACTION。

相關問題