How do I create connection string programmatically to MS SQL in Entity Framework 6?
I\'m using c# and WPF and I was wondering if someone could show me how or link me to
I investigated this question today. in my opinion the easiest solution is not mentioned above.
Why not use the SqlConnectionStringBuilder class? (using System.Data.SqlClient)
Here a simple example how to use it.
SqlConnectionStringBuilder sqlb = new SqlConnectionStringBuilder(getConnectionString(DATABASENAME);
using (SqlConnection connection = new SqlConnection(sqlb.ConnectionString))
...
)
// works for EF Core, should also work for EF6 (haven't tried this)
private static string getConnectionString(string databaseName)
{
return "Data Source=SQLSERVERNAME;Initial Catalog="+databaseName+";Integrated Security=True";
}