亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

獲取連接字符串時出錯:ArgumentNullException:值不能為空。參數名稱:連接字符串

獲取連接字符串時出錯:ArgumentNullException:值不能為空。參數名稱:連接字符串

PHP
慕容森 2024-01-20 21:38:45
我正在使用 ASP.NET Core 2.0。下面是我的代碼。啟動:namespace foo{    public class Startup    {        public Startup(IConfiguration configuration)        {            Configuration = configuration;        }        public IConfiguration Configuration { get; }        // This method gets called by the runtime. Use this method to add services to the container.        public void ConfigureServices(IServiceCollection services)        {            // Add framework services.            services                .AddMvc()                .AddJsonOptions(options => options.SerializerSettings.ContractResolver = new DefaultContractResolver());            services.AddDbContext<fooContext>(options => options.UseSqlServer(Configuration.GetConnectionString("UserDatabase")));        }        // This method gets called by the runtime. Use this method to configure the HTTP request pipeline.        public void Configure(IApplicationBuilder app, IHostingEnvironment env)        {            if (env.IsDevelopment())            {                app.UseBrowserLink();                app.UseDeveloperExceptionPage();            }            else            {                app.UseExceptionHandler("/Home/Error");            }            app.UseStaticFiles();            app.UseMvc(routes =>            {                routes.MapRoute(                    name: "default",                    template: "{controller=Home}/{action=Index}/{id?}");            });        }    }}應用程序設置.json:{  "Logging": {    "IncludeScopes": false,    "LogLevel": {      "Default": "Debug",      "System": "Information",      "Microsoft": "Information"    },    "ConnectionStrings": {      "UserDatabase": "Server=DESKTOP-FSES7UK;Database=xxx;User Id=sa; Password=xxxxxxx;Trusted_Connection=True;"    }  }}如何修復它?
查看完整描述

2 回答

?
慕森卡

TA貢獻1806條經驗 獲得超8個贊

正如評論中提到的,嘗試將連接字符串移至頂部(建議)修復方法是將鍵 * *置于鍵"ConnectionStrings"之外logging


應用程序設置.json


{

  "ConnectionStrings": {

      "UserDatabase": "Server=DESKTOP-FSES7UK;Database=xxx;User Id=sa; Password=xxxxxxx;Trusted_Connection=True;"

  },

  "Logging": {

    "IncludeScopes": false,

    "LogLevel": {

      "Default": "Debug",

      "System": "Information",

      "Microsoft": "Information"

  }

}


查看完整回答
反對 回復 2024-01-20
?
眼眸繁星

TA貢獻1873條經驗 獲得超9個贊

問題是你的ConnectionStrings對象已經是對象的屬性Logging。寫下你的appsettings.json如下:


{

  "Logging": {

    "IncludeScopes": false,

    "LogLevel": {

      "Default": "Debug",

      "System": "Information",

      "Microsoft": "Information"

    },

  },

  "ConnectionStrings": {

      "UserDatabase": "Server=DESKTOP-FSES7UK;Database=xxx;User Id=sa; Password=xxxxxxx;Trusted_Connection=True;"

  }

}


查看完整回答
反對 回復 2024-01-20
  • 2 回答
  • 0 關注
  • 288 瀏覽

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號