Sure create a table or modify an existing table.
CREATE TABLE Connection
(
Id INT IDENTITY NOT NULL PRIMARY KEY
,ConnectionString VARCHAR(100) NOT NULL
);
INSERT INTO Connection (ConnectionString)
VALUES ('Server=myServerAddress;Database=myDataBase;Trusted_Connection=True;');
I would advise against storing passwords in the connection string when the contents of the table are unencrypted. Setup a domain account with Sql Server privileges to run your IIS app pool or Windows Service under.
const string Query = "SELECT ConnectionString FROM Connection WHERE Id = @Id";
public string GetConnectionString(int id)
{
using(var connection = GetConnection())
using(var command = new SqlCommand(Query, connection))
{
command.Parameters.AddWithValue("@Id", id);
connection.Open();
using(var reader = command.ExecuteReader())
{
if(reader.Read())
{
return Convert.ToString(reader["ConnectionString"]);
}
}
}
}
var connectionString = GetConnectionString(1);
using(var connection = new SqlConnection(connectionString))
{
//logic
}