I actually have method for creating dynamically sql connection string that reads it's information from .txt file depending on path which is hard-coded. Now there is a problem that if the user installs exe of this project. The path should depend on where the user installed the exe program - usually Program files, so I need to search selected folder and search it for that .txt file. I was wondering about it for quiet long time. Searched through the internet but didn't find anything helpful. Atleast I will psot my current dynamic connection string.
May I please ask you for any kind of help? Thank you so much for your time. I appreciate that.
internal static class DataSource
{
private static string _ConnectionString;
public static string ConnectionString
{
get
{
if (_ConnectionString == null)
_ConnectionString = FunctionToDynamicallyCreateConnectionstring();
return _ConnectionString;
}
}
private static string FunctionToDynamicallyCreateConnectionstring()
{
string path = "C:\\Users\\marek\\Documents\\Visual Studio 2012\\Projects\\tours\\tours\\sql_string.txt";
StreamReader sr = new StreamReader(File.Open(path, FileMode.Open));
SqlConnectionStringBuilder cb = new SqlConnectionStringBuilder();
cb.DataSource = DecodeFrom64(sr.ReadLine());
cb.InitialCatalog = DecodeFrom64(sr.ReadLine());
cb.UserID = DecodeFrom64(sr.ReadLine());
cb.Password = DecodeFrom64(sr.ReadLine());
return cb.ToString();
}