• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 530
  • Last Modified:

Connect String for Dbase files VS C#

I have been charged with having to read a bunch of dbase(dbf) files and inserting that data into MS SQL. I have used the code below to connect SQL database but my question is how do I change both this code plus the INI file that contains the connection string to accommodate dbase files? The INI file is at the bottom.

        private SqlConnection GetConnection()
            /* Create reader and open file containing connection string */
            TextReader tr = new StreamReader(@"PROD.INI");

            /* Read line containing the connection string */
            ConnectionString = tr.ReadLine();

            /* Close the stream */

                DataConnection = new System.Data.SqlClient.SqlConnection(ConnectionString);
            catch (Exception ex)
                string eMsg = "Error-Opening SQL connection: " + ex.Message;
                if (StackTraceWanted) eMsg += "\n" + ex.StackTrace;
            return DataConnection;
Data Source=PROD;Initial Catalog=PROD;User Id=sa;Password=password;Connection Timeout=60
1 Solution
It is not only the ini file you need to change. The DataConnection should be:
  DataConnection = new System.Data.Odbc.OdbcConnection(ConnectionString);

Open in new window

The connection string will be:
Data Source=Driver={Microsoft dBASE Driver (*.dbf)};DriverID=277;Dbq=c:\mydbpath;

Open in new window

rwheeler23Author Commented:
That did the trick. I am now going to submit another case about how to access the data in the dbf file.
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now