你如何解析大的SQL脚本分批? [英] How do you parse large SQL scripts into batches?

查看:222
本文介绍了你如何解析大的SQL脚本分批?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有我要分手成执行批量非常大的SQL文件。 我想确保我解析它以同样的方式SSMS和SQLCMD做。

I have a very large sql file I want to break up into batches for execution. I want to make sure I'm parsing it the same way that SSMS and SQLCMD do.

微软有一个名为Microsoft.SqlServer.BatchParser一类名为解析器,接缝像它会做的伎俩一个伟大的混合模式组件。

Microsoft has a great mixed mode assembly named Microsoft.SqlServer.BatchParser with a class named Parser that seams like it would do the trick.

它想IBatchSource作为一个参数实现调用解析()之前SetBatchSource。

It wants an implementation of IBatchSource as an argument to SetBatchSource before calling Parse().

我在哪里可以找到如何使用这个功能的实现IBatchSource,更多的信息?

Where can I find an implementation of IBatchSource, and more information on how to make use of this functionality?

推荐答案

我发现在GAC大会Microsoft.SqlServer.BatchParser连同它包含的实现朋友Microsoft.SqlServer.BatchParserClient接口IBatchSource。

I found the assembly Microsoft.SqlServer.BatchParser in the GAC along with it's friend Microsoft.SqlServer.BatchParserClient that contains implementations the interface IBatchSource.

namespace Microsoft.SqlServer.Management.Common
{
  internal class BatchSourceFile : IBatchSource
  internal class BatchSourceString : IBatchSource
}

下面的谈话,然后发生了。

The following conversation then occurred.

大会:的啰!我的名字是    Microsoft.SqlServer.Management.Common.ExecuteBatch 。你想StringCollection GetStatements(字符串的SqlCommand)?

Assembly: Hello! My name is Microsoft.SqlServer.Management.Common.ExecuteBatch. Would you like to StringCollection GetStatements(string sqlCommand)?

我:的是,我会的,BatchParserClient组装。谢谢你的邀请!

Me: Yes, I would, BatchParserClient assembly. Thanks for asking!

重复说明(不要在家里尝试这个!)

Repeatable Instructions (Do try this at home!)

  • 在安装的Microsoft SQL Server 2008 R2共享管理对象
  • 复制Microsoft.SqlServer.BatchParser.dll和Microsoft.SqlServer.BatchParserClient.dll从GAC到解决方案中的一个文件夹。
  • 参考Microsoft.SqlServer.BatchParser和放大器; Microsoft.SqlServer.BatchParserClient

的Program.cs

using System;
using System.Collections.Specialized;
using System.IO;
using System.Text;
using Microsoft.SqlServer.Management.Common;

namespace ScriptParser
{
   class Program
   {
      static void Main(string[] args)
      {
         ExecuteBatch batcher = new ExecuteBatch();
         string text = File.ReadAllText(@"Path_To_My_Long_Sql_File.sql");
         StringCollection statements = batcher.GetStatements(text);
         foreach (string statement in statements)
         {
            Console.WriteLine(statement);
         }
      }
   }
}

的app.config

<?xml version="1.0"?>
<configuration>
   <startup useLegacyV2RuntimeActivationPolicy="true">
      <supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.5"/>
   </startup>
</configuration>

这篇关于你如何解析大的SQL脚本分批?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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