1
votes

When trying to connect to a remote database with enable-migrations, I get an error that insists on checking the connection string, all I want to do is connect my context to the remote database to give and map a "User" class with "migration", here is the connection string:

<add name="TransformerANDConnectDB" connectionString="data source=REMOTE_SERVER_xx ;initial catalog=TransformerANDConnectDB;user id=xxx ;password=xxx ;Integrated Security=True ;MultipleActiveResultSets=True;"  providerName="System.Data.SqlClient" />

Otherwise I present you the error occured after enabling migration:

 ---> System.Data.SqlClient.SqlException: Échec de l'ouverture de session de l'utilisateur 'ADSLOCAL\G558253'.
  à  System.Data.SqlClient.SqlInternalConnectionTds..ctor(DbConnectionPoolIdentity identity, SqlConnectionString connectionOptions, SqlCredential credential, Object providerInfo, String newPassword, SecureString newSecurePassword, Boolean redirectedUserInstance, SqlConnectionString 

An error occurred accessing the database. This usually means that the connection to the database failed. Check that the connection string is correct and that the appropriate DbContext constructor is being used to specify it or find it in the application's config file. See http://go.microsoft.com/fwlink/?LinkId=386386 for information on DbContext and connections. See the inner exception for details of the failure.

This is my context file:

public class TransformerConnectMEContext  :DbContext 
{
    public TransformerConnectMEContext()
            : base("Name=TransformerANDConnectDB")
    {
        Database.SetInitializer<TransformerConnectMEContext>(new TransformerConnectMEContextInitializer());
    }
    public DbSet<User> Users { get; set; }
}

Inner exception:

System.Data.Entity.Core.ProviderIncompatibleException: The provider did not return a ProviderManifestToken string. ---> System.Data.SqlClient.SqlException: Échec de l'ouverture de session de l'utilisateur 'ADSLOCAL\XXXX'.
   à System.Data.SqlClient.SqlInternalConnectionTds..ctor(DbConnectionPoolIdentity identity, SqlConnectionString connectionOptions, SqlCredential credential, Object providerInfo, String newPassword, SecureString newSecurePassword, Boolean redirectedUserInstance, SqlConnectionString userConnectionOptions, SessionData reconnectSessionData, DbConnectionPool pool, String accessToken, Boolean applyTransientFaultHandling, SqlAuthenticationProviderManager sqlAuthProviderManager)
   à System.Data.SqlClient.SqlConnectionFactory.CreateConnection(DbConnectionOptions options, DbConnectionPoolKey poolKey, Object poolGroupProviderInfo, DbConnectionPool pool, DbConnection owningConnection, DbConnectionOptions userOptions)
   à System.Data.ProviderBase.DbConnectionFactory.CreatePooledConnection(DbConnectionPool pool, DbConnection owningObject, DbConnectionOptions options, DbConnectionPoolKey poolKey, DbConnectionOptions userOptions)
   à System.Data.ProviderBase.DbConnectionPool.CreateObject(DbConnection owningObject, DbConnectionOptions userOptions, DbConnectionInternal oldConnection)
   à System.Data.ProviderBase.DbConnectionPool.UserCreateRequest(DbConnection owningObject, DbConnectionOptions userOptions, DbConnectionInternal oldConnection)
   à System.Data.ProviderBase.DbConnectionPool.TryGetConnection(DbConnection owningObject, UInt32 waitForMultipleObjectsTimeout, Boolean allowCreate, Boolean onlyOneCheckConnection, DbConnectionOptions userOptions, DbConnectionInternal& connection)
   à System.Data.ProviderBase.DbConnectionPool.TryGetConnection(DbConnection owningObject, TaskCompletionSource 1 retry, DbConnectionOptions userOptions, DbConnectionInternal& connection)
   à System.Data.ProviderBase.DbConnectionFactory.TryGetConnection(DbConnection owningConnection, TaskCompletionSource 1 retry, DbConnectionOptions userOptions, DbConnectionInternal oldConnection, DbConnectionInternal& connection)
   à System.Data.ProviderBase.DbConnectionInternal.TryOpenConnectionInternal(DbConnection outerConnection, DbConnectionFactory connectionFactory, TaskCompletionSource`1 retry, DbConnectionOptions userOptions)
   à System.Data.ProviderBase.DbConnectionClosed.TryOpenConnection(DbConnection outerConnection, DbConnectionFactory connectionFactory, TaskCompletionSource`1 retry, DbConnectionOptions userOptions)
   à System.Data.SqlClient.SqlConnection.TryOpenInner(TaskCompletionSource 1 retry)
   à System.Data.SqlClient.SqlConnection.TryOpen(TaskCompletionSource 1 retry)
   à System.Data.SqlClient.SqlConnection.Open()
   à System.Data.Entity.Infrastructure.Interception.DbConnectionDispatcher.<Open>b__38(DbConnection t, DbConnectionInterceptionContext c)
   à System.Data.Entity.Infrastructure.Interception.InternalDispatcher 1.Dispatch[TTarget,TInterceptionContext](TTarget target, Action 2 operation, TInterceptionContext interceptionContext, Action 3 executing, Action 3 executed)
   à System.Data.Entity.Infrastructure.Interception.DbConnectionDispatcher.Open(DbConnection connection, DbInterceptionContext interceptionContext)
   à System.Data.Entity.SqlServer.SqlProviderServices.<>c__DisplayClass31.<UsingConnection>b__2f()
   à System.Data.Entity.SqlServer.DefaultSqlExecutionStrategy.<>c__DisplayClass1.<Execute>b__0()
   à System.Data.Entity.SqlServer.DefaultSqlExecutionStrategy.Execute[TResult](Func 1 operation)
   à System.Data.Entity.SqlServer.DefaultSqlExecutionStrategy.Execute(Action operation)
   à System.Data.Entity.SqlServer.SqlProviderServices.UsingConnection(DbConnection sqlConnection, Action 1 act)
   à System.Data.Entity.SqlServer.SqlProviderServices.UsingMasterConnection(DbConnection sqlConnection, Action 1 act)
   à System.Data.Entity.SqlServer.SqlProviderServices.GetDbProviderManifestToken(DbConnection connection)
   à System.Data.Entity.Core.Common.DbProviderServices.GetProviderManifestToken(DbConnection connection)
   --- Fin de la trace de la pile d'exception interne ---
   à System.Data.Entity.Core.Common.DbProviderServices.GetProviderManifestToken(DbConnection connection)
   à System.Data.Entity.Utilities.DbProviderServicesExtensions.GetProviderManifestTokenChecked(DbProviderServices providerServices, DbConnection connection)
   --- Fin de la trace de la pile d'exception interne ---
   à System.Data.Entity.Utilities.DbProviderServicesExtensions.GetProviderManifestTokenChecked(DbProviderServices providerServices, DbConnection connection)
   à System.Data.Entity.Infrastructure.DefaultManifestTokenResolver.<>c__DisplayClass1.<ResolveManifestToken>b__0(Tuple 3 k)
   à System.Collections.Concurrent.ConcurrentDictionary 2.GetOrAdd(TKey key, Func 2 valueFactory)
   à System.Data.Entity.Infrastructure.DefaultManifestTokenResolver.ResolveManifestToken(DbConnection connection)`
  
1
And did you check the inner exception, as advised, to find out exactly why it failed? The check is there to make sure the connection will work. In this case, it seems it doesn't. You need to work out the precise reason. - ADyson
@ADyson the inner exception is not in the post ? the inner exception is too long to publish all of it. - Khadhri Hamza
Well what is the main message from the inner exception? I doubt we need the entire stack trace, just the message. - ADyson
@ADyson i have updated the post. - Khadhri Hamza

1 Answers

3
votes

In connection string set Integrated Security to false.

When Integrated Security is set false, User ID and Password are specified in the connection. When true, the current Windows account credentials are used for authentication