*/
Are you blogging on PH? Get your free blog.

Other Views

corner
*/

ADONET FAQ - Storing and Retrieving Connection String in/from Text File

How do I store / retrieve the connection string in / from a text file?

You can store the connection string in the text file or an xml file and later retrieve it. Let’s see some example code to write a connection string to the text file and read it back

C# Version
	string connStr = "";
	// get connection string in the connStr variable
	// Write connection string to text file
	StreamWriter sw = new StreamWriter(@"C:\ConnectionString.txt");
	sw.WriteLine(connStr);
	// ...
	// Read connection string from the text file
	StreamReader sr = new StreamReader(@"C:\ConnectionString.txt");
	connStr = sr.ReadLine();


VB.Net Version
      Dim connStr As String = ""
      ' get connection string in the connStr variable
      ' Write connection string to text file
      Dim sw As New StreamWriter("C:\ConnectionString.txt")
      sw.WriteLine(connStr)
      ' ...
      ' Read connection string from the text file
      Dim sr As New StreamReader("C:\ConnectionString.txt")
      connStr = sr.ReadLine()


Back
corner
© 1996-2008 CommunityHeaven LLC. All rights reserved. Reproduction in whole or in part, in any form or medium without express written permission is prohibited.
Violators of this policy may be subject to legal action. Please read our Terms Of Use and Privacy Statement for more information.
North American business development: Nicolai Wadstrom. Publisher: Lars Hagelin.