Appsettings.json generating with incorrect settings

Asked

Viewed 360 times

0

Good morning! I am working on an API . Net Core 3.1. This API is divided into 3 environments, DEV, Homologation and Production. I have 4 configuration files, Appsettings.json, Appsettings.Development.Json, Appsettings.Homologation.json and Appsettings.Production.Json.

I have the following problem, in the files with the Environment name, I have a connection string with the bank that points to the correct database. However, when publishing the API, the Appsettings.Json file is generated with an extra connection configuration to the database pointing to a local address that does not exist.

Filing cabinet Appsettings.Json

   {
      "Logging": {
        "IncludeScopes": false,
        "LogLevel": {
          "Default": "Debug",
          "Microsoft": "Information",
          "System": "Information"
        }
      }
    }

Filing cabinet Appsettings.Development.json

{
  "Logging": {
    "LogLevel": {
      "Default": "Information",
      "Microsoft": "Warning",
      "Microsoft.Hosting.Lifetime": "Information"
    }
  },

  "ConnectionStrings": {
    "DefaultConnection": "Data Source=192.168.1.230,1498;Initial Catalog=banco_teste;User ID=usuario_teste;Password=senha"
  },

  "AppSettings": {
    "Secret": "FE2765D5F67B9F1423DF",
    "ExpiresToken": "01 02:00"
  },

  "SQSettings": {
    "SQService": {
      "Url": "http://192.168.10.224:80/api/"
    }
  }
}

Filing cabinet Appsettings.json generated after publication containing the incorrect connectionString

{
  "ConnectionStrings": {
    "DefaultConnection": "Server=(localdb)\\mssqllocaldb;Database=banco_teste;Trusted_Connection=True;MultipleActiveResultSets=true"
  },
  "Logging": {
    "IncludeScopes": false,
    "LogLevel": {
      "Default": "Debug",
      "System": "Information",
      "Microsoft": "Information"
    }
  }
}

The Appsettings.Velopment.json file is generated correctly after posting, but due to this wrong string in the Appsettings.json file the connection to the database does not work.

Does anyone know what it can be????

  • Are you sure you’re not in the mood to point to the AppSettings.Local?

  • The publication you refer to is the visual studio?

  • yes, that’s right

1 answer

0

discovered the error. There was an environment variable setting this in the application properties. In addition, there was another appsettings.json at another point in the application with a local connectionstring that was not used. I removed both and re-compiled correctly. Thank you!

Browser other questions tagged

You are not signed in. Login or sign up in order to post.