Hello I have more than one project connecting to a certain DB that is CodeFirst Entity Framework.
All Projects are able to connect successfully except for one stubbo
The argument of the used base DbContext
constructor is called nameOrConnectionString
. Hence it supports a name of a connection string from the configuration file, or like in your case an actual connection string.
The problem with the later is that it doesn't allow specifying the provider name as with the former coming from the configuration, in which case EF uses the one specified in the defaultConnectionFactory
configuration element, which in your case is System.Data.Entity.Infrastructure.SqlConnectionFactory
, in other words - Sql Server, hence the port
not supported exception.
There are several ways to fix the issue.
(A) Change the defaultConnectionFactory
configuration:
(B) Use named configuration connection string and specify explicitly the provider:
and change the constructor to
public MyDB()
{
// ...
}
or if the name is different than your DbContext
derived class name:
public MyDB() : base(connection_string_name)
{
// ...
}
(C) Use DbConfigurationTypeAttribute:
[DbConfigurationType(typeof(MySql.Data.Entity.MySqlEFConfiguration))]
public class MyDB : DbContext
{
// ...
}