开发者

How to read from a DBF file on a 64bit OS using VB.Net?

How to read from a DBF file on a 64bit OS u开发者_如何学Gosing VB.Net?


First, you need the access 64bit redistributables, available at: http://www.microsoft.com/downloads/en/details.aspx?familyid=C06B8369-60DD-4B64-A44B-84B371EDE16D&displaylang=en

Then you can configure an ODBC data source in control panel, administrative tools, Data Sources (ODBC).

Then, I was able to do so in C#, with the following; this should be similar in VB.NET:

var connectionString = "Driver={Microsoft dBASE Driver (*.dbf)};" +
                                                      "Driverid=277;" +
                                                      @"Dbq=C:\temp\";

var query = "SELECT * FROM UPDATED" //file is "updated.dbf"


using (var oConn = new OdbcConnection { ConnectionString = connectionString })
            {
                try
                {
                    oConn.Open();
                    var oCmd = oConn.CreateCommand();
                    oCmd.CommandText = Query;

                    var dr = oCmd.ExecuteReader();

                    if (dr.HasRows)
                    {
                        while (dr.Read())
                        {

                // get your data from your dbf!
                        }
                    }
                }
                finally
                {
                    oConn.Close();
                }
            }


You need to compile your program as 32 bit; it will still run fine on a 64 bit OS. Change the platform target to "x86" instead of "Any CPU" or "x64". Then you may use the Visual FoxPro Ole Db Provider to access the dbf file.


Instead of Microsoft.Jet.OLEDB... you must use Microsoft.ACE.OLEDB... in your connection string in Win7. More information can be got from www.connectionstrings.com under accdb section. You can connect to DBF file as table and query for data/schema.

If your Win7 is 64 bit and MS Office is 32 bit installed (Taskmanager winword.exe * 32), the ACE drivers will be installed in 32 bit mode and hence your program/source code will not connect to DBF file.

How to find.

Open 32 bit ODBC emulater at C:\windows\sysWoW64\odbcad32.exe and go to "Drivers" tab. You must see lots of drivers to connect in which you'll find ACE provider.

Open 64 bit ODBC administrator at C:\windows\system32\odbcad32.exe and go to "Drivers" tab. You must see "SQL server" driver only or few drivers specific for 64 bit but not the ACE driver.

Solution

  1. Compile your current program in x86 mode to use the 32 bit emulator drivers.
  2. Another solution is to find if you can uninstall 32 bit MS Office and get 64 bit version. That will solve all issues automaticaly.

Good luck

Venkat

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