Solved

Connect String for Dbase files VS C#

Posted on 2014-12-18
2
367 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
2 Comments
 
LVL 25

Accepted Solution

by:
chaau earned 500 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: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

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 is for Object-Oriented Programming (OOP) beginners. An Interface contains declarations of events, indexers, methods and/or properties. Any class which implements the Interface should provide the concrete implementation for each Inter…
Entity Framework is a powerful tool to help you interact with the DataBase but still doesn't help much when we have a Stored Procedure that returns more than one resultset. The solution takes some of out-of-the-box thinking; read on!
Nobody understands Phishing better than an anti-spam company. That’s why we are providing Phishing Awareness Training to our customers. According to a report by Verizon, only 3% of targeted users report malicious emails to management. With compan…

726 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