【问题标题】:Sql Exception Incorrect syntax near '@errno''@errno' 附近的 Sql 异常语法不正确
【发布时间】:2017-11-14 12:58:11
【问题描述】:

我是 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

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

【问题讨论】:

  • 首先标记正在使用的正确数据库.. MySQL 与 SQL-server 不同。
  • 什么是配置文件以及如何链接到数据库?你有带@errno 参数的触发器或函数吗?
  • @RaymondNijland 谢谢,这是个错误
  • 您的代码中没有与@errno 类似的内容,因此我们无法提供帮助。在您的数据库上查找触发器。
  • @JuanCarlosOropeza 我更新了我的问题,请看一下。

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


【解决方案1】:

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

所以这个:

raiserror @errno @errmsg

变成这样:

raiserror(@errmsg, @errno, 1)

【讨论】:

    猜你喜欢
    • 2011-10-25
    • 1970-01-01
    • 2023-03-25
    • 1970-01-01
    • 2017-02-07
    • 2018-06-26
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多