簡體   English   中英

在應用程序配置文件中找不到連接字符串

[英]No connection string could be found in the application config file

我創建了一個Web應用程序項目(基於實體框架5.0)。 在解決方案中,我在基於版本5.0的新.cs項目中創建了實體數據模型。 現在我有2個web.configs(一個用於Web應用程序項目,另一個用於實體數據模型項目),在其中我無法訪問在web.config中定義了連接字符串的網頁的實體類(在實體數據模型項目內部)。 ,我收到錯誤消息“在應用程序配置文件中找不到連接字符串”。 如何消除這個問題?

將連接字符串添加到web.config,

<!--web.config of the project that is utilizing Entity Framework-->
<connectionStrings>
<add name="YourConnectionName"
    providerName="System.Data.SqlClient"
    connectionString="Server=YourServerNameOrIP; Database=YourDatabaseName;
    Integrated Security=SSPI" />
</connectionStrings>

現在,指定到DbContext的連接字符串

// In the class inheriting from DbContext

namespace Context
{
    public class Dbc : DbContext
    {
        public Dbc() : base("YourConnectionName") { }
        public DbSet<Message> Messages { get; set; }

    }
}

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM