5

私は Entity Framework 4 と CTP 4 を使用しており、これまでのところ非常に気に入っています。Windows 認証を使用してデータベースに接続している場合は正常に動作しますが、SQL 認証に切り替えると以下のメッセージで失敗します。ユーザーに sysadmin ロールを与えました。デフォルトのデータベースは master です。

エラー:

この操作には、'master' データベースへの接続が必要です。元のデータベース接続が開かれており、資格情報が接続文字列から削除されているため、'master' データベースへの接続を作成できません。開かれていない接続を提供します。

何か案は?

...エラーの詳細:

[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.SqlProviderServices.UsingMasterConnection(SqlConnection sqlConnection, Action`1 act) +344
   System.Data.SqlClient.SqlProviderServices.DbDatabaseExists(DbConnection connection, Nullable`1 commandTimeout, StoreItemCollection storeItemCollection) +231
   System.Data.Objects.ObjectContext.DatabaseExists() +84
   System.Data.Entity.Internal.DatabaseOperations.Exists(ObjectContext objectContext) +9
   System.Data.Entity.Infrastructure.Database.Exists() +53
   System.Data.Entity.Infrastructure.RecreateDatabaseIfModelChanges`1.InitializeDatabase(TContext context) +129
   System.Data.Entity.Infrastructure.<>c__DisplayClass2`1.<SetInitializer>b__0(DbContext c) +75
   System.Data.Entity.Infrastructure.Database.Initialize() +207
   System.Data.Entity.Internal.InternalContext.Initialize() +70
   System.Data.Entity.Internal.LazyInternalContext.get_ObjectContext() +9
   System.Data.Entity.Internal.InternalContext.TryUpdateEntitySetMappingsForType(Type entityType) +51
   System.Data.Entity.Internal.InternalContext.UpdateEntitySetMappingsForType(Type entityType) +17
   System.Data.Entity.Internal.InternalContext.GetEntitySetAndBaseTypeForType(Type entityType) +24
   System.Data.Entity.Internal.Linq.EfInternalQuery`1.Initialize() +62
   System.Data.Entity.Internal.Linq.EfInternalQuery`1.get_Provider() +9
   System.Data.Entity.Infrastructure.DbQuery`1.System.Linq.IQueryable.get_Provider() +13
   System.Linq.Queryable.Select(IQueryable`1 source, Expression`1 selector) +63
4

2 に答える 2

2

これは私にとってはうまくいきました。

   Database.SetInitializer<YourDbContext>(null);

http://social.msdn.microsoft.com/Forums/en/adonetefx/thread/870959ef-5c06-4c3e-b9f8-454346592280に感謝します

于 2010-09-07T14:22:38.400 に答える
1

次の例外に関して:
System.InvalidOperationException:この操作には、「マスター」データベースへの接続が必要です。元のデータベース接続が開かれ、接続文字列から資格情報が削除されたため、「マスター」データベースへの接続を作成できません。未開封の接続を提供します。System.Data.SqlClient.SqlException:ユーザー'sa'のログインに失敗しました

Entity Framework 4.1 Update 1には、SQL認証を使用するときに接続文字列に「PersistSecurityInfo=True」を指定する必要がなくなるバグ修正が含まれています。
http://www.microsoft.com/download/en/details.aspx?id=26825

于 2011-08-05T07:06:35.427 に答える