Sql CE与多个语句不一致 [英] Sql CE Inconsistent with Multiple Statements

查看:57
本文介绍了Sql CE与多个语句不一致的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

您可以执行使用SQL CE的多个语句。实际上,我正在使用 SQL Server Compact Toolbox 来做到这一点。但是,当我使用相同的多语句命令并从Dapper执行它们时...

It has long been true that you can execute multiple statements with SQL CE. And in fact I'm using SQL Server Compact Toolbox to do exactly that. But when I take the same multiple-statement commands and execute them from Dapper...

public const string SampleDml = @"
   INSERT INTO [Plugin](Name, TypeName) VALUES ('Blog','Shroom.Blog');
   GO
   INSERT INTO [ContentDef](PluginID, Name, Placement, IsStatic) VALUES(@@IDENTITY,'MyBlog','Layout:Left',1);
   GO
";

然后我继续收到此错误:

I then keep getting this error:



解析查询时出错。 [令牌行编号= 3,令牌行偏移量= 1,令牌错误= GO]

There was an error parsing the query. [ Token line number =3, Token line offset = 1, Token in error = GO ]


我正在使用的SQL CE库的版本为4.0.0.0版(运行时版本为v2.0.50727)。我正在使用Dapper 1.12.0.0(运行时版本为v4.0.30319)和Dapper Extensions 1.3.2.0(运行时版本为v4.0.30319)。

The version of the SQL CE library I'm using is version 4.0.0.0 (runtime version v2.0.50727). I'm using Dapper 1.12.0.0 (runtime version v4.0.30319) and Dapper Extensions 1.3.2.0 (runtime v4.0.30319).

SQL CE库似乎运行时错误,但是Web平台安装程序说我拥有最新版本(所以真的是最新版本?)。有想法吗?

The SQL CE library seems like the wrong run-time, but web platform installer says I have the latest (so that really is the latest?). Thoughts?

推荐答案

实际上,您只能使用SQL Server Compact每批执行一条语句,我所要做的(我是SQL Server Compact Toolbox作者),将每个GO和换行符分割成字符串。

You actually can only execute a single statement per batch with SQL Server Compact, all I do (I am the SQL Server Compact Toolbox author), is split the string per GO and newline.

我有这样的代码:

        using (StringReader reader = new StringReader(script))
        {
            string line;
            while ((line = reader.ReadLine()) != null)
            {
                line = line.Trim();
                if (line.Equals("GO", StringComparison.OrdinalIgnoreCase))
                {
                    RunCommand(sb.ToString(), dataset);
                    sb.Remove(0, sb.Length);
                }
                else
                {
                    sb.Append(line);
                    sb.Append(Environment.NewLine);
                }
            }
        }

这篇关于Sql CE与多个语句不一致的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