2

I have a simple Web API using .net Entity Framework Core 2.2. Everything works in debug mode in Visual Studio. But when I build and run it, it fails to connect to the database.

The error massage :

fail: Microsoft.AspNetCore.Server.Kestrel[13]
Connection id "0HLRCVL1R3B1L", Request id "0HLRCVL1R3B1L:00000001": An unhandled exception was thrown by the application.
System.ArgumentNullException: Value cannot be null.
Parameter name: connectionString

at Microsoft.EntityFrameworkCore.Utilities.Check.NotEmpty(String value, String parameterName)
at Microsoft.EntityFrameworkCore.SqlServerDbContextOptionsExtensions.UseSqlServer(DbContextOptionsBuilder optionsBuilder, String connectionString, Action`1 sqlServerOptionsAction)
at TSPfizer.CentoMiner.Web.Startup.b__4_1(DbContextOptionsBuilder options) in C:\Users\shangl02\source\repos\TSolution\CentoMinerWebAPI\Startup.cs:line 43

Did I miss something there?

marc_s
  • 732,580
  • 175
  • 1,330
  • 1,459
Mavershang
  • 1,266
  • 2
  • 15
  • 27
  • The compiler may be changing the connection string in release mode. I would check the config. – Steve Nov 19 '19 at 14:43
  • https://stackoverflow.com/questions/14415614/web-config-build-vs-release-transform-not-working/25301705#25301705 – Steve Nov 19 '19 at 14:46
  • Check your appsettings. The Release settings might contain empty connection string. Another option, do the `IConfiguration.GetConnectionString("name")` at runtime and check what you get in both Debug and Release. – kyrylomyr Nov 19 '19 at 15:07
  • Thanks. Yes it is the release setting removed the connection string. – Mavershang Nov 19 '19 at 16:14

0 Answers0