Restoring a SQL Server database backup file (.bak)

Introduction On regular basis we need to restore the database, either will only schema of the database, or many times both data as well as schema.  Most of the applications (either Web application e.g. ASP.NET based apps, or Windows applications e.g. WPF based apps) requires 'reference data' such as drop-down data, types of users, etc. So what is the most optimum, reliable way of moving database either on separate database server, or on the same database server but with different database name? There are several ways to achieve this objective but my personal preference is to first create the database backup file i.e. 'my_backup.bak' using Microsoft SQL Server Management Studio , and then restoring that backup file to create new database.  This article focuses on restoring the backup file to create a new database. How to create the backup file will be covered in another article.   This article addresses below points: 1.   How to check the name and path of the files



In this post we will explain how to specify the AspNetCore Environment Variable at IIS-level. We can setup the Environment variable 'ASPNETCORE_ENVIROMENT' and run more than one environment instances on the same machine. 

For example, for your application/API (lets call it WebApi) you can install two instances on the same machine, first instance for testing environment and second instance for staging environment

To elaborate it more, refer below code snippet where in, in the Startup.cs file's Configure method, by using input parameter IWebHostEnvironment, we can execute specific code based on the environment. In this example, if it is development environment then we will display 'developer exception page', which will provide developer the needed details to debug the issue. But if it is a production environment then we are making sure that our application always uses HTTPS

public void Configure(IApplicationBuilder app, IWebHostEnvironment env) {
    if (env.IsDevelopment()) {
    else if (env.IsProduction()) {
// do something specific to Production instance. 

    // Rest of the code
    . . .

Steps to follow:

1. Open IIS (Run >> inetmgr) and after selecting your web application, open the 'Configuration Editor' as shown in below image.

2. Once the 'Configuration Editor' is open select the value 'system.webServer' >> 'aspNetCore' from the 'Section' dropdown, as show in below image.

3. On the same screen for the second dropdown i.e. 'From', choose the third option i.e. 'ApplicationHost.Config', as demonstrated in below image.

4. Click the third field 'environmentVariables', you can open this collection by click on the ellipses (i.e. three dots '...') button, as specified in the below image. 

5. Clicking the ellipses button will open a 'Collection Editor', from right-hand side 'Action' choose 'Add' link, and specify the values for 'name' and 'value' fields. In this case for the 'name' you will add value as 'ASPNETCORE_ENVIROMENT', and for the 'value' type 'Production'. 


We have explained, step-by-step how to setup the Environment Variable -  'ASPNETCORE_ENVIROMENT' to setup more than one environment instance on the same machine, at IIS-level. 

Your feedback

Your feedback is of paramount importance to us, provide your valuable inputs; what else you would like to read about, or if you would like the author to elaborate on any specific topic from this article, or any other article on this blog.


The material presented in this blog is to help educate the developers, and the author(s) & owner(s) of this blog are not responsible of any damage arising out of use of the code snippets or any other contents of this blog.