Hi all..
I'm having some trouble parsing a *.CSV file in windows server 2008 64bit version. The problem it that Jet OLEDB 4.0 doesn't read the header row, presented in the CSV.
That means, that when I try to access one of the columns like this:
DataTable tbl = GetCsvData();
string sd = tbl.Rows[0]["id"].ToString();
The program throws an exception, saying that the column does not belong in the datable.
I'm using the following code:
public DataTable GetCsvData() {
FileInfo file = new FileInfo(this.fileName);
string connectionString = "Provider=Microsoft.Jet.OLEDB.4.0;" +
"Data Source=" + file.DirectoryName + "\\;" +
"Extended Properties=\"text;HDR=Yes;FMT=Delimited(;)\";";
OleDbConnection objConn = new OleDbConnection(connectionString);
objConn.Open();
OleDbCommand objCmdSelect = new OleDbCommand(string.Format("SELECT * FROM [{0}]", file.Name), objConn);
OleDbDataAdapter adp = new OleDbDataAdapter(objCmdSelect);
DataTable tbl = new DataTable("CSVData");
adp.Fill(tbl);
objConn.Close();
objConn.Dispose();
return tbl;
}
As you can see, the Extended Properties are correct: "HDR=Yes", this forces the Jet engine to read the header row on the CSV file.
The problem is really strange because I can read the same CSV file on my development machine ( Windows XP SP3 ), with absolutely no problem.
I think this is a problem derived to the 64 bit version of Windows server 2008.
I checked the versions of the msjet40.dll file on both the server and local machine:
Windows XP SP3 => 4.0.9551
Windows Server 2008 64 bit => 4.0.9755
The problem isn't on the CSV file, it's in the driver provided by Microsoft ( at least is what I think ), since I can read the CSV file perfectly on my machine.
Does one has any idea a way to solve this problem? I googled a lot, but I couldn't find anything.
Thanks..