?
Solved

Connect String for Dbase files VS C#

Posted on 2014-12-18
2
Medium Priority
?
486 Views
Last Modified: 2014-12-19
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 */
            tr.Close();

            try
            {
                DataConnection = new System.Data.SqlClient.SqlConnection(ConnectionString);
                DataConnection.Open();
            }
            catch (Exception ex)
            {
                string eMsg = "Error-Opening SQL connection: " + ex.Message;
                if (StackTraceWanted) eMsg += "\n" + ex.StackTrace;
                MessageBox.Show(eMsg);
            }
           
            return DataConnection;
        }
-------------------------------------------------------------------PROD.INI---------------------------------------------------------------------------------
Data Source=PROD;Initial Catalog=PROD;User Id=sa;Password=password;Connection Timeout=60
0
Comment
Question by:rwheeler23
2 Comments
 
LVL 25

Accepted Solution

by:
chaau earned 2000 total points
ID: 40508482
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:
-------------------------------------------------------------------PROD.INI---------------------------------------------------------------------------------
Data Source=Driver={Microsoft dBASE Driver (*.dbf)};DriverID=277;Dbq=c:\mydbpath;

Open in new window

0
 

Author Closing Comment

by:rwheeler23
ID: 40508848
That did the trick. I am now going to submit another case about how to access the data in the dbf file.
0

Featured Post

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article describes a simple method to resize a control at runtime.  It includes ready-to-use source code and a complete sample demonstration application.  We'll also talk about C# Extension Methods. Introduction In one of my applications…
We all know that functional code is the leg that any good program stands on when it comes right down to it, however, if your program lacks a good user interface your product may not have the appeal needed to keep your customers happy. This issue can…
Exchange organizations may use the Journaling Agent of the Transport Service to archive messages going through Exchange. However, if the Transport Service is integrated with some email content management application (such as an anti-spam), the admin…
Please read the paragraph below before following the instructions in the video — there are important caveats in the paragraph that I did not mention in the video. If your PaperPort 12 or PaperPort 14 is failing to start, or crashing, or hanging, …
Suggested Courses

862 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question