生成脚本插入.net

发布于 2024-09-27 22:07:40 字数 913 浏览 0 评论 0原文

我在尝试生成具有特定条件的脚本插入时遇到问题。

到目前为止我已经在尝试这一步了。

  1. 添加引用 Microsoft.SqlServer.ConnectionInfo 和 Microsoft.SqlServer.Smo

  2. 在代码中添加引用 Microsoft.SqlServer.Management.Smo

    >
  3. 将此添加到脚本中。

     var srv = new Server(@"localhost\SQLEXPRESS");
      var db = srv.Databases["Northwind"];
      foreach(db.Tables 中的 Microsoft.SqlServer.Management.Smo.Table 选项卡)
      {
          foreach(tab.Script() 中的字符串)
          {
              File.AppendAllText("sql_insert_conditioanl.sql", s);
          }
      }
    

脚本“sql_insert_conditioanl.sql”仅包含创建数据库并创建数据库“Northwind”中存在的表。

所以我对这个问题进行研究。尝试将不带参数的方法“脚本”更改为参数“ScriptingOptions”参考 链接。我仍然对使用参数脚本选项感到困惑。

然后还尝试使用受保护的方法。但由于它受到保护,我无法测试方法(例如:方法“ScriptAlter”)。

看待

I have problem when trying generate script insert with specific condition.

So far I am already trying this step.

  1. Add references Microsoft.SqlServer.ConnectionInfo and Microsoft.SqlServer.Smo

  2. Add reference in code Microsoft.SqlServer.Management.Smo

  3. Add this to script.

      var srv = new Server(@"localhost\SQLEXPRESS");
      var db = srv.Databases["Northwind"];
      foreach (Microsoft.SqlServer.Management.Smo.Table tab in db.Tables)
      {
          foreach (string s in tab.Script())
          {
              File.AppendAllText("sql_insert_conditioanl.sql", s);
          }
      }
    

Script "sql_insert_conditioanl.sql" contain only to create database and create table that exist in database "Northwind".

So I do research about this problem. Trying change method "Script" without parameter to parameter "ScriptingOptions" ref link. I still confuse to using parameter Scripting Options.

Then also trying using protected method. But since it protected, I can't test method (like: Method "ScriptAlter").

Regard

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

↘人皮目录ツ 2024-10-04 22:07:40

您需要为所有数据库对象生成脚本 - 例如索引、存储过程、视图等。请参阅此 文章(及其相关文章)入门。

You need to generate scripts for all database objects - for example indices, stored procedures, views etc. See this article (and its related articles) for getting started.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文