Exemple #1
0
        public void Ce4VersionChek()
        {
            var helper = new SqlCeHelper4();

            var result = helper.IsV40Installed();

            Assert.AreEqual(null, result);
        }
Exemple #2
0
        public void TestDataDirectory()
        {
            string test   = @"Data Source=|DataDirectory|\Chinook40.sdf";
            var    helper = new SqlCeHelper4();

            string path = helper.PathFromConnectionString(test);

            Assert.IsFalse(path.Contains("DataDirectory"));
        }
        internal static string ShowErrors(Exception ex)
        {
#if V35
            ISqlCeHelper sqlCeHelper = new SqlCeHelper();
#else
            ISqlCeHelper sqlCeHelper = new SqlCeHelper4();
#endif
            Telemetry.TrackException(ex);
            return(sqlCeHelper.FormatError(ex));
        }
        public void CheckCeVersion(object sender, ExecutedRoutedEventArgs e)
        {
#if V35
            var helper = new SqlCeHelper();
#else
            var helper = new SqlCeHelper4();
#endif

            OpenFileDialog ofd = new OpenFileDialog();
            ofd.Filter          = "SQL Server Compact Database (*.sdf)|*.sdf|All Files(*.*)|*.*";
            ofd.CheckFileExists = true;
            ofd.Multiselect     = false;
            ofd.ValidateNames   = true;
            if (ofd.ShowDialog() == true)
            {
                try
                {
                    var    sdfVersion = helper.DetermineVersion(ofd.FileName);
                    string found      = "Unknown";
                    switch (sdfVersion)
                    {
                    case SQLCEVersion.SQLCE20:
                        found = "2.0";
                        break;

                    case SQLCEVersion.SQLCE30:
                        found = "3.0/3.1";
                        break;

                    case SQLCEVersion.SQLCE35:
                        found = "3.5";
                        break;

                    case SQLCEVersion.SQLCE40:
                        found = "4.0";
                        break;

                    default:
                        break;
                    }
                    MessageBox.Show(string.Format("{0} is SQL Server Compact version {1}", Path.GetFileName(ofd.FileName), found), "SQL Server Compact Version Detect");
                }
                catch (Exception ex)
                {
                    MessageBox.Show(Helpers.DataConnectionHelper.ShowErrors(ex));
                }
            }
        }
