PDA

View Full Version : C# Connecting to .dbf Files


Basscyst
05-08-2009, 12:33 AM
Having a bit of trouble connecting to a .dbf (Foxpro/Dbase) file.


OdbcConnection Conn = new OdbcConnection("Driver={Microsoft dBASE Driver (*.dbf)};DriverID=277;Dbq=C:\\Inetpub\\wwwroot\\LegAid\\08Counties\\c001_g08_sov_data_by_g08_srprec. dbf;");
String SQL = "SELECT * FROM c001_g08_sov_data_by_g08_srprec.dbf";
Conn.Open();
OdbcCommand MyCommand = new OdbcCommand(SQL,Conn);
OdbcDataReader dr = MyCommand.ExecuteReader();
while (dr.Read())
{
Response.Write(dr[0].ToString() + "<br />");
}


I get the folowing error:

ERROR [HY024] [Microsoft][ODBC dBase Driver] '(unknown)' is not a valid path. Make sure that the path name is spelled correctly and that you are connected to the server on which the file resides.
ERROR [IM006] [Microsoft][ODBC Driver Manager] Driver's SQLSetConnectAttr failed
ERROR [HY024] [Microsoft][ODBC dBase Driver] '(unknown)' is not a valid path. Make sure that the path name is spelled correctly and that you are connected to the server on which the file resides.


I did a Response.Write(Conn.ConnectionString) and it all looks right. When I try to run the file pointed to in the written Con String it pulls it right up. Just to test if it was a permission issue I set the IIS account to myself, an admin on the machine after simply impersonating myself when the code ran. Still nothing. It doesn't seem to be finding the file.

Am I using the wrong connection string? The file is on the servers local file system. Most every resource I've found solving this issue deals with a .dbf file on a remote machine, which doesn't pertain here.

Thanks.

Basscyst
05-11-2009, 08:03 PM
After much frustration, trying different connection strings, various users with various permissions. It turns out the file name of the data file was too long. Apparently the file cannot have more than 8(?) characters in it's name otherwise the connection will fail and the file cannot be found.

Gotta say, that's about the stupidest crap ever. :mad: