Introduction

This article explains how to create a SQL database in the ASP .NET Web API.

Now we will provide the procedure for creating the database.

Step 1

First we create the MVC4 Web API application.

dt.jpg

Step 2

After performing Step 1, the New ASP .NET MVC4 Project Window is opened; then:

dt1.jpg

Step 3

Now to add the SQL Server Compact 4.0 Local Database. Follow these steps:

dt2.jpg

Step 4

Now we create the table in the database using the following:

dt3.jpg

dt4.jpg

dt5.jpg
The Table looks like this.

Step 5

Now we add the Field in the table.

dt6.jpg

After adding the field in the table it is looks like this.

Step 6

Add the record in the table.

dt7.jpg

Now we add the record in the table.

dt8.jpg

Step 7

Now we add the <connectionStrings> element to the Web.config file.

dt9.jpg

<add name="DefaultConnection" providerName="System.Data.SqlClient" connectionString="Data Source=(LocalDb)\v11.0;Initial Catalog=aspnet-Database_WebAPI-20130530090816;Integrated Security=SSPI;AttachDBFilename=|DataDirectory|\aspnet-Database_WebAPI-20130530090816.mdf" />