473,404 Members | 2,174 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,404 software developers and data experts.

Creating new database tables and indexes from existing tables

Problem: My company generates its own data export from a propietary
database. These (free) tables can be read in C#.NET using a Visual FoxPro
driver (vfpoledb). I can read each of the six tables into its own datatable,
modify them, and add them to a dataset. It take approximately 15 minutes to
pass that dataset to Crystal Reports (45 minutes if the report uses three
subreport datasets). Then it takes over 7 hours for Crystal to generate the
report. Ugh!

My first attempt to speed things up was to generate an external index file
for each table. Even after extensive internet searches and reading, I could
not get past the syntax errors and "Exclusive use" errors; I've tried adding
"Mode=ReadWrite" and "Exclusive=On" to the connection string with no effect.
(I still think the indexing would be beneficial, and would appreciate any
help with this).

The current attempt involves combining similar columns from two tables into
other tables for a total of four tables in the dataset, plus a total re-write
of the report to use this new dataset. This is not a trivial report re-write.

To avoid this dataset cluge and the report re-write: I would like to load
the tables using SELECT commands to limit the data loaded, add indexing, and
write the tables back to disk with the same names in a new location (I cannot
alter the existing tables because that data is used for numerous reports).
My hope is that the report will only have to change the location of where it
gets its tables, and that it will not have to be re-written. Can anyone tell
me if this is a valid approach, or if there is a better way? I have included
the code below:

private void crvReport_Load(object sender, System.EventArgs e)
{
string sDataSourcePath = "C:\\CB\\CRData\\";

// ***** Get data from database (OleDb) *****
string sConnectionString = "Provider=VFPOLEDB.1;DSN=CB Data32;"
+ "DataSource=" + sDataSourcePath + ";";
OleDbConnection conn = new OleDbConnection( sConnectionString );
conn.Open();

// Load the first table - A/R Transactions
string sSelect = "SELECT * FROM ZARTRAN.DBF " +
"WHERE trnstype IN ('CreditAdjustment', 'Charge') " +
"AND (Upper(tblnam) LIKE '%BILLING%')";

OleDbDataAdapter da1 = new OleDbDataAdapter();
da1.SelectCommand = new OleDbCommand( sSelect, conn);
DataTable dtTransactions = new DataTable( "Transactions" );

// Add primary key (needed to create an index)
DataColumn [] dcaPrimaryKeyTransactions = new DataColumn[3];
dcaPrimaryKeyTransactions[0] = dtTransactions.Columns[ "arshort" ];
dcaPrimaryKeyTransactions[1] = dtTransactions.Columns[ "arunqid" ];
dcaPrimaryKeyTransactions[2] = dtTransactions.Columns[ "invptr" ];
dtTransactions.PrimaryKey = dcaPrimaryKeyTransactions;

// Fill the datatable
da1.Fill( dtTransactions );

// ??? attempt to add an index, but could not get it to work
// ??? using "CREATE INDEX" did not work either
OleDbCommand cmdAlterTable = new OleDbCommand();
cmdAlterTable.CommandText = "INDEX ON idxTrnsType ON
dtTransactions(trnstype)";
// cmdAlterTable.ExecuteCommand();
cmdAlterTable.CommandText = "INDEX ON idxTrnsDate ON
dtTransactions(trnsdate)";
// cmdAlterTable.ExecuteCommand();
cmdAlterTable.CommandText = "INDEX ON idxTblNam ON
dtTransactions(tblnam)";
// cmdAlterTable.ExecuteCommand();

// Load second table - A/R Invoices
sSelect = "SELECT * FROM ZARINV.DBF " +
"WHERE (Upper(tbl2nam) LIKE 'NAT%')";
OleDbDataAdapter da2 = new OleDbDataAdapter();
da2.SelectCommand = new OleDbCommand( sSelect, conn);
DataTable dtInvoices = new DataTable( "Invoices" );
DataColumn [] dcaPrimaryKeyInvoices = new DataColumn[3];
dcaPrimaryKeyInvoices[0] = dtInvoices.Columns[ "arshort" ];
dcaPrimaryKeyInvoices[1] = dtInvoices.Columns[ "arunqid" ];
dcaPrimaryKeyInvoices[2] = dtInvoices.Columns[ "invunqid" ];
dtInvoices.PrimaryKey = dcaPrimaryKeyInvoices;
// (add index goes here)
da2.Fill( dtInvoices );

// Repeat above steps above for remaining tables

// Create the dataset
DataSet dsDataSet = new DataSet();

// Add the tables to the dataset
dsDataSet.Tables.Add( dtTransactions );
dsDataSet.Tables.Add( dtInvoices );
// repeat to add other tables ... dsDataSet.Tables.Add( ... );

conn.Close();
// ***** end reading OleDb *****

// Write back to disk (currrently passing the dataset to Crystal)
// ???

// Launch Crystal Reports
}

