views:

27

answers:

1

Hi all,

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

A: 

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.

VinayC