Sql Exception' @ errno'

时间:2017-11-14 12:58:12

标签: sql sql-server vb.net linq-to-sql

我是Vb.net和Linq2sql的新手,我在google上搜索了一个解决方案,然后在这里发布了一个问题,但我无法修复它,我试图将行插入数据使用Vb.net和Linq2sql,SubmitChanges()函数返回' @ errno'附近的错误语法。 SQl例外。 表格相关的触发器:

 USE [Roster]
 GO
 /****** Object:  Trigger [dbo].[ti_profile]    Script Date: 11/14/2017 
 4:17:00 PM ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO

ALTER TRIGGER [dbo].[ti_profile] on [dbo].[PROFILE] AFTER  INSERT
AS 

BEGIN
-- SET NOCOUNT ON added to prevent extra result sets from
-- interfering with SELECT statements.
SET NOCOUNT ON;

declare @ls_profile_code  varchar(6)
declare @errno int
declare @errmsg varchar(255)


--set @ls_profile_code = select inserted.profile_code from inserted

-- insert what ever was added to the object table and not yet been inserted or updated in the profile_access
insert into Profile_access (profile_code , object_code)

    select  (select inserted.profile_code from inserted) ,
            object_code
    from    Objects
    where   object_code not in

        (
            select  object_code
            from    Profile_access 
            where   profile_code = @ls_profile_code
        )




return

error:
raiserror @errno @errmsg
rollback transaction


END

关于如何解决这个问题的任何想法请...

1 个答案:

答案 0 :(得分:4)

RAISEERROR()函数requires parentheses now。这在Sql Server 2008 R2和Sql Server 2012之间发生了变化。

所以这个:

raiserror @errno @errmsg

成为这个:

raiserror(@errmsg, @errno, 1)