[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

microsoft.public.dotnet.framework.odbcnet

Can't access certain files with odbc text driver

Bala Nair

3/13/2002 8:29:00 PM

I've written a small test harness to test file import using delimited text
files. I'm using the odbc managed provider to read the data into a dataset.
Here's what my connection string and command look like:

connection string : "Provider=MSDASQL;DSN=CSV"

where CSV is a user data source created with the odbc data source
administrator pointing to a folder on my local system. I browse to the
folder and pick a file named test1.csv.

sql command : "SELECT * from test1.csv"

Here's the core code that fills the dataset:

if (strCnn != null)
{
OdbcConnection cnn = new OdbcConnection(strCnn);
string cmdText = "SELECT * from " + this.m_filename;
OdbcDataAdapter adapter = new OdbcDataAdapter();
adapter.SelectCommand = new OdbcCommand(cmdText, cnn);

if (rows == -1)
{
adapter.Fill(dataset, this.m_filename);
}
else
{
adapter.Fill(dataset, 0, rows, this.m_filename);
}
return true;
}

This works fine if the filename is test1.csv, but it throws an exception if
I remove the extension. The exception is:

{"ERROR [42000] [Microsoft][ODBC Text Driver] Cannot update. Database or
object is read-only." }

Is this a bogus error message or do I have my dataset configured wrong?



Bala Nair
Intranets.com



5 Answers

(Steven Bras [MS])

3/15/2002 10:17:00 PM

0

Bala Nair

3/16/2002 2:09:00 PM

0

Thanks - I think I'm starting to get a handle on the issues. I'm writing a
data import/export interface for a web based service and I want to use odbc
for reading the import files and writing the export files. I realized that I
really want a dsnless connection to the Jet engine, using extended
properties that will mimic what's in a schema.ini file. Is there any
documentation on what the supported extended properties for Jet are? Also
what are the differences between using the oledb provider for Microsoft Jet
and the odbc provider? Are there any performance issues, is one more stable
than the other, will one work better in a high capacity environment? Thanks
again.

Bala Nair
Intranets.com



(Steven Bras [MS])

3/18/2002 6:17:00 PM

0

Bala Nair

3/19/2002 11:00:00 PM

0

Ok, it's getting better, but still not perfect. I can now read generic CSV
files with and w/o a header row, but it doesn't seem to be able to handle
tab delimited files correctly. Here's what I'm using for connection
strings:

For files with a header row:

"Provider=Microsoft.Jet.OLEDB.4.0;Data Source=C:\WebSite\Import;Extended
Properties="text;HDR=YES;FMT=Delimited;";"

For file w/o a header row:

"Provider=Microsoft.Jet.OLEDB.4.0;Data Source=C:\WebSite\Import;Extended
Properties="text;HDR=NO;FMT=Delimited;";"

CSV files work fine, but tab delimited files come out as one column per row
with all the data concatenated. Here's a code snippet for getting the data:

OleDbConnection cnn = new OleDbConnection(m_strCnn);
OleDbDataAdapter adapter = new OleDbDataAdapter();
adapter.SelectCommand = new OleDbCommand(m_strCmd, cnn);

if (rows == -1)
{
adapter.Fill(dataset, this.m_filename);
}
else
{
adapter.Fill(dataset, 0, rows, this.m_filename);
}


I can get tab delimited files to work if I use a DSN connection and make an
entry in schema.ini for the file I'm going to import. eg.

[test.txt]
ColNameHeader=False
Format=TabDelimited
MaxScanRows=3
CharacterSet=ANSI

[test2.txt]
ColNameHeader=True
Format=TabDelimited
MaxScanRows=3
CharacterSet=ANSI

Any idea what's going on?

Bala Nair
Intranets.com




(Steven Bras [MS])

3/20/2002 6:58:00 PM

0