private bool CheckForRowsetStart()

in RowsetImportEngine/TextRowsetImporter2.cs [658:742]


        private bool CheckForRowsetStart (string ColumnLines, string ColumnNames, string RowsetIdentifier, bool NonTabularOnly)
		{
			bool ret = true;
			ArrayList rowsets;

			try
			{
				// See whether any of the known rowsets "claims" this one. 
				if (NonTabularOnly)
					rowsets = this.KnownNonTabularRowsets;
				else
					rowsets = this.KnownRowsets;
				foreach (TextRowset r in rowsets)
				{
					if (r.CheckForRowsetStart(ColumnLines, ColumnNames, RowsetIdentifier))
					{
						this.CurrentRowset = r;
						break;
					}
				}
	
				if (!(null == this.CurrentRowset)) 
				{
					// We've found a rowset object that claims the current rowset. 
					this.CurrentRowset.DefineRowsetColumns(ColumnLines, ColumnNames);
					// Issue a DROP TABLE for this rowset if this is the first time we've encountered it and if 
					// we're not supposed to be appending rows to existing tables. 
					if ((this.dropTables) && (!this.CurrentRowset.HasBeenEncountered))
						DropCurrentTable();
					// Create table in SQL if this is the first time we've run into it. 
					if (!this.CurrentRowset.HasBeenEncountered)
					{
						CreateTable();
						// Set up the BCP connection for this rowset (only the first time we encounter a given rowset). 
						if (0 == this.CurrentRowset.hConn)
							this.CurrentRowset.hConn = BulkLoad.AllocateConnectionHandle();
						if (0 == this.CurrentRowset.hConn)
						{
							ret = false;
                            ErrorDialog ed = new ErrorDialog("Failed to allocate BCP connection object.", true, this.logger);
							ed.Handle();
						}
						if (!(ret = BulkLoadConnect()))
						{
                            string ErrMsg;
                            if (0 == this.connStr.Length)
                            {
                                ErrMsg = "BCP connection attempt to server [" + server + "] failed.\n"
                                    + BulkLoad.GetErrorMessage(this.CurrentRowset.hConn);
                            }
                            else
                            {
                                ErrMsg = "BCP connection attempt failed.  ConnStr=[" + this.connStr + "].\n"
                                    + BulkLoad.GetErrorMessage(this.CurrentRowset.hConn);
                            }
                            ErrorDialog ed = new ErrorDialog(ErrMsg, true, this.logger);
							ed.Handle();
						}
					}
					if (!ret)
					{
						// We ran into some error while trying to set up this BCP side of things, but the user 
						// chose to continue.  Return false to skip this rowset in the input text file. 
						return false; 
					}
					// If we don't have an in-progress bulk load for the rowset, start one. 
					if (!this.CurrentRowset.InBCPRowset)
					{
						ret = SetUpBulkLoadRowset(this.CurrentRowset);
						if (!ret) return false;
					}
					// We're all set. Mark this rowset as "encountered" so we don't drop it again next time.
					this.CurrentRowset.HasBeenEncountered = true;
					return true;
				}
				else 
					return false; 
			}
			catch (Exception e)
			{
                ErrorDialog ed = new ErrorDialog(e, true, this.logger);
				ed.Handle();
			}
			return true;
		}