salooraja

salooraja

  • NA
  • 12
  • 0

C#: Need help with reading connection string from file

Nov 6 2003 2:45 PM
Hi, I am using VS.NET 2003 and C#. I am trying to create a SqlConnection by reading in the connection string from a text file. But this does not seem to work. I would really appreciate some help as to how I can accomplish this task. Here is my example code: FileStream fs = new FileStream(@"C:\connPath.txt" , FileMode.Open, FileAccess.Read); StreamReader m_streamReader = new StreamReader(fs); path = m_streamReader.ReadLine(); SqlConnection sqlConn = new SqlConnection(path); ******* If I use the following it works just fine: path = "data source = Saloo\\VSdotNET;database=Test_DB;trusted_connection=yes"; SqlConnection sqlConn = new SqlConnection(path); ******* I have no clue at this moment as to how to fix this problem. I would really appreciate some help. Thanks P.S. I have checked the string variable, it does pick up the connection string from the file but when I assign it to the SqlConnection it crashes.

Answers (5)