ASP.NET Core with an MSSQL database
Publish an ASP.NET Core application together with its SQL Server database and connection string.
This guide publishes an ASP.NET Core MVC application that stores its data in an MSSQL database. Visual Studio uploads the application through Web Deploy and writes the connection string of your hosted database into the published application.
Before you start
- A website created in the Control Panel — see Create your first website.
- Visual Studio with the ASP.NET and web development workload.
Create the project
Choose the template
In Visual Studio create a new project, select ASP.NET Core Web App (Model-View-Controller) and click Next.
Turn on authentication
On the Additional information page set Authentication type to Individual Accounts and click Create. This gives the application a database with user accounts, so there is something to store.
If you already have your own application that uses a database, skip this part.
Prepare the hosting
Download the publish profile
In the Control Panel open your website, choose Deploy, switch WebDeploy to Enabled on the Visual Studio access card and click Download publish profile. Save the
.publishSettingsfile.Create the database
Create an MSSQL database in the Control Panel — see Create an MSSQL database.
Copy the connection string
Open the database and copy its connection string — see Find your connection string.
Publish with the database
Import the profile
In Solution Explorer right-click the project and choose Publish. Click Import profile and select the
.publishSettingsfile you downloaded.Open the publish settings
Before publishing, click Show all settings.
Fill in the connection string
In the settings, expand the Database and Entity Framework Migrations sections and fill in the connection string of your hosted database in both of them.
Publish
Save the settings and click Publish. Visual Studio builds the project and publishes it to your website.
When the publish finishes, open the website in your browser. With the sample project you can register a user to check that the application writes to the database.
Tip
The application running on your website should use the local connection string — the website and the database talk to each other directly inside our network. The remote connection string is meant for connections from outside and requires remote access to be enabled.
Something went wrong?
- Error 500 after publishing. A wrong connection string is one of the most frequent causes. See HTTP Error 500 – the application failed to start.
- The application cannot sign in to the database. Go through Cannot connect to the database.