Page 1 of 1

Executecommand issue

Posted: Thu 04 Aug 2011 17:16
by Lucas Phillip
Hi there!

I'm trying to execute a custom SQL statment. A "LOAD DATA INFILE" to be more exact.

The problem is that if I use a hardcoded path to the file, everything works. But if I use a variable path, it does not.
For exemple:

this snipped works

Code: Select all

string command = @"LOAD DATA INFILE 'D:\Econ\ECONCPAServer\bin\Release\occurrences.sql' INTO TABLE occurrence FIELDS TERMINATED BY ';';
dc.ExecuteCommand(command);

this on the other hand does not

Code: Select all

string workingFile = string.Format(@"{0}\occurrences.sql", Environment.CurrentDirectory);
string command = string.Format(@"LOAD DATA INFILE '{0}' INTO TABLE occurrence FIELDS TERMINATED BY ';'", workingFile);
dc.ExecuteCommand(command);
When I look the exception, it says that it could not find file D:EconECONCPAServerbin\Releaseoccurrences.sql

What is going on here? Am I doing something stupid and not even seeing it?

Thanks

Posted: Fri 05 Aug 2011 16:22
by StanislavK
The problem is that the path constant specified in the 'LOAD DATA INFILE' command should contain double slashes, and the Environment.CurrentDirectory string contains single ones. To resolve the problem, you can. e.g., duplicate the slashes:

Code: Select all

string workingFile = string.Format(@"{0}\occurrences.sql", Environment.CurrentDirectory.Replace(@"\",@"\"));
Otherwise, you can pass the file name as a SQL parameter:

Code: Select all

dc.ExecuteCommand(@"LOAD DATA INFILE {0} INTO TABLE occurrence FIELDS TERMINATED BY ';'", workingFile);
Please tell us if this helps.