Exemple #5
0
        private void Window_Loaded(object sender, RoutedEventArgs e)
        {
            var bw = new BackgroundWorker();

            bw.DoWork             += bw_DoWork;
            bw.RunWorkerCompleted += (s, ea) =>
            {
                Version.Text = "Version " + Assembly.GetExecutingAssembly().GetName().Version + " " + ea.Result.ToString();
            };
            bw.RunWorkerAsync();

            Background   = VsThemes.GetWindowBackground();
            Version.Text = "Version " + Assembly.GetExecutingAssembly().GetName().Version;

            txtStatus.Text = "SQL Server Compact 4.0 in GAC - ";
            try
            {
                var version = new SqlCeHelper4().IsV40Installed();
                if (version != null)
                {
                    txtStatus.Text += string.Format("Yes - {0}\n", version);
                }
                else
                {
                    txtStatus.Text += "No\n";
                }
            }
            catch
            {
                txtStatus.Text += "No\n";
            }

            txtStatus.Text += "SQL Server Compact 4.0 DbProvider - ";
            try
            {
                System.Data.Common.DbProviderFactories.GetFactory(SqlCeToolbox.Resources.SqlCompact40InvariantName);
                txtStatus.Text += "Yes\n";
            }
            catch
            {
                txtStatus.Text += "No\n";
            }

            txtStatus.Text += "SQL Server Compact 4.0 Simple DDEX provider - ";
            try
            {
                if (DataConnectionHelper.DdexProviderIsInstalled(new Guid(SqlCeToolbox.Resources.SqlCompact40PrivateProvider)))
                {
                    txtStatus.Text += "Yes\n";
                }
                else
                {
                    txtStatus.Text += "No\n";
                }
            }
            catch
            {
                txtStatus.Text += "No\n";
            }

            txtStatus.Text += "\n\nSQL Server Compact 3.5 in GAC - ";
            try
            {
                var version = new SqlCeHelper().IsV35Installed();
                if (version != null)
                {
                    txtStatus.Text += string.Format("Yes - {0}\n", version);
                }
                else
                {
                    txtStatus.Text += "No\n";
                }
            }
            catch
            {
                txtStatus.Text += "No\n";
            }

            txtStatus.Text += "SQL Server Compact 3.5 DbProvider - ";
            try
            {
                System.Data.Common.DbProviderFactories.GetFactory(SqlCeToolbox.Resources.SqlCompact35InvariantName);
                txtStatus.Text += "Yes\n";
            }
            catch
            {
                txtStatus.Text += "No\n";
            }

            txtStatus.Text += "\n\nSync Framework 2.1 SqlCe 3.5 provider - ";
            if (DataConnectionHelper.IsSyncFx21Installed())
            {
                txtStatus.Text += "Yes\n";
            }
            else
            {
                txtStatus.Text += "No\n";
            }

            txtStatus.Text += $"\n\nSQLite ADO.NET Provider used: {Helpers.RepositoryHelper.SqliteEngineVersion}\n";

            txtStatus.Text += "SQLite EF6 DbProvider in GAC - ";
            try
            {
                if (DataConnectionHelper.IsSqLiteDbProviderInstalled())
                {
                    txtStatus.Text += "Yes\n";
                }
                else
                {
                    txtStatus.Text += "No\n";
                }
            }
            catch
            {
                txtStatus.Text += "No\n";
            }

            txtStatus.Text += "System.Data.SQLite DDEX provider - ";
            try
            {
                if (DataConnectionHelper.DdexProviderIsInstalled(new Guid(SqlCeToolbox.Resources.SQLiteProvider)))
                {
                    txtStatus.Text += "Yes\n";
                }
                else
                {
                    txtStatus.Text += "No\n";
                }
            }
            catch
            {
                txtStatus.Text += "No\n";
            }

            txtStatus.Text += "SQLite Simple DDEX provider - ";
            try
            {
                if (DataConnectionHelper.DdexProviderIsInstalled(new Guid(SqlCeToolbox.Resources.SqlitePrivateProvider)))
                {
                    txtStatus.Text += "Yes\n";
                }
                else
                {
                    txtStatus.Text += "No\n";
                }
            }
            catch
            {
                txtStatus.Text += "No\n";
            }
        }
        public void UpgradeTo40(object sender, ExecutedRoutedEventArgs e)
        {
            if (EnvDteHelper.ShowMessageBox("This will upgrade the 3.5 database to 4.0 format, and leave a renamed backup of the 3.5 database. Do you wish to proceed?",
                                            OLEMSGBUTTON.OLEMSGBUTTON_YESNO, OLEMSGDEFBUTTON.OLEMSGDEFBUTTON_SECOND, OLEMSGICON.OLEMSGICON_QUERY) == System.Windows.Forms.DialogResult.No)
            {
                return;
            }

            if (!Helpers.RepositoryHelper.IsV40Installed())
            {
                EnvDteHelper.ShowError("The SQL Server Compact 4.0 runtime is not installed, cannot upgrade. Install the 4.0 runtime.");
                return;
            }
            try
            {
                var databaseInfo = ValidateMenuInfo(sender);
                if (databaseInfo == null)
                {
                    return;
                }

                var helper = new SqlCeHelper4();
                var path   = helper.PathFromConnectionString(databaseInfo.DatabaseInfo.ConnectionString);

                if (!File.Exists(path))
                {
                    EnvDteHelper.ShowError(string.Format("Database file in path: {0} could not be found", path));
                    return;
                }
                var path1 = Path.GetDirectoryName(path);
                if (path1 != null)
                {
                    var newFile = Path.Combine(path1, Path.GetFileNameWithoutExtension(path) + "_35" + Path.GetExtension(path));
                    if (File.Exists(newFile))
                    {
                        for (var i = 0; i < 100; i++)
                        {
                            newFile = Path.Combine(path1, Path.GetFileNameWithoutExtension(newFile) + "_" + i.ToString() + "." + Path.GetExtension(newFile));
                            if (!File.Exists(newFile))
                            {
                                break;
                            }
                        }
                    }

                    if (File.Exists(newFile))
                    {
                        EnvDteHelper.ShowError("Could not create unique file name...");
                        return;
                    }
                    File.Copy(path, newFile);
                    helper.UpgradeTo40(databaseInfo.DatabaseInfo.ConnectionString);
                    EnvDteHelper.ShowMessage(string.Format("Database upgraded, version 3.5 database backed up to: {0}", newFile));
                }
                if (databaseInfo.DatabaseInfo.FromServerExplorer)
                {
                    DataConnectionHelper.RemoveDataConnection(package, databaseInfo.DatabaseInfo.ConnectionString, new Guid(Resources.SqlCompact35Provider));
                }
                else
                {
                    DataConnectionHelper.RemoveDataConnection(databaseInfo.DatabaseInfo.ConnectionString);
                }
                DataConnectionHelper.SaveDataConnection(databaseInfo.DatabaseInfo.ConnectionString, DatabaseType.SQLCE40, package);
                var control = _parentWindow.Content as ExplorerControl;
                if (control != null)
                {
                    control.BuildDatabaseTree();
                }
                DataConnectionHelper.LogUsage("DatabaseUpgrade40");
            }
            catch (Exception ex)
            {
                DataConnectionHelper.SendError(ex, DatabaseType.SQLCE35);
            }
        }
        private void ExportServerDatabaseToEmbedded(DatabaseType databaseType, DatabaseMenuCommandParameters parameters)
        {
            var filter = DataConnectionHelper.GetSqlCeFileFilter();
            var scope  = Scope.SchemaData;

            if (databaseType == DatabaseType.SQLite)
            {
                filter = DataConnectionHelper.GetSqliteFileFilter();
                scope  = Scope.SchemaDataSQLite;
            }
            Debug.Assert(databaseType == DatabaseType.SQLite || databaseType == DatabaseType.SQLCE40, "Unexpected database type");
            try
            {
                var connectionString = parameters.DatabaseInfo != null
                    ? parameters.DatabaseInfo.ConnectionString :
                                       DataConnectionHelper.PromptForConnectionString(_package);
                if (!string.IsNullOrEmpty(connectionString))
                {
                    var ptd = new PickTablesDialog();
                    int totalCount;
                    using (var repository = DataConnectionHelper.CreateRepository(new DatabaseInfo
                    {
                        ConnectionString = connectionString, DatabaseType = DatabaseType.SQLServer
                    }))
                    {
                        ptd.Tables = repository.GetAllTableNamesForExclusion();
                        totalCount = ptd.Tables.Count;
                    }

                    var res = ptd.ShowModal();
                    if (!res.HasValue || res.Value != true || (ptd.Tables.Count >= totalCount))
                    {
                        return;
                    }
                    string dbConnectionString = null;
                    var    fd = new SaveFileDialog
                    {
                        Title           = "Export as",
                        Filter          = filter,
                        OverwritePrompt = true,
                        ValidateNames   = true
                    };
                    var result = fd.ShowDialog();
                    if (!result.HasValue || result.Value != true)
                    {
                        return;
                    }
                    var dbName = fd.FileName;
                    try
                    {
                        if (databaseType == DatabaseType.SQLCE40)
                        {
                            _package.SetStatus("Creating SQL Server Compact database...");
                            var helper = new SqlCeHelper4();
                            dbConnectionString = string.Format("Data Source={0};Max Database Size=4091", dbName);
                            if (File.Exists(dbName))
                            {
                                File.Delete(dbName);
                            }
                            helper.CreateDatabase(dbConnectionString);
                        }
                        if (databaseType == DatabaseType.SQLite)
                        {
                            _package.SetStatus("Creating SQLite database...");
                            var helper = new SqliteHelper();
                            dbConnectionString = string.Format("Data Source={0};", dbName);
                            if (File.Exists(dbName))
                            {
                                File.Delete(dbName);
                            }
                            helper.CreateDatabase(dbConnectionString);
                        }

                        var bw = new BackgroundWorker();
                        var workerParameters = new List <object>
                        {
                            dbConnectionString,
                            connectionString,
                            ptd.Tables,
                            databaseType.ToString(),
                            scope.ToString()
                        };

                        bw.DoWork             += bw_DoWork;
                        bw.RunWorkerCompleted += (s, ea) =>
                        {
                            try
                            {
                                if (ea.Error != null)
                                {
                                    DataConnectionHelper.SendError(ea.Error, databaseType, false);
                                }
                                DataConnectionHelper.LogUsage("DatabasesExportFromServer");
                            }
                            finally
                            {
                                bw.Dispose();
                            }
                        };
                        bw.RunWorkerAsync(workerParameters);
                    }
                    catch (Exception ex)
                    {
                        DataConnectionHelper.SendError(ex, databaseType, false);
                    }
                }
            }
            catch (Exception ex)
            {
                DataConnectionHelper.SendError(ex, DatabaseType.SQLServer);
            }
        }
