5
Answers

C#: Need help with reading connection string from file

Photo of salooraja

salooraja

21y
1.7k
1
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)

0
Photo of mrxs1999
NA 19 0 20y
first problem solved i used the following code : protected void FileSaveAs_Click(object sender, EventArgs e) { Object o = null; AxWebBrowser1.ExecWB(SHDocVw.OLECMDID.OLECMDID_SAVEAS, SHDocVw.OLECMDEXECOPT.OLECMDEXECOPT_PROMPTUSER, ref o, ref o); } but i still have the open htm file problem, any ideas ? Thanks
Next Recommended Forum