I appreciate any help or suggestions. Thanks!

Nov 16 '05 #1
1 6293
This is just a follow up post in case anyone else has the same problem.

There does not seem to be a way to add external indexes to these old-style
FoxPro tables. But we were still able to cut the entire report process down
to 15 minutes by creating new tables that were just a subset of the original
tables, and re-writing the Crystal Report to remove the subreport sections!

Here's an example of one table:
string sSourceFile = sDataSourcePath + "ZACCOUNT.DBF";
string sDestFile = sDataSourcePath + "QACCOUNT.DBF";
if ( true == File.Exists( sDestFile )) File.Delete( sDestFile );
string sCreate = "CREATE DBF QACCOUNT FREE (arshort c(16), arname c(30),
arunqid c(10))";
OleDbCommand cmdCreate = new OleDbCommand( sCreate, conn);
cmdCreate.ExecuteNonQuery();
string sInsert = "INSERT INTO QACCOUNT SELECT arshort, arname, arunqid FROM
ZACCOUNT";
OleDbCommand cmdInsert = new OleDbCommand( sInsert, conn);
cmdInsert.ExecuteNonQuery();

The new table (QACCOUNT) is created with only the columns needed. The
INSERT command takes only those columns from the source table and puts them
into the new table.

An alternative way to do this is to use C#'s File.Copy command, then remove
the unwanted columns from the new table:
string sSourceFile = sDataSourcePath + "ZACCOUNT.DBF";
string sDestFile = sDataSourcePath + "QACCOUNT.DBF";
File.Copy( sSourceFile, sDestFile, true );
if ( ConnectionState.Closed == conn.State ) conn.Open();
string sDropColumn = "ALTER TABLE QACCOUNT DROP COLUMN arnum";
OleDbCommand cmdAlter = new OleDbCommand( sDropColumn, conn );
cmdAlter.ExecuteNonQuery();

Nov 16 '05 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
by: K Finegan | last post by:
I have an archival process on a large database that runs once a month. At the beginning of the process the triggers and indexes on the tables whose data is moved are dropped, the data is moved and...
5
by: serge | last post by:
What is the best way to run one command and have a database be created and sql scripts run on it to create the tables, indexes, triggers, procedures, etc.? Is there an existing tool free or...
3
by: serge | last post by:
I have all the scrips to create a database. I have a few questions: 1- I am creating a batch file that it will call many lines like: db2 -td@ -f filename.sql -z output.txt The order i am using...
8
by: Brian S. Smith | last post by:
Hi gang, Please help. I've been through the Access help, searched the Web, and I can't seem to get a straight answer. As the Subject line suggests, I want to run a fairly simple VB/Access Sub...
4
by: Eric E | last post by:
Hi all, I'm having quite a bit of trouble with code to create linked tables in Access 2K. I create a DAO tabledef using CreateTableDef against a DAO database object, then set its connection...
1
by: Paul | last post by:
Hi, I wish to be able to add tables to a sql server database at runtime from my asp.net application. As well as creating fields I also wish to be able to create indexes on selected fields and to...
3
by: Dixie | last post by:
I know how to append records from one table to another in the same database, but I need to be able to append the records from all the tables in one database into new empty tables in another...
7
by: reachsamdurai | last post by:
Hello, I'm looking for a method to check the utilization of index by any SQL (Static and Dynamic) at the database level instead of generating the access plan for each SQL. I have inherited a...
10
by: Jim Devenish | last post by:
I have a split front end/back end system. However I create a number of local tables to carry out certain operations. There is a tendency for the front end to bloat so I have set 'compact on...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.