using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Linq; using System.Text; using System.Windows.Forms; using System.Collections.Specialized; using System.Data.SqlClient; using Microsoft.SqlServer.Management.Smo; using Microsoft.SqlServer.Management.Common; using System.Reflection; using Microsoft.SqlServer.Management.Sdk.Sfc; using System.IO; namespace GenerateScript { public partial class Form1 : Form { public Form1() { InitializeComponent(); } private void btnGenerateScript_Click(object sender, EventArgs e) { var server = new Server(new ServerConnection { ConnectionString = new SqlConnectionStringBuilder { DataSource = @".\SQLEXPRESS", IntegratedSecurity = true }.ToString() }); server.ConnectionContext.Connect(); var database = server.Databases["ankit"]; var output = new StringBuilder(); foreach (Table table in database.Tables) { var scripter = new Scripter(server) { Options = { ScriptData = true } }; var script = scripter.EnumScript(new SqlSmoObject[] { table }); foreach (var line in script) output.AppendLine(" "+line); } File.WriteAllText(@"D:\ankit.sql", output.ToString()); MessageBox.Show("Script Created"); } } }
but i have a problem of this code, i want to generate script only current updated data or daywise script only, because my database size is too large. Please help me. Thanks in Advance. Ankit AgarwalSoftware Engineer