我決定學習如何通過存儲庫模式將一個簡單的ASP.Net項目與參考關聯到數據庫項目。ASP.Net無法從ISS中看到我的數據庫
我有我的控制器呼籲List<Weight>
處理:
public IActionResult MyWeight()
{
var repo = new Database.Repositories.WeightRepository();
var data = repo.GetWeight().Result;
return View(data);
}
當repo.GetWeight()
被調用時,我得到一個AggregateException
錯誤,與內部異常說:
"No connection string named 'MyDatabaseConnection' could be found in the application config file."
所以爲了清楚起見,讓我概述解決方案的結構:
- aspP ROJ
- 控制器
- 查看
- 服務
- 的App.config(1)
- 的Web.config
- ...
- 數據庫
- 實體
- 庫
- App.config中(2)
- ...
- Database.Test
- test.cs中
- App.config中(3)
- ...
我已經添加了以下connectionString
所有App.config
S和Web.config
:
<connectionStrings>
<add
name="MyDatabaseConnection"
connectionString="Data Source=(localdb)\MSSQLLocalDB;Integrated Security=True"
providerName="System.Data.SqlClient"/>
</connectionStrings>
我已經從從Visual Studio的Server Explorer
,並通過從測試項目Test.cs
文件測試數據庫。我可以插入數據和檢索沒有問題。 但是,當ASP.Net部分想要訪問它時,沒有愛。
我想這可能是國際空間站這不知道從那裏的路徑...
有什麼想法?
__
編輯:
該asp.net項目只需要一個'web.config'文件。連接字符串將進入Web配置文件的 connectionStrings>部分。 –
Nkosi
就像我在**編輯**中所做的一樣? –
你的asp項目是什麼版本?我注意到你的應用程序設置爲'JSON' – Nkosi