views:

12

answers:

1

Using Windows Server 2003, MySQL 5.1.23, MySQL .NET Connector 6.2.2

I am trying to use the MySQLBulkLoader class to read in a fixed width text file. An excerpt from that classes Load method is:

string sql = BuildSqlCommand();
MySqlCommand cmd = new MySqlCommand(sql, Connection);
cmd.CommandTimeout = 10 * 60;// Timeout;
cmd.ExecuteNonQuery();

The string created by 'BuildSqlCommand' is:

LOAD DATA LOCAL INFILE 'c:/M/D/ALLDATA_0.TXT' INTO TABLE dk.tk 
FIELDS  TERMINATED BY '' LINES TERMINATED BY '\n' 

When the program launchs the 'ExecuteNonQuery' the following error occurs:

(Message) Fatal error encountered during command execution. (Source) MySql.Data (Inner Exception Message) Fatal error encountered attempting to read the resultset.

Is there any known limitations to ExecuteNonQuery? The text file size is 290MB.

A: 

After many different attempts it looks like the error was related to a mix the syntax of the LOAD DATA INFILE statement and how the MySQL Bulk Loader works. I ended up completely ignoring the MySQL Bulk Loader class as the BuildSQLCommand method returned results that did not work. The problem with the BulkLoader is that it appears to want comma delimited files where my file was fixed width with no field delimiters.

The following code sample works for importing a fixed width file - the table field sizes are setup to slice up the file into the appropriate fields.

string sql = @"load data infile 'c:/myfolder/Data/" + aFile.Name 
+ "' ignore into table t_data fields terminated by '' enclosed by '' lines terminated by '\n'";
MySqlCommand cmd = new MySqlCommand(sql, conn);
cmd.CommandTimeout = Timeout;
cmd.ExecuteNonQuery();

My Timeout value is set to 0.

John M