/// <summary> /// Set up the SQL connections for the table adapters when creating/opening /// a database. /// </summary> private void CreateConnections() { localDB = new DPDatabaseImportV1(); localTAManager = new DPDatabaseImportV1TableAdapters.TableAdapterManager(); localTAManager.ChatLogTableAdapter = new DPDatabaseImportV1TableAdapters.ChatLogTableAdapter(); // DVS/DirectParse uses SQLCE 3.1, so we can always do an upgrade here. System.Data.SqlServerCe.SqlCeEngine sqlCeEngine = new System.Data.SqlServerCe.SqlCeEngine(databaseConnectionString); // Creates a 0-byte file. We need the name, but don't want the file to exist. tempDatabaseName = Path.GetTempFileName(); File.Delete(tempDatabaseName); string tempConnectionString = string.Format("Data Source={0}", tempDatabaseName); sqlCeEngine.Upgrade(tempConnectionString); Properties.Settings.Default.Properties["DvsParse_SaveConnectionString"].DefaultValue = tempConnectionString; System.Data.SqlServerCe.SqlCeConnection sqlConn = new System.Data.SqlServerCe.SqlCeConnection(tempConnectionString); localTAManager.Connection = sqlConn; localTAManager.ChatLogTableAdapter.Connection = sqlConn; localTAManager.ChatLogTableAdapter.Fill(localDB.ChatLog); }
private static void Spike_SqlServerCe_Upgrade_To_Current(string[] args) { var e = new System.Data.SqlServerCe.SqlCeEngine(Nespe.Data.Context.NespeDataContext.ConnectionString); e.Upgrade(); }
protected override void OnStartup(StartupEventArgs e) { var key = Microsoft.Win32.Registry.LocalMachine.OpenSubKey(@"SOFTWARE\Microsoft\Microsoft SQL Server Compact Edition\v4.0", false); if (key == null) // || Util.Parse<int>(key.GetValue("ServicePackLevel")) < 2) { throw new Exception(Labels.AppRequiresSql); } key = Microsoft.Win32.Registry.LocalMachine.OpenSubKey(@"SOFTWARE\Microsoft\Office"); bool found = false; if (key != null) { string[] versions = key.GetSubKeyNames().Where(v => Util.Parse <double>(v) >= 10).ToArray(); foreach (string v in versions) { key = Microsoft.Win32.Registry.LocalMachine.OpenSubKey(@"SOFTWARE\Microsoft\Office\" + v + @"\PowerPoint\InstallRoot", false); if (key != null && !String.IsNullOrEmpty(key.GetValue("Path") as string)) { found = true; } } } if (!found) { key = Microsoft.Win32.Registry.LocalMachine.OpenSubKey(@"SOFTWARE\Wow6432Node\Microsoft\Office"); if (key == null) { throw new Exception(Labels.AppRequiresOffice); } string[] versions = key.GetSubKeyNames().Where(v => Util.Parse <double>(v) >= 10).ToArray(); foreach (string v in versions) { key = Microsoft.Win32.Registry.LocalMachine.OpenSubKey(@"SOFTWARE\Wow6432Node\Microsoft\Office\" + v + @"\PowerPoint\InstallRoot", false); if (key != null && !String.IsNullOrEmpty(key.GetValue("Path") as string)) { found = true; } } } if (!found) { throw new Exception(Labels.AppRequiresOffice); } Config.FontSize = Util.Parse <double?>(ConfigurationManager.AppSettings["FontSize"]) ?? SystemFonts.MessageFontSize; base.OnStartup(e); //accessing database causes 3 or 4 sec delay so place in background thread, useful preloading for when planner is opened new Action(() => { //determine if it's a new installation by whether there are any schedules loaded or not //if Presenter 0.9.9, will be running sql compact 3.5 that will need to be upgraded to 4.0 bool isnew = true; try { isnew = !Schedule.LoadSchedules().Any(); } catch (Exception ex) { if (ex.GetBaseException().Message == "The database file has been created by an earlier version of SQL Server Compact. Please upgrade using SqlCeEngine.Upgrade() method.") { var engine = new System.Data.SqlServerCe.SqlCeEngine(ConfigurationManager.ConnectionStrings["DatabaseConnectionString"].ConnectionString); engine.Upgrade(); engine.Compact(null); isnew = !Schedule.LoadSchedules().Any(); } else { throw ex; } } //gives warning that videos won't work without WMP10, not a requirement so only display if a new installation if (isnew) { key = Microsoft.Win32.Registry.LocalMachine.OpenSubKey(@"SOFTWARE\Microsoft\MediaPlayer\PlayerUpgrade", false); if (key == null || Util.Parse <int>((key.GetValue("PlayerVersion") ?? "").ToString().Split(',').FirstOrDefault()) < 10) { if (!Application.Current.Dispatcher.CheckAccess()) { Application.Current.Dispatcher.Invoke(new Action(() => { MessageBox.Show(MainWindow, Labels.AppRequiresWMP, "", MessageBoxButton.OK, MessageBoxImage.Exclamation); })); } } } }).BeginInvoke(null, null); }