473,739 Members | 6,655 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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.EventArg s e)
{
string sDataSourcePath = "C:\\CB\\CRData \\";

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

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

OleDbDataAdapte r da1 = new OleDbDataAdapte r();
da1.SelectComma nd = new OleDbCommand( sSelect, conn);
DataTable dtTransactions = new DataTable( "Transactio ns" );

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

// 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.C ommandText = "INDEX ON idxTrnsType ON
dtTransactions( trnstype)";
// cmdAlterTable.E xecuteCommand() ;
cmdAlterTable.C ommandText = "INDEX ON idxTrnsDate ON
dtTransactions( trnsdate)";
// cmdAlterTable.E xecuteCommand() ;
cmdAlterTable.C ommandText = "INDEX ON idxTblNam ON
dtTransactions( tblnam)";
// cmdAlterTable.E xecuteCommand() ;

// Load second table - A/R Invoices
sSelect = "SELECT * FROM ZARINV.DBF " +
"WHERE (Upper(tbl2nam) LIKE 'NAT%')";
OleDbDataAdapte r da2 = new OleDbDataAdapte r();
da2.SelectComma nd = new OleDbCommand( sSelect, conn);
DataTable dtInvoices = new DataTable( "Invoices" );
DataColumn [] dcaPrimaryKeyIn voices = new DataColumn[3];
dcaPrimaryKeyIn voices[0] = dtInvoices.Colu mns[ "arshort" ];
dcaPrimaryKeyIn voices[1] = dtInvoices.Colu mns[ "arunqid" ];
dcaPrimaryKeyIn voices[2] = dtInvoices.Colu mns[ "invunqid" ];
dtInvoices.Prim aryKey = dcaPrimaryKeyIn voices;
// (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.Table s.Add( dtTransactions );
dsDataSet.Table s.Add( dtInvoices );
// repeat to add other tables ... dsDataSet.Table s.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 6328
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.D BF";
string sDestFile = sDataSourcePath + "QACCOUNT.D BF";
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.Execu teNonQuery();
string sInsert = "INSERT INTO QACCOUNT SELECT arshort, arname, arunqid FROM
ZACCOUNT";
OleDbCommand cmdInsert = new OleDbCommand( sInsert, conn);
cmdInsert.Execu teNonQuery();

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.D BF";
string sDestFile = sDataSourcePath + "QACCOUNT.D BF";
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.Execut eNonQuery();

Nov 16 '05 #2

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

Similar topics

0
1509
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 then the triggers and indexes are recreated at the end. This produces a massive improvement in performance. The problem is the process is supposed to run on users accounts (thats the way the front-end is set up) and they don't have the...
5
1832
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 commercial to automate this? Thank you
3
2397
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 is: 1- Create the database 2- Tables 3- Insert the data
8
4328
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 Function/Module that creates relationships for my tables. The problem is that I need to provide for some tables that may have > 32 relationships (which is apparently the limit on Indexes that Access can support). How can I prevent Access from...
4
13495
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 string appropriately. The trouble is when I go to append the tableDef to the collection I get error 3264: No field defined --cannot append TableDef or Index Any suggestions?
1
1807
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 assign user permissions. (I need to assign permissions to the table object as I will be using sp_executesql or exec to execute a string). I'm thinking there are 3 possible ways to do this:
3
7214
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 database. The tables in the second database would have the same names as those in the first database. Can this be done and if so how? dixie
7
2148
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 database where index occupies more space than the data and most of the indexes are looking redundant to me hence I would like to check each index utilization and drop the same if it is not used. Env: DB2 UDB 8.2 /AIX 5.3
10
7704
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 close' I think that I have read in some threads (althoug I cannot find them now) that others place such tables in a local, linked database. I could do this but I am interested to know what would be the advantages. And disadvantages, if any. Any...
0
8969
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8792
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
9479
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
9337
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
8215
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
6754
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
4826
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
3280
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
3
2193
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.