Exemple #8
0
        public void TestDataDirectory()
        {
            string test = @"Data Source=|DataDirectory|\Chinook40.sdf";
            var helper = new SqlCeHelper4();

            string path = helper.PathFromConnectionString(test);
            Assert.IsFalse(path.Contains("DataDirectory"));
        }
        private void Window_Loaded(object sender, RoutedEventArgs e)
        {
            Background   = VsThemes.GetWindowBackground();
            Version.Text = "Version " + Assembly.GetExecutingAssembly().GetName().Version;

            txtStatus.Text = "SQL Server Compact 4.0 in GAC - ";
            try
            {
                var version = new SqlCeHelper4().IsV40Installed();
                if (version != null)
                {
                    txtStatus.Text += string.Format("Yes - {0}\n", version);
                }
                else
                {
                    txtStatus.Text += "No\n";
                }
            }
            catch
            {
                txtStatus.Text += "No\n";
            }

            txtStatus.Text += "SQL Server Compact 4.0 DbProvider - ";
            try
            {
                System.Data.Common.DbProviderFactories.GetFactory(EFCorePowerTools.Resources.SqlCompact40InvariantName);
                txtStatus.Text += "Yes\n";
            }
            catch
            {
                txtStatus.Text += "No\n";
            }

            txtStatus.Text += "\nSQL Server Compact 4.0 DDEX provider - ";
            try
            {
                if (EnvDteHelper.DdexProviderIsInstalled(new Guid(EFCorePowerTools.Resources.SqlCompact40Provider)))
                {
                    txtStatus.Text += "Yes\n";
                }
                else
                {
                    txtStatus.Text += "No\n";
                }
            }
            catch
            {
                txtStatus.Text += "No\n";
            }

            txtStatus.Text += "SQL Server Compact 4.0 Simple DDEX provider - ";
            try
            {
                if (EnvDteHelper.DdexProviderIsInstalled(new Guid(EFCorePowerTools.Resources.SqlCompact40PrivateProvider)))
                {
                    txtStatus.Text += "Yes\n";
                }
                else
                {
                    txtStatus.Text += "No\n";
                }
            }
            catch
            {
                txtStatus.Text += "No\n";
            }

            txtStatus.Text += "\n\nSQLite ADO.NET Provider included: ";
            try
            {
                Assembly asm = Assembly.Load("System.Data.SQLite");
                txtStatus.Text += string.Format("{0}\n", asm.GetName().Version);
            }
            catch
            {
                txtStatus.Text += "No\n";
            }

            txtStatus.Text += "SQLite EF6 DbProvider in GAC - ";
            try
            {
                if (EnvDteHelper.IsSqLiteDbProviderInstalled())
                {
                    txtStatus.Text += "Yes\n";
                }
                else
                {
                    txtStatus.Text += "No\n";
                }
            }
            catch
            {
                txtStatus.Text += "No\n";
            }

            txtStatus.Text += "\nSystem.Data.SQLite DDEX provider - ";
            try
            {
                if (EnvDteHelper.DdexProviderIsInstalled(new Guid(EFCorePowerTools.Resources.SQLiteProvider)))
                {
                    txtStatus.Text += "Yes\n";
                }
                else
                {
                    txtStatus.Text += "No\n";
                }
            }
            catch
            {
                txtStatus.Text += "No\n";
            }

            txtStatus.Text += "SQLite Simple DDEX provider - ";
            try
            {
                if (EnvDteHelper.DdexProviderIsInstalled(new Guid(EFCorePowerTools.Resources.SqlitePrivateProvider)))
                {
                    txtStatus.Text += "Yes\n";
                }
                else
                {
                    txtStatus.Text += "No\n";
                }
            }
            catch
            {
                txtStatus.Text += "No\n";
            }
        }
        internal static string ShowErrors(Exception ex)
        {
#if V35
            ISqlCeHelper sqlCeHelper = new SqlCeHelper();
#else
            ISqlCeHelper sqlCeHelper = new SqlCeHelper4();
#endif
            Monitor.TrackException(ex);
            return sqlCeHelper.FormatError(ex);
        }