static void export(string[] args) { // /export "target folder here" "provider_name_here" "connection_string_here" db_name_here string folder = args[1].Replace("\"", ""); string during = "Connecting to database"; try { // parse the dsc into a DataConnectionSpec object DataConnectionSpec dsc = new DataConnectionSpec { ProviderName = args[2].Replace("\"", ""), ConnectionString = args[3].Replace("\"", ""), }; __frmProgress = new frmProgress(); __frmProgress.Show(); __frmProgress.Text = "Exporting Data from " + args[4] + " Database..."; // read table info from database Creator c = Creator.GetInstance(dsc); c.OnProgress += new ProgressEventHandler(c_OnProgress); updateProgress("Loading table information..."); during = "loading table information"; List <TableInfo> tables = c.LoadTableInfo(args[4], null, false, int.MaxValue); // save table schema to file c.SaveTableInfoToXml((folder + @"\__schema.xml").Replace(@"\\", @"\"), tables); // copy the data from the database during = "copying data"; c.CopyDataFromDatabase(folder, args[4], tables); updateProgress("Done"); } catch (Exception ex) { updateProgress("Error while " + during + ": " + ex.Message); // MessageBox.Show("Error while " + during + ": " + ex.Message); throw; } __frmProgress.btnDone.Enabled = true; __frmProgress.Close(); //while (__frmProgress.Visible) { // Thread.Sleep(1000); // Application.DoEvents(); //} }
private void btnCopyDataFrom_Click(object sender, EventArgs e) { clearWorker(); List <string> tableNames = new List <string>(); for (int i = 0; i < lvFromTables.Items.Count; i++) { ListViewItem lvi = lvFromTables.Items[i]; if (lvi.Checked) { tableNames.Add(lvi.Text); } } DataConnectionSpec dcs = new DataConnectionSpec { ConnectionString = cboConnectionStringFrom.Text, ProviderName = getFromProviderName(), CommandTimeout = COMMAND_TIMEOUT }; if (dcs.ConnectionString.Contains("Driver=")) { // assume odbc dcs.ProviderName = "ODBC"; } Creator c = Creator.GetInstance(dcs); string schemaName = txtFromDatabaseOwner.Text; string dest = txtDestinationFolder.Text; backgroundWorker1.ProgressChanged += new ProgressChangedEventHandler(backgroundWorker1_ProgressChanged); backgroundWorker1.DoWork += new DoWorkEventHandler(delegate(object sender2, DoWorkEventArgs evt2) { _timer = new HighPrecisionTimer("timer", true); c.OnProgress += new ProgressEventHandler(c_OnProgress); backgroundWorker1.ReportProgress(0, new ProgressEventArgs("Gathering schema information from database...", 0, 0)); List <TableInfo> tables = c.LoadTableInfo(schemaName, tableNames, false); c.CopyDataFromDatabase(dest, schemaName, tables); }); backgroundWorker1.RunWorkerCompleted += new RunWorkerCompletedEventHandler(backgroundWorker1_RunWorkerCompleted); backgroundWorker1.RunWorkerAsync(); }
private void btnActionWriteDataGo_Click(object sender, EventArgs e) { if (rbActionWriteDatabaseData.Checked) { if (rbToIsDatabase.Checked && (rbFromIsCSV.Checked || rbFromIsDatabase.Checked)) { MessageBox.Show("Copying data is only allowed from a database to xml file(s), or from xml file(s) to a database.\n"); return; } Creator c = rbFromIsDatabase.Checked ? getFromCreator() : getToCreator(true); if (c == null) { return; } // first make sure checkboxes line up with our 'selected' tables selectTables(); background((sentBy, args) => { if (rbFromIsDatabase.Checked) { // copy from database to xml string toFolder = Toolkit.ResolveDirectoryPath(txtToFolderName.Text, true); c.CopyDataFromDatabase(toFolder, txtFromDatabaseName.Text, _tables); } else { // copy from xml to database string fromFolder = new FileInfo(Toolkit.ResolveFilePath(txtFromFileName.Text, false)).DirectoryName; c.CopyDataToDatabase(fromFolder, txtToDatabaseName.Text, _tables, false, false); } }); } else if (rbActionWriteMappingData.Checked) { MessageBox.Show("Dataview data cannot be saved to file. It must be written directly to a target database."); return; //Creator c = getToCreator(true); //int selectedCount = selectTables(); //background((sentBy, args) => { // if (rbToIsDatabase.Checked) { // int i = 0; // foreach (TableInfo ti in _tables) { // if (ti.IsSelected) { // i++; // showProgress("Mapping dataview for table " + ti.TableName + "... ", i, selectedCount); // c.CreateDataviewMappings(ti, _tables); // } // } // } else { // // copy sys_* table info to file // } // }); } else { throw new NotImplementedException("Change code here. btnActionWriteDataGo_Click"); } }