N
Norman Diamond
A file is successfully opened, partly read, and not closed, but suddenly it
stops existing? How does Ado.Net accomplish this result?
This seems to be a 100% repro on one file but 100% no problem on a different
file. Again how does Ado.Net do this?
// Sample dirName is C:\myDir and tableName is myFile1.csv or myFile2.csv.
OleDbConnection connection = new OleDbConnection(
"Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" +
dirName +
";Extended Properties='Text;Extensions=asc,csv,tab,txt;" +
"HDR=Yes;FMT=Delimited'");
connection.Open();
OleDbDataAdapter dataAdapter = new OleDbDataAdapter(
"SELECT * FROM [" + tableName + "]", connection);
DataTable dataTable = new DataTable(tableName);
dataAdapter.FillSchema(dataTable, SchemaType.Source);
DataColumnCollection dataColumns = dataTable.Columns;
int fileColumnCount = dataColumns.Count;
foreach (DataColumn dataColumn in dataColumns)
{
dataColumn.DataType = typeof(string);
}
// This works up to here. FillSchema worked.
// The next call works on myFile1.csv but fails on myFile2.csv.
dataAdapter.Fill(dataTable); // Exception: file does not exist. Wtf?
stops existing? How does Ado.Net accomplish this result?
This seems to be a 100% repro on one file but 100% no problem on a different
file. Again how does Ado.Net do this?
// Sample dirName is C:\myDir and tableName is myFile1.csv or myFile2.csv.
OleDbConnection connection = new OleDbConnection(
"Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" +
dirName +
";Extended Properties='Text;Extensions=asc,csv,tab,txt;" +
"HDR=Yes;FMT=Delimited'");
connection.Open();
OleDbDataAdapter dataAdapter = new OleDbDataAdapter(
"SELECT * FROM [" + tableName + "]", connection);
DataTable dataTable = new DataTable(tableName);
dataAdapter.FillSchema(dataTable, SchemaType.Source);
DataColumnCollection dataColumns = dataTable.Columns;
int fileColumnCount = dataColumns.Count;
foreach (DataColumn dataColumn in dataColumns)
{
dataColumn.DataType = typeof(string);
}
// This works up to here. FillSchema worked.
// The next call works on myFile1.csv but fails on myFile2.csv.
dataAdapter.Fill(dataTable); // Exception: file does not exist. Wtf?