//*************************************************************************** // Private Methods // private DataSet ExecuteCommand(string ConnectionString, string Command, AdoProviderType Provider) { this.ReadStartedEvent(); // Declare DB object. rsDb dbRead = null; try { // Initialize using the proper DB provider class. dbRead = rsDb.GetDbObject(Provider, ConnectionString, Command); dbRead.DataAdapter.MissingSchemaAction = MissingSchemaAction.AddWithKey; return(dbRead.GetData()); } catch (Exception ex) { throw new Exception("Unable to read data from database.", ex); } finally { if (dbRead != null) { dbRead.Dispose(); } } }
public frmDataExport(rsDb dbSrc, string dbName) : this() { this._db = dbSrc; this._dbNm = dbName; this.PopulateTableList(); this.drpDstFormatType.SelectedIndex = 0; }
//public void BeginTransaction(IsolationLevel isoLvl) //{ // this._db.DbConnection.BeginTransaction(isoLvl); //} //public void RollbackTransaction() //{ // this._db.DbCommand.Transaction.Rollback(); //} //public void CommitTransaction() //{ // this._db.DbCommand.Transaction.Commit(); //} #endregion #region Private Methods //*************************************************************************** // Private Methods // //private void DoQueryExec(rsDb dataObj) private void DoQueryExec(AdoProviderType dbType, string cnStr, string qrStr, int timeOut) { this._abort = false; this._isExec = true; this.ExecuteStartedEvent(); this._abortEx = null; // Create an rsDb object to handle our database interface. using (rsDb dataObj = rsDb.GetDbObject(dbType, cnStr, qrStr)) { // We set the connection's timeout here. By default, this value is // set to 'Zero' (meaning no timeout). dataObj.DbCommand.CommandTimeout = timeOut; // We use the 'keepReading' value to determine if the statement // returns multiple result sets. bool keepReading = true; try { // Performing the call to 'Prepare' ensures there are no syntax errors // before actually executing a batch of statements. This also helps // to speed execution slightly. dataObj.DbCommand.Prepare(); dataObj.InitReader(); // Loop through each result set. while (keepReading && !this._abort) { int idx = 0; DataTable dtNew = dataObj.DataReader.GetSchemaTable().Clone(); this.ResultStartEvent(dtNew); while (dataObj.DataReader.Read()) { DataRow drNew = dtNew.NewRow(); dataObj.DataReader.GetValues(drNew.ItemArray); this.RecordProcessedEvent(drNew.ItemArray, idx); } this.ResultCompleteEvent(); keepReading = dataObj.DataReader.NextResult(); } } catch (Exception ex) { this._abortEx = ex; this.ExecuteAbortEvent(); return; } finally { dataObj.CloseReader(); this._isExec = false; } } }
//*************************************************************************** // Private Methods // //private DataSet DoQueryExec(rsDb dataObj) private DataSet DoQueryExec(string connStr, string qryString, AdoProviderType provId) { rsDb dataObj = null; this.RaiseExecuteStarted(); this._abortEx = null; this._dtResult = null; this._recAffected = 0; DataSet retVal = null; try { if (this._db == null || this._db.ConnectionString != connStr || this._db.QueryString != qryString) { if (this._db != null) { this._db.Dispose(); } dataObj = rsDb.GetDbObject(provId, connStr, qryString); dataObj.DbCommand.CommandTimeout = this._timeOut; this._db = dataObj; } retVal = new DataSet(); this._recAffected = dataObj.GetData(ref retVal); return(retVal); } catch (Exception ex) { this._abortEx = ex; this.RaiseExecuteAbortEvent(); return(null); } //finally //{ // if (dataObj != null) // dataObj.Dispose(); //} }
private void PopulateColumns() { if (this._cols == null) { this._cols = new ColumnParamsCollection(); } else { this._cols.Clear(); } if (this.TargetDirection == DataTargetDirection.Source) { if (this.DataTargetType == DataTargetType.Flat_File) { if (string.IsNullOrEmpty(this.pan02cboFlatSrcColDelim.Text) || string.IsNullOrEmpty(this.pan02cboFlatSrcRowDelim.Text) || !File.Exists(this.pan02txtFlatSrcFileName.Text)) { return; } string[] pcs = null; switch (this.pan02drpFlatSrcFormat.SelectedIndex) { case 0: // Delimited string cDelim = string.Empty, rDelim = string.Empty; switch (this.pan02cboFlatSrcColDelim.Text) { case "{CR}{LF}": cDelim = "\r\n"; break; case "{CR}": cDelim = "\r"; break; case "{LF}": cDelim = "\n"; break; case "Semicolon {;}": cDelim = "\n"; break; case "Colon {:}": cDelim = ":"; break; case "Comma {,}": cDelim = ","; break; case "Tab {t}": cDelim = "\t"; break; case "Vertical Bar {|}": cDelim = "|"; break; default: cDelim = this.pan02lblFlatSrcColDelim.Text; break; } switch (this.pan02cboFlatSrcRowDelim.Text) { case "{CR}{LF}": rDelim = "\r\n"; break; case "{CR}": rDelim = "\r"; break; case "{LF}": rDelim = "\n"; break; case "Semicolon {;}": rDelim = "\n"; break; case "Colon {:}": rDelim = ":"; break; case "Comma {,}": rDelim = ","; break; case "Tab {t}": rDelim = "\t"; break; case "Vertical Bar {|}": rDelim = "|"; break; default: rDelim = this.pan02lblFlatSrcColDelim.Text; break; } string sTxtQual = this.pan02txtFlatSrcTextQual.Text; if (sTxtQual.ToLower() == "<none>") { sTxtQual = string.Empty; } using (FileStream fs = new FileStream(this.pan02txtFlatSrcFileName.Text, FileMode.Open, FileAccess.Read)) using (RainstormStudios.IO.DelimitedTextReader rdr = new RainstormStudios.IO.DelimitedTextReader(fs, rDelim, cDelim, sTxtQual, Encoding.Default)) for (int i = 0; i < this.pan02numFlatSrc.Value + 1; i++) { pcs = rdr.ReadRow(); } break; case 1: // Fixed width break; case 2: // Ragged right break; } // If the first row doesn't contain the column names, then // just populate the array with generic "ColumnXXX" values. if (!this.pan02chkFlatSrcColNameFirstRow.Checked) { for (int i = 0; i < pcs.Length; i++) { pcs[i] = "Column" + i.ToString().PadLeft(pcs.Length.ToString().Length, '0'); } } // Create the entries in the ColumnParams collection. for (int i = 0; i < pcs.Length; i++) { this._cols.Add(new RainstormStudios.Data.ColumnParams(pcs[i], typeof(System.String), 0, i)); } if (pcs == null) { return; } } else { string sqlQry = "SELECT TOP 1 * FROM " + this.pan02drpSqlDatabaseList.Text; using (rsDb db = rsDb.GetDbObject(AdoProviderType.Auto, this.GetConnectionString(), sqlQry)) { using (DataSet ds = db.GetData()) { if (ds.Tables.Count > 0) { foreach (DataColumn dc in ds.Tables[0].Columns) { this._cols.Add(new ColumnParams(dc.ColumnName, dc.DataType, dc.MaxLength, dc.Ordinal)); } } } } } } else { if (this.DataTargetType == DataTargetType.Flat_File && File.Exists(this.pan02txtFlatSrcFileName.Text)) { } else if (this.DataTargetType == DataTargetType.SQL_Native_Client) { } } // If we're working with a flat data type, then populate the columns in the wizard. if (this.DataTargetType == DataTargetType.Flat_File) { this.pan02lstFlatSrcColPrev.BeginUpdate(); this.pan02lstFlatSrcColPrev.Items.Clear(); for (int c = 0; c < this._cols.Count; c++) { this.pan02lstFlatSrcColPrev.Items.Add(new ListViewItem(new string[] { this._cols[c].ColumnName, this._cols[c].DataType.ToString(), this._cols[c].FieldSize.ToString() })); } this.pan02lstFlatSrcColPrev.EndUpdate(); } }