Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I get a connection string from a text file?

I have developed a Windows application with the backend of SQL Server to insert employee names. I am going to insert the employee details on three databases one by one. So, I like to get connecting values from text file. Whenever I want to change the connection, I just want to enter the login details in the text file.

How can I get a connection string from a text file?

like image 686
Gopi Avatar asked Oct 08 '13 04:10

Gopi


People also ask

How do I get my connection string?

Right-click on your connection and select "Properties". You will get the Properties window for your connection. Find the "Connection String" property and select the "connection string". So now your connection string is in your hands; you can use it anywhere you want.

What is your connection string?

In computing, a connection string is a string that specifies information about a data source and the means of connecting to it. It is passed in code to an underlying driver or provider in order to initiate the connection.


2 Answers

Use an app.config (MSDN) file.

Allows you to configure multiple named connection strings which you can access via the System.Configuration.ConfigurationManager class' ConnectionStrings property

like image 118
Moho Avatar answered Nov 15 '22 04:11

Moho


Plaese try like this

using System;
using System.IO;

class Test 
{

    public static void Main() 
    {
        string txtpath = @"c:\textfile.txt";
        try 
        {
            if (File.Exists(txtpath)) 
            {



            using (StreamReader sr = new StreamReader(txtpath)) 
            {
                while (sr.Peek() >= 0) 
                {
                    string ss = sr.ReadLine();
                     string [] txtsplit = ss.Split(';');

                     //now loop through   array
                     string server=txtsplit[0].Tostring();
                    string userid= split[1].Tostring(); // user id
                   string password= split[2].Tostring(); // password

                }
            }
          }
        } 
        catch (Exception e) 
        {
            Console.WriteLine("Error: {0}", e.ToString());
        }
    }
}
like image 25
Regon Avatar answered Nov 15 '22 05:11

Regon