2010-09-06 668 views
5

Tôi đang làm việc với Entity Framework 4 và CTP 4 và tôi thực sự thích nó cho đến nay. Tôi có thể làm cho nó hoạt động chính xác khi tôi đang sử dụng Windows Authentication để kết nối với cơ sở dữ liệu nhưng khi tôi chuyển sang SQL Authentication nó không thành công với thông báo bên dưới. Tôi đã cung cấp cho người dùng một vai trò sysadmin và cơ sở dữ liệu mặc định của nó là chính.Code First Entity Framework 4: Không có xác thực SQL

Lỗi:

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.

Bất kỳ ý tưởng?

... một số chi tiết lỗi hơn:

[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 

Trả lời

2

này đã làm việc cho tôi.

Database.SetInitializer<YourDbContext>(null); 

Nhờ http://social.msdn.microsoft.com/Forums/en/adonetefx/thread/870959ef-5c06-4c3e-b9f8-454346592280

+0

Chỉ cần đi để hiển thị như thế nào 'beta' EF này thực sự là. 'và thực sự thích nó cho đến nay' sợ tôi rất nhiều. –

+0

Trừ khi bạn thực sự KHÔNG muốn thả nếu mô hình thay đổi, hoặc thả luôn ... người gọi (null) này làm cho nó được đặt thành CreateIfNotExists, luôn luôn. – bc3tech

1

Liên quan đến các ngoại lệ sau đây:
System.InvalidOperationException: Thao tác này đòi hỏi một kết nối đến cơ sở dữ liệu 'thầy'. Không thể tạo kết nối đến cơ sở dữ liệu 'chính' vì kết nối cơ sở dữ liệu gốc đã được mở và thông tin đăng nhập đã bị xóa khỏi chuỗi kết nối. Cung cấp kết nối chưa mở. System.Data.SqlClient.SqlException: Đăng nhập không thành công cho người dùng '

Entity Framework 4.1 Update 1 chứa một sửa lỗi để loại bỏ sự cần thiết phải chỉ định ‘Thông tin bảo mật liên tục = True’ trong chuỗi kết nối khi sử dụng xác thực SQL.
http://www.microsoft.com/download/en/details.aspx?id=26825