Solved

Connect String for Dbase files VS C#

Posted on 2014-12-18
2
303 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 24

Accepted Solution

by:
chaau earned 500 total points
Comment Utility
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
Comment Utility
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

What Security Threats Are You Missing?

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

This article introduced a TextBox that supports transparent background.   Introduction TextBox is the most widely used control component in GUI design. Most GUI controls do not support transparent background and more or less do not have the…
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…
This video shows how to remove a single email address from the Outlook 2010 Auto Suggestion memory. NOTE: For Outlook 2016 and 2013 perform the exact same steps. Open a new email: Click the New email button in Outlook. Start typing the address: …
When you create an app prototype with Adobe XD, you can insert system screens -- sharing or Control Center, for example -- with just a few clicks. This video shows you how. You can take the full course on Experts Exchange at http://bit.ly/XDcourse.

762 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

Need Help in Real-Time?

Connect with top rated Experts

8 Experts available now in Live!

Get 1:1 Help Now