# 3.3: Database and Connection String

In this module we'll talk about connection strings and complete our first migration for database set up.

## Purpose

A connection string is a piece of code that helps us establish our initial connection to the database. The connection string includes the source database name and other parameters needed to establish the initial connection. For the next few steps we'll examine this important concept and get our database established.

## Connection String

First, let us show you where the connection string is established:

1. Go to the **ElevenNote.WebMVC** assembly, and double click on the `Web.Config` file.
2. Look at the `<connectionStrings>` on line 13.
3. Notice the the name is `"DefaultConnection"`

   ![ConnectionString](/files/-LAxHTVVcXw6w3Y5wrFP)
4. Go to **ElevenNote.Data ->** `IdentityModels.cs`
5. In the `ApplicationDbContext` method, one of the arguments is `"DefaultConnection"`

   ![Default Connection](/files/-LAxHTYibtAnZVq19rbl)
6. This is how the application can communicate with the Web.Config file and persist application data.
7. Go back to **ElevenNote.WebMVC ->** `Web.Config`
8. In the connection string, the name of the database is in two places.&#x20;

   ![Name](/files/-LAxHT_5cds1kW9HooDe)
9. Take the following connection string code and paste it over the top of your existing connection string:

```markup
  <connectionStrings>
    <add name="DefaultConnection" connectionString="Data Source=(LocalDb)\MSSQLLocalDB;AttachDbFilename=|DataDirectory|\ElevenNote.mdf;Initial Catalog=ElevenNote;Integrated Security=True"
      providerName="System.Data.SqlClient" />
  </connectionStrings>
```

## Run the application

Again, the connection string helps us establish an initial connection to the database, so when we run the application, we will have our initial database created: 1. Run the application and register an account. 2. Make sure to remember the login/password you use to test with later. 3. In the top right of the application, you should be greeted with the email you entered ![Welcome](/files/-LAxHTdCaL8xGqLUPxcG)

## Database

Let's show you how to view the data in the SQL Server Object Explorer.

1. In the **Quick Launch** (top right), type in 'SQL'
2. Find the **SQL Server Object Explorer** (you can also get this by going to **View -> SQL Server Object Explorer**)
3. Find your ElevenNote database and expand the **Tables** folder
4. Right click on `dbo.ApplicationUser` and select **View Data**

   ![Right Click View Data](/files/-LAxHTmrabAQW4hHOY26)
5. Checkout the data

   ![Data](/files/-LAxHToMPV1-WS_GL5RP)
6. Close the data tab
7. Right click on `dbo.ApplicationUser` and select **Properties**

   ![Properties](/files/-LAxHTrzqI3zbgpP-gOa)
8. Take a look at the table's properties
9. ![Git](/files/-LAwyxUd0dcYSLXYb-5s)


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://eleven-fifty-academy.gitbook.io/dotnet-201-elevennote/elevennote-parts-1-11/part-3-database-setup/3.3-databaseandconnectionstring.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
