---
title: "How to Create Connection string?"  
description: "How to Create Connection string?"  
author: "Anonymous User"  
published: 2020-01-22  
updated: 2020-01-22  
canonical: https://www.mindstick.com/forum/155724/how-to-create-connection-string  
category: "asp.net mvc"  
tags: ["asp.net mvc"]  
reading_time: 2 minutes  

---

# How to Create Connection string?

[Please describe](https://www.mindstick.com/interview/33713/please-describe-the-relationship-between-seo-and-sem) me about how we [add](https://www.mindstick.com/forum/12983/add-address-in-textbox-when-page-is-load-and-if-i-search-address-in-textbox-show-in-map-by-javascript) [connection string](https://www.mindstick.com/articles/328/connection-strings) in [web.config](https://www.mindstick.com/forum/183/web-config-file) [file](https://www.mindstick.com/articles/59/encrypting-and-decrypting-files-using-c-sharp) within [mvc](https://www.mindstick.com/forum/155803/define-cache-profile-in-mvc) with example and and image.

## Replies

### Reply by Nishi Tiwari

**Creating a [Connection](https://www.mindstick.com/articles/13012/what-makes-ethernet-connection-better-than-wifi) [String](https://www.mindstick.com/articles/1527/string-split-in-c-sharp)**

In the application, the class is mainly responsible for handling the task of connecting the database and to map the Class objects to database records. The Entity Framework automatically connects the database and uses it. The default database is LocalDB. Now, we are adding a connection string explicitly in the Web.Config file in an application.

## Working with SQL Server Express LocalDB

The SQL Server Express Database Engine has the LocalDB. It is very lightweight which automatically starts on demand and runs in the user mode. SQL Server Express has the special execution mode in which LocalDB runs and which facilitates us to work with the database as .mdf files. The .mdf file of any database are stored in the App_data folder in the application.

We should not use the LocalDB in particular for production with a web application because it is designed to work with **[Internet Information Services (IIS).](https://www.mindstick.com/forum/155672/what-is-iis-server)** We can easily migrate our LocalDB database to SQL Server or SQL Azure. It is by default installed in Visual Studio 2012 and 2013 Preview versions of Visual Studio.

**We can add a connection string to our app using the following procedure.**

Step 1: Open our project

Step 2: In Solution Explorer open the Web.Config file

![How to Create Connection string?](https://www.mindstick.com/mindstickforums/f4fef531-b147-4449-9a92-336876e8736c/images/d9cc3cb3-6e6c-4067-80ee-a4be23960cdc.png)

Step 3: Find the <connectionStrings> in the file.

![How to Create Connection string?](https://www.mindstick.com/mindstickforums/f4fef531-b147-4449-9a92-336876e8736c/images/075f6fba-fe51-4879-867d-ed62d8dfb057.png)

Step 4: Add the following connection string to the <connectionStrings> after the previous connection string:

<add name="CricketerDBContext" connectionString="Data Source=(LocalDB)\v11.0;AttachDbFileName=|DataDirectory|\Cricketers.mdf;Integrated Security=True" providerName="System.Data.SqlClient" />

Now there are two connection strings available in our Web.Config file. The connection string named DefaultConnection is used for the membership database and the connection string named CricketerDBConetext determines a LocalDB database which is located in the App_Data folder as Cricketers.mdf.

Note: we need to note that the connection string must match the name of DbContext class.

![How to Create Connection string?](https://www.mindstick.com/mindstickforums/f4fef531-b147-4449-9a92-336876e8736c/images/6a542339-2d4b-4727-91d0-7136944a654c.png)


---

Original Source: https://www.mindstick.com/forum/155724/how-to-create-connection-string

Copyright © MindStick Software Pvt. Ltd. This Markdown version is provided for developers, AI systems, and offline reading.
