By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
438,868 Members | 1,974 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 438,868 IT Pros & Developers. It's quick & easy.

I need solution for read connection string from text file

P: 2
this code for aspx.cs:

Expand|Select|Wrap|Line Numbers
  1.  string inputString;
  2.         resultLabel.Text = "";
  3.         using (StreamReader streamReader = File.OpenText(@"E:\projects\readtxt\nan.txt"))
  4.         {
  5.             inputString = streamReader.ReadLine();
  6.             while (inputString != null)
  7.             {
  8.                 resultLabel.Text += inputString + "<br />";
  9.                 inputString = streamReader.ReadLine();
  10.             }
  11.         }
text file contains:

string con = new SqlConnection(ConfigurationManager.ConnectionStrin gs["nandhaconnectionstring"].ConnectionString);

i get error The ConnectionString property has not been initialized.
Oct 15 '13 #1

✓ answered by Rabbit

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.

Share this Question
Share on Google+
3 Replies


Rabbit
Expert Mod 10K+
P: 12,370
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.
Oct 15 '13 #2

P: 2
just tell me how to do this because i am beginner to learn asp.net....
Oct 16 '13 #3

Rabbit
Expert Mod 10K+
P: 12,370
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:
Expand|Select|Wrap|Line Numbers
  1. connectionStringFromFile = read line from text file
  2. connection.connectionString = connectionStringFromFile
Where the file ONLY contains the connection string, not code.
Oct 16 '13 #4

Post your reply

Sign in to post your reply or Sign up for a free account.