2016-05-29 13 views
0

参照をリポジトリパターンを通してデータベースプロジェクトに単純なASP.Netプロジェクトを作成する方法を学ぶことにしました。ASP.NetはISSから自分のデータベースを見ることができません

私は私のコントローラが処理するList<Weight>を呼びかけています:repo.GetWeight()が呼び出されると

public IActionResult MyWeight() 
{ 
    var repo = new Database.Repositories.WeightRepository(); 
    var data = repo.GetWeight().Result; 

    return View(data); 
} 

、私は言って内側の例外を除いて、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)
    • ...
私はすべての App.config秒以下 connectionStringWeb.configを追加しました

:私は、Visual StudioのServer Explorer、から、テスト・プロジェクトからTest.csファイルを介して、両方のデータベースをテストしている

<connectionStrings> 
    <add 
     name="MyDatabaseConnection" 
     connectionString="Data Source=(localdb)\MSSQLLocalDB;Integrated Security=True" 
     providerName="System.Data.SqlClient"/> 
</connectionStrings> 

。私はデータを挿入して問題なく検索することができます。 しかし、ASP.Net-パートがアクセスしたい場合、愛はありません。

私は、任意の考え

...それはそれはどこからのパスを知りませんでしたISSかもしれないと思いましたか?

私のWeb.config: enter image description here

私のAppSetting

編集__

。JSON: enter image description here

+0

asp.netプロジェクトには1つの 'web.config'ファイルしか必要ありません。接続文字列は、Web設定ファイルの ''セクションに入ります。 – Nkosi

+0

私が**編集**でやったように? –

+0

あなたのASPプロジェクトのバージョンは?私はあなたのアプリケーション設定のための 'JSON'を持っていることに気づいています – Nkosi

答えて

1

まあ問題は明確である - ASP.NETは名前MyDatabaseConnectionで接続文字列を使用してデータベースにアクセスしようとしている:あなたが唯一持っている

<connectionStrings> 
    <add name="MyDatabaseConnection" connectionString="put the connection to the db here..." /> 
    </connectionStrings> 

そして、あなたのWeb.configファイルに名前WeightDatabaseConnectionとの接続文字列:

<connectionStrings> 
    <add name="WeightDatabaseConnection" connectionString="put the connection to the db here..." /> 
    </connectionStrings> 

ただMyDatのための新たな要素を追加しますabaseConnection <connectionStrings>Web.configファイルで動作するはずです

関連する問題