2

I'm developing an ASP.NET Core 3 Web API with a database first generated db context. I have the connection string in the appsettings.json file.

Everything is fine when I run it locally on IIS Express.

The problem is that when I publish it on Azure, it gives me the error:

System.ArgumentException: Keyword not supported: 'data source'.
[...]

I noticed that the connection string, when published changed from:

metadata=res://*/DTOs.csdl|res://*/DTOs.ssdl|res://*/DTOs.msl;provider=System.Data.SqlClient;provider connection string='data source=*****;initial catalog=*****;persist security info=True;user id=*****;password=*****;MultipleActiveResultSets=True;App=EntityFramework'",

to:

metadata=res://*/DTOs.csdl|res://*/DTOs.ssdl|res://*/DTOs.msl;provider=System.Data.SqlClient;provider connection string="data source=*****;initial catalog=*****;persist security info=True;user id=*****;password=*****;MultipleActiveResultSets=True;App=EntityFramework""

As a work around I changed the line

services.AddScoped<palmdtos>(_ => new MyDbContext(Configuration.GetConnectionString("myConnectionString")));

to

services.AddScoped<palmdtos>(_ => new MyDbContext(Configuration.GetConnectionString("myConnectionString").Replace("&quot;","'").Replace("&amp;", "&")));

Is there a better way to do it?

2
  • Please put the whole error Commented Nov 26, 2019 at 23:58
  • that's it, it does not say anything else. I have the stack trace if it is useful Commented Nov 26, 2019 at 23:59

2 Answers 2

2

Models created with the EF Designer are different from Code First in that your model already exists and is not generated from code when the application runs. The model typically exists as an EDMX file in your project.

The designer will add an EF connection string to your app.config or web.config file. This connection string is special in that it contains information about how to find the information in your EDMX file.

Refer to this article.

The cause was the connection string for one of the EDMX files we were using. Since the EDMX has to be read-only, we had to use a different connection string in Azure.

When replacing &quote; by a single quote ', it will work fine again. So go to azure website > Configuration > Connection strings > add your conn string with custom type.

Note: Make sure you also select Custom instead of SQLAzure for your Entity Framework connection string, even though the database runs on Azure.

Sign up to request clarification or add additional context in comments.

Comments

1

Can you try updating the settings?

In Azure Panel:

Select App -> Application Settings -> Enter new Connection String -> Save

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.