Solved

Connect String for Dbase files VS C#

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

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Article by: Ivo
C# And Nullable Types Since 2.0 C# has Nullable(T) Generic Structure. The idea behind is to allow value type objects to have null values just like reference types have. This concerns scenarios where not all data sources have values (like a databa…
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…
In this video, viewers are given an introduction to using the Windows 10 Snipping Tool, how to quickly locate it when it's needed and also how make it always available with a single click of a mouse button, by pinning it to the Desktop Task Bar. Int…
Monitoring a network: why having a policy is the best policy? Michael Kulchisky, MCSE, MCSA, MCP, VTSP, VSP, CCSP outlines the enormous benefits of having a policy-based approach when monitoring medium and large networks. Software utilized in this v…

724 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