Beispiel #1
0
 public void TestServerDgml()
 {
     using (IRepository sourceRepository = new  ServerDBRepository4(serverConnectionString))
     {
         var generator = new Generator4(sourceRepository, @"C:\temp\test2.dgml");
         generator.GenerateSchemaGraph(serverConnectionString);
     }
 }
Beispiel #2
0
 public void TestGraphSortServer()
 {
     using (IRepository sourceRepository = new ServerDBRepository4(serverConnectionString))
     {
         var generator = new Generator4(sourceRepository, @"C:\temp\testAMS40.sqlce");
         generator.ExcludeTables(new System.Collections.Generic.List <String>());
     }
 }
Beispiel #3
0
 public void TestServerDgml()
 {
     using (IRepository sourceRepository = new  ServerDBRepository4(serverConnectionString))
     {
         var generator = new Generator4(sourceRepository, @"C:\temp\test2.dgml");
         generator.GenerateSchemaGraph(serverConnectionString);
     }
 }
Beispiel #4
0
        private void RunMigration(string localDbPath, string[] tablesToIgnoreOrAppend, string targetConnectionString, Scope scope, bool removeTempFiles)
        {
            using (var repository = new DB4Repository($"Data Source={localDbPath};Max Database Size=4000"))
            {
                var scriptRoot = Path.GetTempFileName();
                var tempScript = scriptRoot + ".sqltb";
                var generator  = new Generator4(repository, tempScript);

                if (scope == Scope.DataOnlyForSqlServerIgnoreIdentity)
                {
                    //Ignore all tables except the ones in tablesToAppend
                    var tables = repository.GetAllTableNames();
                    var list   = tables.Except(tablesToIgnoreOrAppend.ToList());
                    generator.ExcludeTables(list.ToList());
                }
                else
                {
                    generator.ExcludeTables(tablesToIgnoreOrAppend.ToList());
                }

                generator.ScriptDatabaseToFile(scope);
                using (var serverRepository = new ServerDBRepository4(targetConnectionString))
                {
                    try
                    {
                        //Handles large exports also...
                        if (File.Exists(tempScript)) // Single file
                        {
                            serverRepository.ExecuteSqlFile(tempScript);
                            if (removeTempFiles)
                            {
                                TryDeleteFile(tempScript);
                            }
                        }
                        else // possibly multiple files - tmp2BB9.tmp_0.sqlce
                        {
                            for (var i = 0; i < 400; i++)
                            {
                                var testFile = string.Format("{0}_{1}{2}", scriptRoot, i.ToString("D4"), ".sqltb");
                                if (File.Exists(testFile))
                                {
                                    serverRepository.ExecuteSqlFile(testFile);
                                    if (removeTempFiles)
                                    {
                                        TryDeleteFile(testFile);
                                    }
                                }
                            }
                        }
                    }
                    catch (Exception ex)
                    {
                        CreateBlockFile(localDbPath, ex);
                        throw;
                    }
                }
            }
        }
Beispiel #5
0
 public void TestServerExportDotInTable()
 {
     string path = @"C:\temp\API2012.sqlce";
     using (IRepository sourceRepository = new ServerDBRepository4(serverApiTestConnectionString))
     {
         var generator = new Generator4(sourceRepository, path);
         generator.ExcludeTables(new List<string>());
     }
 }
Beispiel #6
0
 public void TestServerExportConstrainsIssue()
 {
     string path = @"C:\temp\Baseball.sqlce";
     using (IRepository sourceRepository = new ServerDBRepository4(BaseballTestConnectionString))
     {
         var generator = new Generator4(sourceRepository, path);
         generator.ExcludeTables(new List<string>());
     }
 }
Beispiel #7
0
 public void TestServerTableGenWithGeography()
 {
     using (IRepository sourceRepository = new ServerDBRepository4(@"Data Source=.\SQL2016DEV;Initial Catalog=AW2014Geo;Integrated Security=true;"))
     {
         var generator = new Generator4(sourceRepository);
         generator.GenerateTableCreate("Address");
         var script = generator.GeneratedScript;
     }
 }
Beispiel #8
0
 public void TestServerExport()
 {
     string path = @"C:\temp\testAW2012.sqlce";
     using (IRepository sourceRepository = new ServerDBRepository4(serverAWConnectionString))
     {
         var generator = new Generator4(sourceRepository, path);
         generator.ScriptDatabaseToFile(Scope.SchemaData);
     }
 }
Beispiel #9
0
        public void TestServerExport()
        {
            string path = @"C:\temp\testAW2012.sqlce";

            using (IRepository sourceRepository = new ServerDBRepository4(serverAWConnectionString))
            {
                var generator = new Generator4(sourceRepository, path);
                generator.ScriptDatabaseToFile(Scope.SchemaData);
            }
        }
Beispiel #10
0
        public void TestServerExportDotInTable()
        {
            string path = @"C:\temp\API2012.sqlce";

            using (IRepository sourceRepository = new ServerDBRepository4(serverApiTestConnectionString))
            {
                var generator = new Generator4(sourceRepository, path);
                generator.ExcludeTables(new List <string>());
            }
        }
