2014-06-18 33 views
0

我有一個代碼第一個web.api項目,它可以在App_Data文件夾中自動創建的.mdf中正常工作。我決定將我的應用程序移至IIS並修改應用程序池配置以加載用戶配置文件,同樣沒有問題。然後我在Visual Studio的sql explorer中加載了.mdf,此時,來自Web應用程序的應用程序池登錄開始失敗。不知道爲什麼,也無法修復它,所以我決定使用sql express,而不是浪費更多時間。所以,我安裝了SQL Express,殺了我的所有遷移,並修改了web.config中的連接字符串:爲什麼我的web.api項目仍在尋找.mdf文件?

<connectionStrings> 
    <add name="DefaultConnection" providerName="System.Data.SqlClient" connectionString="Data Source=.;Initial Catalog=MyApp;Integrated Security=SSPI"/> 
</connectionStrings> 

當我嘗試使用遷移來更新數據庫或運行應用程序的API,我得到一個異常說

無法附加文件 'C:\用戶\來源\ MyApp的\ MAIN \解決方案\ MyApp.API \ App_Data文件\ MyApp.DataService.DataModel.AppEntities.mdf' 數據庫「MyApp.DataService.DataModel .AppEntities'。

那麼,這是有道理的,因爲我刪除它,但爲什麼我的應用程序仍然試圖連接到.mdf文件?它消失了,我改變了默認連接。我已經在解決方案中搜索引用.mdf文件的任何內容,但沒有顯示。我錯過了什麼?

回答

0

我終於想通了,我必須說出我的連接字符串一樣我的DbContext類,所以在我的情況:

<connectionStrings> 
    <add name="AppEntities" providerName="System.Data.SqlClient" connectionString="Data Source=.;Initial Catalog=MyApp;Integrated Security=SSPI"/> 
</connectionStrings> 

符合我的DbContext派生類

namespace MyApp.DataService.DataModel 
{ 
    internal class AppEntities : DbContext 
相關問題