摘要:修改WebSecurity設定時,發生錯誤:找不到必要的 .Net Framework Data Provider。可能尚未安裝。
發生經過:
建立一個新的ASP.NET MVC4網際網路應用程式,想要使用原本已經建立好的資料庫時,我在專案上加入了【ADO.NET 實體資料模型】(Entity Framework)並連結到要使用的資料庫:
以上為 database-first
在指定的資料庫裏面有一個資料表Users,想要讓WebSecurity使用時修改了
WebSecurity.InitializeDatabaseConnection("DefaultConnection", "UserProfile", "UserId", "UserName", autoCreateTables: true);
為
WebSecurity.InitializeDatabaseConnection("TestDbEntities", "Users", "UserId", "UserName", autoCreateTables: true);
我將預設產生的DefaultConnection改為TestDbEntities,並將UserProfile資料表改為Users
開始執行網站,當執行到上面這段修改過的程式時, 發生錯誤:
找不到必要的 .Net Framework Data Provider。可能尚未安裝。
看來membership服務認不出entity framework的連結字串,因此將連結字串改回用DefaultConnection,並修改內容:
<add name="DefaultConnection" connectionString="Data Source=(LocalDb)\v11.0;Initial Catalog=TestDb;Integrated Security=SSPI;" providerName="System.Data.SqlClient" />


