2012-11-29 31 views
18

此視頻演示如何使用現有數據庫中的Code First。 http://msdn.microsoft.com/en-us/data/jj572367當我嘗試對EF5代碼中的數據庫進行逆向工程時,我收到了一個異常

因此,我使用nuget安裝EF Power Tools,並選擇我的項目,右鍵單擊並選擇; 實體框架 - >反向工程師代碼優先。 我按照概述選擇了數據庫,但當單擊確定時出現以下異常;

System.Data.ProviderIncompatibleException: The provider did not return a ProviderManifestToken string. ---> System.InvalidOperationException: This operation requires a connection to the 'master' database. Unable to create a connection to the 'master' database because the original database connection has been opened and credentials have been removed from the connection string. Supply an unopened connection. ---> System.Data.SqlClient.SqlException: Login failed for user 'ictdev'. 
    at System.Data.SqlClient.SqlInternalConnection.OnError(SqlException exception, Boolean breakConnection) 
    at System.Data.SqlClient.TdsParser.ThrowExceptionAndWarning() 
    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, Boolean ignoreSniOpenTimeout, TimeoutTimer timeout, SqlConnection owningObject) 
    at System.Data.SqlClient.SqlInternalConnectionTds.LoginNoFailover(ServerInfo serverInfo, String newPassword, Boolean redirectedUserInstance, SqlConnection owningObject, SqlConnectionString connectionOptions, TimeoutTimer timeout) 
    at System.Data.SqlClient.SqlInternalConnectionTds.OpenLoginEnlist(SqlConnection owningObject, TimeoutTimer timeout, SqlConnectionString connectionOptions, String newPassword, Boolean redirectedUserInstance) 
    at System.Data.SqlClient.SqlInternalConnectionTds..ctor(DbConnectionPoolIdentity identity, SqlConnectionString connectionOptions, Object providerInfo, String newPassword, SqlConnection owningObject, Boolean redirectedUserInstance) 
    at System.Data.SqlClient.SqlConnectionFactory.CreateConnection(DbConnectionOptions options, Object poolGroupProviderInfo, DbConnectionPool pool, DbConnection owningConnection) 
    at System.Data.ProviderBase.DbConnectionFactory.CreateNonPooledConnection(DbConnection owningConnection, DbConnectionPoolGroup poolGroup) 
    at System.Data.ProviderBase.DbConnectionFactory.GetConnection(DbConnection owningConnection) 
    at System.Data.ProviderBase.DbConnectionClosed.OpenConnection(DbConnection outerConnection, DbConnectionFactory connectionFactory) 
    at System.Data.SqlClient.SqlConnection.Open() 
    at System.Data.SqlClient.SqlProviderServices.UsingConnection(SqlConnection sqlConnection, Action`1 act) 
    at System.Data.SqlClient.SqlProviderServices.UsingMasterConnection(SqlConnection sqlConnection, Action`1 act) 
    --- End of inner exception stack trace --- 
    at System.Data.SqlClient.SqlProviderServices.UsingMasterConnection(SqlConnection sqlConnection, Action`1 act) 
    at System.Data.SqlClient.SqlProviderServices.GetDbProviderManifestToken(DbConnection connection) 
    at System.Data.Common.DbProviderServices.GetProviderManifestToken(DbConnection connection) 
    --- End of inner exception stack trace --- 
    at System.Data.Common.DbProviderServices.GetProviderManifestToken(DbConnection connection) 
    at System.Data.Entity.Design.EntityStoreSchemaGenerator.GetProviderSchemaMetadataWorkspace(DbProviderServices providerServices, DbConnection providerConnection) 
    at System.Data.Entity.Design.EntityStoreSchemaGenerator.CreateStoreSchemaConnection(String providerInvariantName, String connectionString) 
    at System.Data.Entity.Design.EntityStoreSchemaGenerator..ctor(String providerInvariantName, String connectionString, String namespaceName) 
    at Microsoft.DbContextPackage.Handlers.ReverseEngineerCodeFirstHandler.ReverseEngineerCodeFirst(Project project) 

所以問題是我該如何解決這個問題?

回答

48

我在EF Power Tools產品網頁的評論中找到了解決方案; http://visualstudiogallery.msdn.microsoft.com/72a60b14-1581-4b9b-89f2-846072eff19d

在連接嚮導中,應單擊高級,並且Persist Security Info的值應爲True。

如果任何人都可以回答原始問題並解釋當你這樣做時發生了什麼,我可能會給他們答案!

+5

以下是發生了什麼,以及爲什麼你需要這樣做...... http://blog.longle.net/2013/02/05/system-data-providerincompatibleexception-with-entity-framework-power-tools- β-2-和-β-3 / – LeLong37

相關問題