/// <summary> /// Static helper function to create an empty CE database /// </summary> /// <param name="client"></param> public static void CheckAndCreateCEDatabase(CEDatabase client) { if (!File.Exists(client.Location)) { SqlCeEngine engine = new SqlCeEngine(client.Connection.ConnectionString); engine.CreateDatabase(); engine.Dispose(); } }
private void addCEBtn_Click(object sender, EventArgs e) { ceCreationWizard = new NewCEClientCreationWizard(); //Create a new client CEDatabase client = new CEDatabase(); if (ceCreationWizard.ShowDialog(this) == DialogResult.OK) { //Creation mode is based on the option the user picked in the new ce creation wizard client.CreationMode = (ceCreationWizard.fullInitRadioBtn.Checked) ? CEDatabaseCreationMode.FullInitialization : CEDatabaseCreationMode.SnapshotInitialization; //Database location is based on mode. switch (client.CreationMode) { case CEDatabaseCreationMode.FullInitialization: client.Location = ceCreationWizard.fullInitDbLocation.Text; try { SynchronizationHelper.CheckAndCreateCEDatabase(client); } catch (Exception e1) { MessageBox.Show(e1.ToString(), "Error in creating CE database", MessageBoxButtons.OK); return; } break; case CEDatabaseCreationMode.SnapshotInitialization: client.Location = ceCreationWizard.snapshotDestLocation.Text; //Export the source SDF file first. ExportClientDatabase(new SqlCeConnection("Data Source=\"" + ceCreationWizard.snapshotSrcLocation.Text + "\""), client.Location); break; } //Provide our client a unique name client.Name = "Client " + (clientsMapping.Keys.Count + 1); //Add this client info to our mapping so it can be retrieved clientsMapping.Add(client.Name, client); //Create a SqlCeSyncProvider for the new client that is being added SqlCeSyncProvider clientProvider = synchronizationHelper.ConfigureCESyncProvider(client.Connection); providersCollection.Add(client.Name, clientProvider); //Now add a new tab to the peer tabs TabPage tab = new TabPage(client.Name); tab.Padding = new Padding(8); tab.Tag = client; TablesViewControl control = new TablesViewControl(client.Name); control.Name = "TablesViewCtrl"; control.Dock = DockStyle.Fill; tab.Controls.Add(control); this.peerTabsControl.TabPages.Add(tab); tab.BackColor = Color.Transparent; tab.UseVisualStyleBackColor = true; // Add the name of the file to the bottom Label labelFileName = new Label(); labelFileName.Text = "SqlCe Filename: " + ceCreationWizard.fullInitDbLocation.Text; labelFileName.Dock = DockStyle.Bottom; labelFileName.Padding = new System.Windows.Forms.Padding(4); tab.Controls.Add(labelFileName); //Add the client name to the list of providers available for synchronization this.srcProviderComboBox.Items.Add(client.Name); this.destProviderComboBox.Items.Add(client.Name); this.destProviderComboBox.SelectedIndex = destProviderComboBox.Items.Count - 1; this.synchronizeBtn.Enabled = this.providersCollection.Count > 1; } }