Sql Reading The Connection String
Is it possible to read the connection string from a txt file, by using the direct path of the said .txt file witch contains the connection string? The code is the following, I have
Solution 1:
In short: no, it is not possible to do it like this. You need an object that can read from a stream first, obtain you connection string using that reader and then pass the connection string to the constructor of your SqlConnection object instance.
string connectionString;
var path = @"C:\Users\Administrator\Desktop\connstring.txt";
using (StreamReader sr = new StreamReader(path))
{
connectionString = sr.ReadLine();
}
var connection = new SqlConnection(connectionString);
Post a Comment for "Sql Reading The Connection String"