Executecommand issue

Executecommand issue

Postby Lucas Phillip » Thu 04 Aug 2011 17:16

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
Lucas Phillip
 
Posts: 10
Joined: Wed 29 Jun 2011 14:37

Postby StanislavK » Fri 05 Aug 2011 16:22

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.
StanislavK
Devart Team
 
Posts: 1710
Joined: Thu 03 Dec 2009 10:48


Return to LinqConnect (LINQ to SQL support)