Reputation: 18198
I created a web application using the ASP.Net 5 web application template and published to an Azure web application.
In the Settings section of my web app I was able to create a Data Connection. How do I tell my web application to use this data connection.
[Update] the name of the connection string in my appsettings.json is DefaultConnection
Upvotes: 3
Views: 4959
Reputation: 318
Connection strings can now be found in Azure from App Services --> Select the website --> select the webslot if necessary --> Settings Section/Environment Variables
Upvotes: 0
Reputation: 18198
App Services, then select the web app, then Settings, then Application Settings. Scroll down to connection strings. Make sure the connection is named DefaultConnection
Upvotes: 1
Reputation: 506
Please try this...
Go to Azure web app > configure > connection strings.
Add a connection string with the name DefaultConnection.
Use Configuration.Get("Data:DefaultConnection:ConnectionString") to access it.
Example using timesheet_db instead of DefaultConnection This is an example from my own timesheet application. My connection string was named timesheet_db. Just replace all instances of that string with DefaultConnection to adapt the example to your use case.
Azure web app service control manager The online service control manager at https://myWebAppName.scm.azurewebsites.net/Env will show the connection strings.
Startup.cs Setup configuration settings in Startup so that the environmental variables overwrite the config.json
public IConfiguration Configuration { get; set; }
public Startup()
{
Configuration = new Configuration()
.AddJsonFile("config.json")
.AddEnvironmentVariables(); <----- will cascade over config.json
}
Configure the database in Startup.
public void ConfigureServices(IServiceCollection services)
{
services
.AddEntityFramework()
.AddSqlServer()
.AddDbContext<ProjectContext>(options =>
{
var connString =
Configuration.Get("Data:timesheet_db:ConnectionString");
options.UseSqlServer(connString);
});
}
Of course, the example uses a connection string named timesheet_db. For you, replace all instances of it with your own connection string named DefaultConnection and everything will work.
Upvotes: 3