使用Entity Framework時,通常一開始就要設定好要連接的資料庫 但如果想要在Run time時 變更連接的資料庫, 就得先設定LazyLoadingEnabled屬性, 讓Entities延遲讀取,在設定連接字串到新的資料庫中 dim MyEntities = New Entities() MyEntities.Configuration.LazyLoadingEnabled = True MyEntities.Database.Connection.ConnectionString = "{New Connection String}"