Quantcast
Channel: CSharp Forum Latest Questions
Viewing all articles
Browse latest Browse all 32170

How to generate sql database script according to date?

$
0
0
Hello,
 
I am using this code for generate script:
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
{publicpartialclass Form1 : Form
    {public Form1()
        {
            InitializeComponent();
        } privatevoid 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

Viewing all articles
Browse latest Browse all 32170

Trending Articles