0

I need help, I'm trying to deploy my ASP.NET Core Blazor web assembly on somee, but I am having an issue on how to change my connection string while deploying to somee server. In my server project I have appsettings.json configured like this:

"ConnectionStrings": {
    "DefaultConnection": "server=localhost\\sqlexpress;database=xxxxxx;trusted_connection=true"
},

while my somee connection string goes like this:

workstation id=xxxxx.mssql.somee.com;packet size=4096;user id=xxxx_SQLLogin_1;pwd=xxxx;data source=xxxx.mssql.somee.com;persist security info=False;initial catalog=xxxx

Please how do I integrate the somee connection string into my appsettings.json before deployment?

marc_s
  • 732,580
  • 175
  • 1,330
  • 1,459

1 Answers1

0

My guess is that you want to keep the SQL Express connection string when running locally and switch to the other one when running on Somee. You can use appsettings transformations for that. If you don't have a file named appsettings.production.json already, create it. Then add the following to that file:

"ConnectionStrings": {
    "DefaultConnection": "workstation id=xxxxx.mssql.somee.com;packet size=4096;user id=xxxx_SQLLogin_1;pwd=xxxx;data source=xxxx.mssql.somee.com;persist security info=False;initial catalog=xxxx"
},

When publishing your web application to Somee you need to make sure that the ASPNETCORE_ENVIRONMENT environment variable is set to Production. This usually happen automatically. This will merge the changes from the appsettings.production.json file into the appsettings.json file published as part of your release. If you want to test that the update will happen as you expect it before actually deploying you can use this Appsettings.json Transformation Tester. Also, there are some additional information about how transformations work in ASP.NET Core here: Config transformations in ASP.NET Core.

ThomasArdal
  • 4,999
  • 4
  • 33
  • 73