C # resolves an issue where the Microsoft Jet database engine cannot find objects by reading the DBF file

Source: Internet
Author: User
Tags odbc

Objective

The latest projects need to deal with DBF files often, in the actual scenario, many software needs to interact with some old systems, and these systems are using the FoxPro database, reading DBF files are generally divided into two situations: first; The driver of the installation FoxPro is read, second; no driver is installed, Use ODBC for reading.

Specifically how to set the Dbf/foxpro connection string, you can refer to this article (https://www.connectionstrings.com/dbf-foxpro/)

Scenario One: Installing the FoxPro driver

 You can download the file "Vfpoledbsetup.msi" for installation at Microsoft Official website (https://www.microsoft.com/en-us/download/details.aspx?id=14839). Then use code to read as follows:

1             stringFilePath =@"C:\Temp\test.dbf";//file path, such as: C:\TEMP\TEST.DBF2FileInfo FileInfo =NewFileInfo (filePath);3             stringDirectoryName =Fileinfo.directoryname; //Folder directory 4             stringFileName =Fileinfo.name;5 6OleDbConnection conn =NewOleDbConnection ();7             stringConnStr =@"Provider=vfpoledb.1;data source="+ DirectoryName +"; Collating Sequence=machine";8Conn. ConnectionString =connstr;9 Conn. Open ();Ten  One             stringstrSQL =@"SELECT * from"+FileName; AOleDbDataAdapter da =NewOleDbDataAdapter (strSQL, conn); -DataTable dt =NewDataTable (); -Da. Fill (DT);
Scenario Two: Do not install drivers, use ODBC to read
1         Private voidButton1_Click (Objectsender, EventArgs e)2         {3             Try4             {5                 stringDirectoryPath =@"C:\Temp";//the stored dbf folder directory. 6                 stringFileName =@"test.dbf";//dbf file name, here is TEST.DBF because this is the name of the table, so the suffix. DBF can be omitted, directly test can be. 7                 stringstrconn =@"driver={microsoft DBASE Driver (*.dbf)};D riverid=277;dbq="+DirectoryPath;8 9System.Data.Odbc.OdbcConnection Odbcconn =NewSystem.Data.Odbc.OdbcConnection ();TenOdbcconn.connectionstring =strconn; One Odbcconn.open (); A  -                 stringstrSQL =@"SELECT * from"+FileName; -  theOdbcDataAdapter ODA =NewOdbcDataAdapter (strSQL, odbcconn); -DataTable dt =NewDataTable (); - ODA. Fill (DT); -  +Datagridview1.datasource =DT; - odbcconn.close (); +             } A             Catch(Exception ex) at             { - MessageBox.Show (ex. Message); -             } -}
ODBC Read exception problem

In the actual process, we often encounter a problem that prompts the Microsoft Jet database engine to find no object .

But! Detected n times, the name and path are not wrong, the internet also looked up a lot of relevant information, but have not been resolved (the problem is the same, but the solution is not valid). After repeated testing, finally found the problem:DBF file name can not exceed 8 characters, once more than 8 characters, will report such a mistake. (Why is it so unclear ~%>_<%)

  Workaround: Control the DBF file name to within 8 characters, temporarily unable to find a better method

PS: If in doubt, please leave a message, without permission, may not be reproduced privately, reproduced please indicate the source: http://www.cnblogs.com/xuliangxing/p/7690709.html

  

  

C # resolves an issue where the Microsoft Jet database engine cannot find objects by reading the DBF file

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.