I need solution for read connection string from text file

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • nandha2808
    New Member
    • Oct 2013
    • 2

    I need solution for read connection string from text file

    this code for aspx.cs:

    Code:
     string inputString;
            resultLabel.Text = "";
            using (StreamReader streamReader = File.OpenText(@"E:\projects\readtxt\nan.txt"))
            {
                inputString = streamReader.ReadLine();
                while (inputString != null)
                {
                    resultLabel.Text += inputString + "<br />";
                    inputString = streamReader.ReadLine();
                }
            }
    text file contains:

    string con = new SqlConnection(C onfigurationMan ager.Connection Strings["nandhaconnecti onstring"].ConnectionStri ng);

    i get error The ConnectionStrin g property has not been initialized.
    Last edited by Rabbit; Oct 15 '13, 02:42 PM. Reason: Please use [CODE] and [/CODE] tags when posting code or formatted data.
  • Rabbit
    Recognized Expert MVP
    • Jan 2007
    • 12517

    #2
    Please use code tags when posting code or formatted data.

    Reading data from a text file does not run code. You need to put the code in your source files and use the text file to supply only the string.

    Comment

    • nandha2808
      New Member
      • Oct 2013
      • 2

      #3
      just tell me how to do this because i am beginner to learn asp.net....

      Comment

      • Rabbit
        Recognized Expert MVP
        • Jan 2007
        • 12517

        #4
        You already know how, you just need to move the code around. It's all there.

        You know how to open and read from a file. You just need to move the code out of your text file and into the rest of the source code.

        In pseudo code, you need to do something like this:
        Code:
        connectionStringFromFile = read line from text file
        connection.connectionString = connectionStringFromFile
        Where the file ONLY contains the connection string, not code.

        Comment

        Working...