Quando EF tenta di connettersi al database sql di Azure (forse quando tenta di aprire una connessione al database, non è sicuro) tenta di connettersi/accedere al master database, la domanda è: perché?Framework Entity, codice prima: Evitare connessioni indesiderate al database master azure
L'utente sulla stringa di connessione non può connettersi al database master, da quello che posso vedere registrato, gli errori vengono visualizzati da EF che tenta senza successo di accedere al database master con l'utente, ma funzionalmente l'applicazione funziona correttamente (The l'app non richiede l'accesso al master db per fare qualcosa).
Dalla mia ricerca sembra più simile a this issue, ma questo è stato chiuso come non riproducibile e non sono sicuro se questo si verifica quando si tenta di ottenere ProviderManifestToken.
Quindi, dato un utente del database con le giuste autorizzazioni sul database di cui ha bisogno e la stringa di connessione che lo riflette, perché EF tenta di connettersi al database master?
stringa di connessione di esempio per il contesto
Server=tcp:MyServer;Database=MyDb;User ID=MyDatabaseUser;Password=*****;Trusted_Connection=False;Encrypt=True;Connection Timeout=30;TrustServerCertificate=False;
messaggio di errore log di seguito:
15-05-07 04:06:16.404 System.Data.SqlClient.SqlException (0x80131904): The server principal "MyDatabaseUser" is not able to access the database "master" under the current security context.
Database 'master' on server 'MyServer' is not currently available. Please retry the connection later. If the problem persists, contact customer support, and provide them the session tracing ID of '69955F47-7746-41560-A03C-807FB9A56478A'.
Login failed for user 'MyDatabaseUser'.
at System.Data.SqlClient.SqlInternalConnection.OnError(SqlException exception, Boolean breakConnection, Action`1 wrapCloseInAction)
at System.Data.SqlClient.TdsParser.ThrowExceptionAndWarning(TdsParserStateObject stateObj, Boolean callerHasConnectionLock, Boolean asyncClose)
at System.Data.SqlClient.TdsParser.TryRun(RunBehavior runBehavior, SqlCommand cmdHandler, SqlDataReader dataStream, BulkCopySimpleResultSet bulkCopyHandler, TdsParserStateObject stateObj, Boolean& dataReady)
at System.Data.SqlClient.TdsParser.Run(RunBehavior runBehavior, SqlCommand cmdHandler, SqlDataReader dataStream, BulkCopySimpleResultSet bulkCopyHandler, TdsParserStateObject stateObj)
at System.Data.SqlClient.SqlInternalConnectionTds.CompleteLogin(Boolean enlistOK)
at System.Data.SqlClient.SqlInternalConnectionTds.AttemptOneLogin(ServerInfo serverInfo, String newPassword, SecureString newSecurePassword, Boolean ignoreSniOpenTimeout, TimeoutTimer timeout, Boolean withFailover)
at System.Data.SqlClient.SqlInternalConnectionTds.LoginNoFailover(ServerInfo serverInfo, String newPassword, SecureString newSecurePassword, Boolean redirectedUserInstance, SqlConnectionString connectionOptions, SqlCredential credential, TimeoutTimer timeout)
at System.Data.SqlClient.SqlInternalConnectionTds.OpenLoginEnlist(TimeoutTimer timeout, SqlConnectionString connectionOptions, SqlCredential credential, String newPassword, SecureString newSecurePassword, Boolean redirectedUserInstance)
at System.Data.SqlClient.SqlInternalConnectionTds..ctor(DbConnectionPoolIdentity identity, SqlConnectionString connectionOptions, SqlCredential credential, Object providerInfo, String newPassword, SecureString newSecurePassword, Boolean redirectedUserInstance, SqlConnectionString userConnectionOptions, SessionData reconnectSessionData)
at System.Data.SqlClient.SqlConnectionFactory.CreateConnection(DbConnectionOptions options, DbConnectionPoolKey poolKey, Object poolGroupProviderInfo, DbConnectionPool pool, DbConnection owningConnection, DbConnectionOptions userOptions)
at System.Data.ProviderBase.DbConnectionFactory.CreatePooledConnection(DbConnectionPool pool, DbConnection owningObject, DbConnectionOptions options, DbConnectionPoolKey poolKey, DbConnectionOptions userOptions)
at System.Data.ProviderBase.DbConnectionPool.CreateObject(DbConnection owningObject, DbConnectionOptions userOptions, DbConnectionInternal oldConnection)
at System.Data.ProviderBase.DbConnectionPool.UserCreateRequest(DbConnection owningObject, DbConnectionOptions userOptions, DbConnectionInternal oldConnection)
at System.Data.ProviderBase.DbConnectionPool.TryGetConnection(DbConnection owningObject, UInt32 waitForMultipleObjectsTimeout, Boolean allowCreate, Boolean onlyOneCheckConnection, DbConnectionOptions userOptions, DbConnectionInternal& connection)
at System.Data.ProviderBase.DbConnectionPool.TryGetConnection(DbConnection owningObject, TaskCompletionSource`1 retry, DbConnectionOptions userOptions, DbConnectionInternal& connection)
at System.Data.ProviderBase.DbConnectionFactory.TryGetConnection(DbConnection owningConnection, TaskCompletionSource`1 retry, DbConnectionOptions userOptions, DbConnectionInternal oldConnection, DbConnectionInternal& connection)
at System.Data.ProviderBase.DbConnectionInternal.TryOpenConnectionInternal(DbConnection outerConnection, DbConnectionFactory connectionFactory, TaskCompletionSource`1 retry, DbConnectionOptions userOptions)
at System.Data.SqlClient.SqlConnection.TryOpenInner(TaskCompletionSource`1 retry)
at System.Data.SqlClient.SqlConnection.TryOpen(TaskCompletionSource`1 retry)
at System.Data.SqlClient.SqlConnection.Open()
at System.Data.Entity.Infrastructure.Interception.InternalDispatcher`1.Dispatch[TTarget,TInterceptionContext](TTarget target, Action`2 operation, TInterceptionContext interceptionContext, Action`3 executing, Action`3 executed)
at System.Data.Entity.Infrastructure.Interception.DbConnectionDispatcher.Open(DbConnection connection, DbInterceptionContext interceptionContext)
at System.Data.Entity.SqlServer.SqlProviderServices.<>c__DisplayClass33.<UsingConnection>b__32()
at System.Data.Entity.Infrastructure.DbExecutionStrategy.<>c__DisplayClass1.<Execute>b__0()
at System.Data.Entity.Infrastructure.DbExecutionStrategy.Execute[TResult](Func`1 operation)
ClientConnectionId:5a5e2892-0d1f-471c-a1b7-5f9e5705655f1
ErrorCode: 916
ErrorCode: 40613
ErrorCode: 18456
Ma se il database esiste (lo fa), perché dovrebbe provare a ricrearlo? o va al master per verificare se il db esiste, e quando fallisce, prova comunque, facendo in modo che l'applicazione funzioni correttamente. L'applicazione funziona bene, solo questi errori intermittenti nel registro. – Mayoweezy
Immagino che passi automaticamente al ramo 'master' in modo che possa eseguire una query che restituisca la struttura delle tabelle nel database. – krillgar