Click here to Skip to main content
15,905,144 members
Please Sign up or sign in to vote.
5.00/5 (1 vote)
See more:
Hello,

I am using this code for generate script:

C#
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 Agarwal
Software Engineer
Posted
Updated 26-Nov-13 20:42pm
v2
Comments
Maciej Los 28-Nov-13 16:33pm    
Not sure what you want to achieve...
Please, be more specific and provide more details. How do you want to recognize which data have been modified and which have been inserted?
Maciej Los 28-Nov-13 16:34pm    
By The Way: upvoted (5 stars)

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900