You can get the database name from the connection string if it is specified there. For example, this will work if you use a SQL server:
public class BaseMigration : Migration
{
public override void Up()
{
System.Data.SqlClient.SqlConnectionStringBuilder builder =
new System.Data.SqlClient.SqlConnectionStringBuilder(ConnectionString);
var databaseName = builder.InitialCatalog;
}
}
Otherwise, use one of the available
: System.Data.Common.DbConnectionStringBuilder
System.Data.EntityClient.EntityConnectionStringBuilder
System.Data.Odbc.OdbcConnectionStringBuilder
System.Data.OleDb.OleDbConnectionStringBuilder
System.Data.OracleClient.OracleConnectionStringBuilder
See fooobar.com/questions/30023 / ... for more information .
source
share