Certain users of an application are receiving exceptions when filling a dataset from a DBF file using the VisualFoxPro 9.0 driver. I can't seem to figure out what's going on because the error always happens for some users, never happens for other users and sometimes (based on the location of the .DBF file) happens for yet other users. I've ensured that all users have the visual fox pro 9.0 driver is installed. Here's the bit of code causing the problem (leieLoc is the location of the DBF file):
string constr = "Provider=VFPOLEDB.1;Data Source=" + this.leieLoc + ";";
OleDbConnection con = new OleDbConnection(constr);
string sql = "select * from " + this.leieLoc + ";";
OleDbCommand cmd = new OleDbCommand(sql, con);
con.Open();
DataSet ds = new DataSet();
OleDbDataAdapter da = new OleDbDataAdapter(cmd);
da.Fill(ds);
da.Dispose();
ds.Dispose();
cmd.Dispose();
con.Dispose();
con.Close();
I do wish that I were able to change the format of the database, however I cannot as it's released by a third party.
The error stack trace is as follows:
System.Data.OleDb.OleDbException (0x80040E14): Command contains unrecognized phrase/keyword.
at System.Data.OleDb.OleDbCommand.ExecuteCommandTextErrorHandling(OleDbHResult hr)
at System.Data.OleDb.OleDbCommand.ExecuteCommandTextForSingleResult(tagDBPARAMS dbParams, Object& executeResult)
at System.Data.OleDb.OleDbCommand.ExecuteCommandText(Object& executeResult)
at System.Data.OleDb.OleDbCommand.ExecuteCommand(CommandBehavior behavior, Object& executeResult)
at System.Data.OleDb.OleDbCommand.ExecuteReaderInternal(CommandBehavior behavior, String method)
at System.Data.OleDb.OleDbCommand.ExecuteReader(CommandBehavior behavior)
at System.Data.OleDb.OleDbCommand.System.Data.IDbCommand.ExecuteReader(CommandBehavior behavior)
at System.Data.Common.DbDataAdapter.FillInternal(DataSet dataset, DataTable[] datatables, Int32 startRecord, Int32 maxRecords, String srcTable, IDbCommand command, CommandBehavior behavior)
at System.Data.Common.DbDataAdapter.Fill(DataSet dataSet, Int32 startRecord, Int32 maxRecords, String srcTable, IDbCommand command, CommandBehavior behavior)
at System.Data.Common.DbDataAdapter.Fill(DataSet dataSet)
at ExclusionSearcher.Searching.ThreadProcesser.searchLeie(List`1 names)
Any help would be greatly appreciated; I've no idea what could be causing the problem here.
You have problem with
string sql = "select * from " + this.leieLoc + ";";
string constr = "Provider=VFPOLEDB.1;Data Source=" + this.leieLoc + ";";
First your table and DataSource can not be the same.If the error is Command contains unrecognized phrase/keyword
I will suppose that the connection string is correct. That means you should fix your tableName
in the sql string.
Also there is no need to call Close
and Dispose
on the connection. Only Close is enough ! There is no need to Dispose
the DataSet. Also you can use using instead of Dispose, because in your code if exception happen the resources will be not Dispose. If you want to use directly Dispose, you need to write it like this:
try
{
conn.Open()
}
catch(Exception)
{
throw;
}
finnaly
{
conn.Close();
}
In this case you guarantee that the connection will be closed. This should be done for the Adapter too.
Try to enclose this.leieLoc
variable in double quotes in your SELECT
statement.
User contributions licensed under CC BY-SA 3.0