Open file suddenly stops existing?!

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?
 
W

Wen Yuan Wang [MSFT]

Hello Norman,

I never heard of it. Which version of .net framework are you using? (.net
1.0, 1.1, 2.0 ?)
I have tried it in .net 2.0 on my side. I created an excel file, saved it
as ".csv" file. Then, I pasted your code snippet in my console application,
run application and checked DataTable. It works fine...

Is it possible for you to send me your problematic csv file? My email
address is (e-mail address removed).
It seems the issue only occurs on your specific "myFile2.csv" file. I
cannot reproduce the issue without it.
I will perform further research after getting problematic csv file.

If you have any more concern, please feel free to let me know. We are glad
to assist you.

Have a great day,
Best regards,

Wen Yuan
Microsoft Online Community Support
==================================================
This posting is provided "AS IS" with no warranties, and confers no rights.
 
N

Norman Diamond

The program uses .Net framework 2.0 SP1.

It doesn't surprise me that you had no problem with your CSV file. As
mentioned in my previous posting, I have a 100% repro with one CSV file but
no problem with a different CSV file. Both of those files are proprietary
to a customer. If I have time I will try to create a simpler repro.

I don't know if my employer will allow me time to create a simpler repro,
because I already put a workaround in code. I wrapped the FillSchema and
Fill calls in a try statement (even though FillSchema executes with no
problem). When any exception occurs, even this unbelievable exception, I
display an error and let the user try a different file.

Still, how can this exception be possible. The file exists, the file was
opened, FillSchema already read part of the file, and I do not play any
games like deleting the file in Windows Explorer or anything like that.
Both the working file and the failing file remain on disk exactly as they
are.
 
W

Wen Yuan Wang [MSFT]

Hello Norman,
Thanks for your reply.

I am afraid we cannot find out the exact root cause without further
information captured when the problem occurs. It will be helpful if you can
create a simple repro...

Just for curious , have you tried to fill dataset before the FillSchemal
method? Does Fill method still complain for "Filedoes not exist" error?
Do you have any call stack when the issue happens? I'm not sure why this
happens. But we may get some hint from the call stack.

Have a great day,
Best regards,

Wen Yuan
Microsoft Online Community Support
==================================================
This posting is provided "AS IS" with no warranties, and confers no rights.
 
N

Norman Diamond

If I omit the call to FillSchema then it will be difficult to set the column
datatypes to be all strings. However, the purpose of this test will be to
try to track down the bug, so it doesn't matter that my program will have
additional problems temporarily during that test. I will try to make time
for that test.
 
W

Wen Yuan Wang [MSFT]

Hello Norman,
Thanks for your reply.

It sounds you are a little busy these day, haven't enough time to drill
into the issue.
Anyway, if you are still intersted in this case when available, we are
standing by.
Please feel free to let us know if you need any assistance. It's my
pleasure to assist you.

Have a great day,
Best regards,
Wen Yuan
Microsoft Online Community Support
==================================================
This posting is provided "AS IS" with no warranties, and confers no rights.
 
W

Wen Yuan Wang [MSFT]

Hello Norman,
Thanks for your reply.

I have reproduced the issue. As far as I know, Jet database engine could
not read data from a file where file name contains ".". Thereby, the
OleDBAdapter failed to fill data into datatable, and thrown "file not
existing" error.

Actually, the FillSchema method failed, either. But it doesn't throw any
exception. Thus, we misunderstood it works fine. If you check ColumnCount
after you filled the schema, you will notice there is no any column in that
table. This means OleDBAdapter failed on filling schema.

dataAdapter.FillSchema(dataTable, SchemaType.Source);
DataColumnCollection dataColumns = dataTable.Columns;
int fileColumnCount = dataColumns.Count;// I believe the value is Zero.

I didn't test with file which contains dot in it name before. I think this
is the root cause why issue only occur on this file. :)

Hope this helps. Let me know if there is anything unclear. We are glad to
assist you.
Best regards,
Wen Yuan

Delighting our customers is our #1 priority. We welcome your comments and
suggestions about how we can improve the support we provide to you. Please
feel free to let my manager know what you think of the level of service
provided. You can send feedback directly to my manager at:
(e-mail address removed).
==================================================
This posting is provided "AS IS" with no warranties, and confers no rights.
 
W

Wen Yuan Wang [MSFT]

Hello Norman,

Thanks for your reply.
But, I cannot understand what do you mean by "Period is the new space."? Am
I missing anything here?

If you have any more concern or there is anything unclear, please feel free
to let me know. It's my pleasure to assist you.
Have a great day,
Best regards,
Wen Yuan

Delighting our customers is our #1 priority. We welcome your comments and
suggestions about how we can improve the support we provide to you. Please
feel free to let my manager know what you think of the level of service
provided. You can send feedback directly to my manager at:
(e-mail address removed).
==================================================
This posting is provided "AS IS" with no warranties, and confers no rights.
 
N

Norman Diamond

The old tradition was that poorly written Windows programs couldn't handle
filenames with spaces in the filename. The new version can't handle
filenames with periods in the filename.

Anyway I understand the answer. Thank you for explaining the restriction.
 
W

Wen Yuan Wang [MSFT]

Hello Norman,

Thanks for your understanding.
If there is anything you feel we can help with, just feel free to let me
know. I am glad to be of assistance.

Have a great day,
Best regards,
Wen Yuan

Delighting our customers is our #1 priority. We welcome your comments and
suggestions about how we can improve the support we provide to you. Please
feel free to let my manager know what you think of the level of service
provided. You can send feedback directly to my manager at:
(e-mail address removed).
==================================================
This posting is provided "AS IS" with no warranties, and confers no rights.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top