Home > Software engineering >  Strange error in Asp.Net Core 5.0 on Linux "Value cannot be null. (Parameter 'connectionSt
Strange error in Asp.Net Core 5.0 on Linux "Value cannot be null. (Parameter 'connectionSt

Time:09-26

Im blocked since one week with that error...

"An unhandled exception was thrown by the application. System.ArgumentNullException: Value cannot be null. (Parameter 'connectionString') "

I deployed an application in Asp.Net Core in Apache on Linux. I can access to the pages but when it needs to call the database it gives me that error.

When I use it locally on my windows everything work and I can access to the database with the same connectionString.

I dont understand why it doesnt work when I build the project and I deploy it ..

Can somebody help me please

Here is my connection string:

{
"ConnectionStrings": {
    "DefaultConnection": "Data Source=IP SERVER;Initial Catalog=Database;User ID=SA;Password=Password"
},   

I already deployed that app on Azure with an SQL database on azure, maybe its because of that ?

CodePudding user response:

I knew that nobody could help me I'm sure it's literally a bug from .Net because I tried all the possibilities since 1 week

CodePudding user response:

Since you are using net core, the connection string is kept in appsettings.json file. The default JsonConfigurationProvider loads configuration in the following order:

  1. appsettings.json

  2. appsettings.Environment.json . For example, the appsettings.Production.json and appsettings.Development.json files.

appsettings.Environment.json values override keys in appsettings.json:

In development, appsettings.Development.json configuration overwrites values found in appsettings.json.

In production, appsettings.Production.json configuration overwrites values found in appsettings.json. For example, when deploying the app to Azure or any another server.

So you have to check appsettings.Production.json file. Maybe it doesn't containg connection string and since overrides your development file you can have the error.

UPDATE

If you use MS SQl server your connection string should look like this, but I don't think that it is a problem. Problem could be if you use a different name, instead of "DefaultConnection"

"DefaultConnection": "Data Source=xx.182.xx.xxx;Initial catalog=XXXX;Integrated Security=False;User ID=user;Password=passwod;"
  • Related