Beispiel #11
0
 public void TestServerHierarchyIdSqlCe()
 {
     using (IRepository sourceRepository = new ServerDBRepository4(serverHIDConnectionString))
     {
         var exclusions = new List <string>();
         var generator  = new Generator4(sourceRepository, @"C:\code\test2.sql");
         generator.ExcludeTables(exclusions);
         generator.ScriptDatabaseToFile(Scope.SchemaData);
     }
 }
Beispiel #12
0
        public void TestServerExportConstrainsIssue()
        {
            string path = @"C:\temp\Baseball.sqlce";

            using (IRepository sourceRepository = new ServerDBRepository4(BaseballTestConnectionString))
            {
                var generator = new Generator4(sourceRepository, path);
                generator.ExcludeTables(new List <string>());
            }
        }
Beispiel #13
0
 public void TestServerDgml()
 {
     using (IRepository sourceRepository = new ServerDBRepository4(serverAWConnectionString, true))
     {
         var exclusions = new List <string>();
         exclusions.Add("dbo.BuildVersion");
         exclusions.Add("dbo.ErrorLog");
         var generator = new Generator4(sourceRepository, @"C:\temp\test2.dgml", false, false, false);
         generator.GenerateSchemaGraph(serverConnectionString, exclusions);
     }
 }
Beispiel #14
0
 public void ExerciseEngineWithTable()
 {
     using (IRepository sourceRepository = new DB4Repository(sdfConnectionString))
     {
         var generator = new Generator4(sourceRepository);
         using (IRepository targetRepository = new ServerDBRepository4(serverConnectionString))
         {
             SqlCeDiff.CreateDiffScript(sourceRepository, targetRepository, generator, false);
         }
     }
 }
Beispiel #15
0
        public void TestServerExportToSqlite()
        {
            var path = @"C:\temp\testAW2012.sql";

            using (var sourceRepository = new ServerDBRepository4(serverDefConnectionString, true))
            {
                var generator = new Generator4(sourceRepository, path, false, false, true);
                generator.ExcludeTables(new List <string>());
                generator.ScriptDatabaseToFile(Scope.SchemaDataSQLite);
            }
        }
Beispiel #16
0
        public void ExerciseEngineWithTable()
        {
            using (IRepository sourceRepository = new DB4Repository(sdfConnectionString))
            {
                var generator = new Generator4(sourceRepository);
                using (IRepository targetRepository = new ServerDBRepository4(serverConnectionString))
                {
                    SqlCeDiff.CreateDiffScript(sourceRepository, targetRepository, generator, false);
                }

            }
        }
Beispiel #17
0
        public void TestServerExportUniqueIssue()
        {
            string path = @"C:\temp\E2E.sqlce";

            using (IRepository sourceRepository = new ServerDBRepository4(E2EConnectionString))
            {
                var generator = new Generator4(sourceRepository, path);
                generator.ExcludeTables(new List <string>());
                generator.GenerateTableScript("OneToOneSeparateFKDependent");
                var test = generator.GeneratedScript;
            }
        }
Beispiel #18
0
 public void TestServerMigration()
 {
     string path = @"C:\temp\testChinook40.sqlce";
     using (IRepository sourceRepository = new DB4Repository(chinookConnectionString))
     {
         var generator = new Generator4(sourceRepository, path);
         generator.GenerateAllAndSave(true, false, false, false);
     }
     Assert.IsTrue(System.IO.File.Exists(path));
     using (IRepository serverRepository = new ServerDBRepository4(migrateConnectionString))
     {
         serverRepository.ExecuteSqlFile(path);
     }
 }
Beispiel #19
0
        public void TestServerMigration()
        {
            string path = @"C:\temp\testChinook40.sqlce";

            using (IRepository sourceRepository = new DB4Repository(chinookConnectionString))
            {
                var generator = new Generator4(sourceRepository, path);
                generator.GenerateAllAndSave(true, false, false, false);
            }
            Assert.IsTrue(System.IO.File.Exists(path));
            using (IRepository serverRepository = new ServerDBRepository4(migrateConnectionString))
            {
                serverRepository.ExecuteSqlFile(path);
            }
        }
