2

非常简单的 table 和 insert 语句,如果字符串是“Golf”则失败,但适用于任何其他字符串。表创建:

CREATE TABLE [dbo].[market]
(
    [marketID] [int] NOT NULL,
    [name] [varchar](50) NULL,
CONSTRAINT [PK_market] PRIMARY KEY CLUSTERED ([marketID] ASC)
)

插入:

INSERT [dbo].[market] ([marketID], [name]) VALUES (4, N'Golf')

Error: Unclosed quotation mark after the character string ''. (State:37000, Native Code: 69)
Error: Incorrect syntax near ''. (State:37000, Native Code: 66)
Error: Unclosed quotation mark after the character string ')'.

现在,如果我将插入更改为:

INSERT [dbo].[market] ([marketID], [name]) VALUES (4, N'Test')

它工作得很好。以前有人见过吗?

4

1 回答 1

3

我认为如果在字符串中的任何位置找到 GO,您正在使用的应用程序必须被破坏并分成多个批次。

例如,它使用了一种天真的方法,如下所示。

Regex.Split(sqlString, "GO", RegexOptions.IgnoreCase);

然后将结果作为单独的批次执行。

跑步

INSERT [dbo].[market] ([marketID], [name]) VALUES (4, N'

返回您报告的前两个错误。

Msg 105, Level 15, State 1, Line 1 字符串 '' 后面的非闭合引号。

消息 102,级别 15,状态 1,第 1 行 '' 附近的语法不正确。

执行

lf')

返回第三个。

Msg 105, Level 15, State 1, Line 1 字符串 ') ' 后面的非闭合引号。

一个临时的解决方法可能是尝试

INSERT [dbo].[market] ([marketID], [name]) VALUES (4, N'G' + 'olf')

但当然,该应用程序确实需要修复。

于 2014-03-11T13:43:05.373 回答