示例#1
0
        static void Main(string[] args)
        {
            var options = new Options();

            if (CommandLine.Parser.Default.ParseArguments(args, options))
            {
                var builder = new SqlConnectionStringBuilder();
                try
                {
                    builder = new SqlConnectionStringBuilder(options.SourceConnectionString);
                }
                catch
                {
                    Console.WriteLine("Please verify that the connection string is in correct format, also please encapsulate it with qoutes");
                }
                Server myServer = new Server(builder.DataSource);
                myServer.ConnectionContext.LoginSecure = true;
                myServer.ConnectionContext.Connect();
                var tableStructureExtractor = new TableStructureExtractor();
                var dataExtractor           = new DataExtractor(options.SourceConnectionString);


                Database sourceDatabase = null;

                List <Table> tables = new List <Table>();
                foreach (Database myDatabase in myServer.Databases)
                {
                    if (myDatabase.Name != builder.InitialCatalog)
                    {
                        continue;
                    }
                    sourceDatabase = myDatabase;
                }
                if (sourceDatabase == null)
                {
                    Console.WriteLine(String.Format("Database {0} not found on server:{1}", builder.InitialCatalog, builder.DataSource));
                    return;
                }

                tableStructureExtractor.CreateFileWithCreateStatements(sourceDatabase, options.Path);
                dataExtractor.CreateDBInserts(options.SourceConnectionString, sourceDatabase, options.Path);
            }
        }
示例#2
0
        static void Main(string[] args)
        {
            var options = new Options();
            if (CommandLine.Parser.Default.ParseArguments(args, options))
            {
                var builder = new SqlConnectionStringBuilder();
                try
                {
                    builder = new SqlConnectionStringBuilder(options.SourceConnectionString);

                }
                catch
                {
                    Console.WriteLine("Please verify that the connection string is in correct format, also please encapsulate it with qoutes");
                }
                Server myServer = new Server(builder.DataSource);
                myServer.ConnectionContext.LoginSecure = true;
                myServer.ConnectionContext.Connect();
                var tableStructureExtractor = new TableStructureExtractor();
                var dataExtractor = new DataExtractor(options.SourceConnectionString);

                Database sourceDatabase = null;

                List<Table> tables = new List<Table>();
                foreach (Database myDatabase in myServer.Databases)
                {
                    if (myDatabase.Name != builder.InitialCatalog)
                        continue;
                    sourceDatabase = myDatabase;
                }
                if (sourceDatabase == null)
                {
                    Console.WriteLine(String.Format("Database {0} not found on server:{1}", builder.InitialCatalog, builder.DataSource));
                    return;
                }

                tableStructureExtractor.CreateFileWithCreateStatements(sourceDatabase, options.Path);
                dataExtractor.CreateDBInserts(options.SourceConnectionString, sourceDatabase, options.Path);
            }
        }