Beispiel #20
0
        private void AssertMsSqlToSqliteGeneratorContains(string createTableQuery, string tableName, string expectedSql)
        {
            // connect to database server
            string connectionString = @"Data Source=.\sqlexpress;Integrated Security=SSPI;";

            // create a new random database name
            string databaseName = this.RandomString(10);

            using (SqlConnection sqlConnection = new SqlConnection(connectionString))
            {
                sqlConnection.Open();

                while (sqlConnection.DatabaseExists(databaseName))
                {
                    // create a new random database name
                    databaseName = this.RandomString(10);
                }

                using (TempDatabase tempDatabase = new TempDatabase(sqlConnection, databaseName))
                {
                    using (SqlConnection tempSqlConnection = new SqlConnection(tempDatabase.ConnectionString))
                    {
                        tempSqlConnection.Open();

                        tempSqlConnection.Execute(createTableQuery);
                    }

                    string sql = null;

                    using (var repository = new ServerDBRepository4(tempDatabase.ConnectionString, false))
                    {
                        Generator4 generator = new Generator4(
                            repository,
                            null,
                            false,
                            false,
                            true);
                        generator.GenerateTableScript(tableName);
                        sql = generator.GeneratedScript;
                    }

                    Assert.IsTrue(sql.Contains(expectedSql), sql);
                }
            }
        }
        public void GenerateServerDgmlFiles(object sender, ExecutedRoutedEventArgs e)
        {
            // http://www.mztools.com/articles/2007/MZ2007011.aspx
            var menuItem = sender as MenuItem;

            if (menuItem == null)
            {
                return;
            }

            var databaseInfo = menuItem.CommandParameter as DatabasesMenuCommandParameters;

            if (databaseInfo == null)
            {
                return;
            }
            var  treeViewItem  = databaseInfo.DatabasesTreeViewItem;
            bool originalValue = Properties.Settings.Default.KeepServerSchemaNames;

            try
            {
                DataSource sqlDataSource = new DataSource("MicrosoftSqlServer", "Microsoft SQL Server");
                sqlDataSource.Providers.Add(DataProvider.SqlDataProvider);
                DataConnectionDialog dcd = new DataConnectionDialog();
                dcd.DataSources.Add(sqlDataSource);
                dcd.SelectedDataProvider = DataProvider.SqlDataProvider;
                dcd.SelectedDataSource   = sqlDataSource;
                if (DataConnectionDialog.Show(dcd) == System.Windows.Forms.DialogResult.OK)
                {
                    string connectionString = dcd.ConnectionString;
                    string fileName;

                    PickTablesDialog ptd = new PickTablesDialog();
                    int totalCount       = 0;
                    using (IRepository repository = RepoHelper.CreateServerRepository(dcd.ConnectionString))
                    {
                        ptd.Tables = repository.GetAllTableNamesForExclusion();
                        totalCount = ptd.Tables.Count;
                    }
                    ptd.Owner = Application.Current.MainWindow;
                    bool?res = ptd.ShowDialog();
                    if (res.HasValue && res.Value == true && (ptd.Tables.Count < totalCount))
                    {
                        SaveFileDialog fd = new SaveFileDialog();
                        fd.Title           = "Save generated DGML file as";
                        fd.Filter          = "DGML (*.dgml)|*.dgml";
                        fd.OverwritePrompt = true;
                        fd.ValidateNames   = true;
                        bool?result = fd.ShowDialog();
                        if (result.HasValue && result.Value == true)
                        {
                            Properties.Settings.Default.KeepServerSchemaNames = true;
                            fileName = fd.FileName;
#if V35
                            using (IRepository repository = new ServerDBRepository(connectionString, Properties.Settings.Default.KeepServerSchemaNames))
#else
                            using (IRepository repository = new ServerDBRepository4(connectionString, Properties.Settings.Default.KeepServerSchemaNames))
#endif
                            {
                                var generator = RepoHelper.CreateGenerator(repository, fileName);
                                generator.GenerateSchemaGraph(connectionString, ptd.Tables);
                                MessageBox.Show(string.Format("Saved {0}", fileName));
                            }
                        }
                    }
                    dcd.Dispose();
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(Helpers.DataConnectionHelper.ShowErrors(ex));
            }
            finally
            {
                Properties.Settings.Default.KeepServerSchemaNames = originalValue;
            }
        }
Beispiel #22
0
 public void TestServerDgml()
 {
     using (IRepository sourceRepository = new  ServerDBRepository4(serverConnectionString))
     {
         var exclusions = new List<string>();
         exclusions.Add("dbo.BuildVersion");
         exclusions.Add("dbo.ErrorLog");
         var generator = new Generator4(sourceRepository, @"C:\temp\test2.dgml");
         generator.GenerateSchemaGraph(serverConnectionString, exclusions);
     }
 }
Beispiel #23
0
 public void TestServerHierarchyIdSqlCe()
 {
     using (IRepository sourceRepository = new ServerDBRepository4(serverHIDConnectionString))
     {
         var exclusions = new List<string>();
         var generator = new Generator4(sourceRepository, @"C:\code\test2.sql");
         generator.ExcludeTables(exclusions);
         generator.ScriptDatabaseToFile(Scope.SchemaData);
     }
 }
Beispiel #24
0
 public void TestServerExportUniqueIssue()
 {
     string path = @"C:\temp\E2E.sqlce";
     using (IRepository sourceRepository = new ServerDBRepository4(E2EConnectionString))
     {
         var generator = new Generator4(sourceRepository, path);
         generator.ExcludeTables(new List<string>());
         generator.GenerateTableScript("OneToOneSeparateFKDependent");
         var test = generator.GeneratedScript;
     }
 }
Beispiel #25
0
 public void TestGraphSortServer()
 {
     using (IRepository sourceRepository = new ServerDBRepository4(serverConnectionString))
     {
         var generator = new Generator4(sourceRepository, @"C:\temp\testAMS40.sqlce");
         generator.ExcludeTables(new System.Collections.Generic.List<String>());
     }
 }