title: How to configure SQL Server 2014 Database using MVC 5
body: <p>I am trying to connect my SQL Server 2014 Database With my MVC Application.</p>
  
  <p>My code is as follows:</p>
  
  <p>Model class <code>Category.cs</code>: </p>
  
  <pre><code>using System;
  using System.Collections.Generic;
  using System.Linq;
  using System.Web;
  
  namespace GetImage.Models
  {
      public class Category
      {
  
          public int CategoryID { get; set; }
  
          public string CategoryName { get; set; }
  
          public byte[] Picture { get; set; }
      }
  }
  </code></pre>
  
  <p>My context class <code>CategoryContext.cs</code>:</p>
  
  <pre><code>using System;
  using System.Collections.Generic;
  using System.Linq;
  using System.Web;
  using System.Data;
  using System.Data.SqlClient;
  using System.Configuration;
  
  namespace GetImage.Models
  {
      public class CategoryContext
      {
          SqlConnection connection = null;
          SqlCommand command = null;
          SqlDataReader reader = null;
          string connectionString = ConfigurationManager.ConnectionStrings["Spencers"].ConnectionString;
  
          //Get Categories
          public List&lt;Category&gt; GetCategories()
          {
              List&lt;Category&gt; categories = null;
              try
              {
                  using (connection = new SqlConnection(connectionString))
                  {
                      using (command=new SqlCommand("uspGetCategories",connection))
                      {
                          connection.Open();
                          if (connection.State == ConnectionState.Open)
                          {
                              command.CommandType = CommandType.StoredProcedure;
                              reader = command.ExecuteReader();
                              categories = new List&lt;Category&gt;();
                              while (reader.Read())
                              {
                                  categories.Add(
                                      new Category() { 
                                      CategoryID=int.Parse(reader["CategoryID"].ToString()),
                                      CategoryName=reader["CategoryName"].ToString(),
                                      Picture=reader["Picture"] as byte[]
                                      }
                                      );
                              }
                          }
                      }
                  }
                  return categories;
              }
              catch (Exception)
              {
  
                  throw;
              }
          }
      }
  }
  </code></pre>
  
  <p>In <code>web.config</code> file:</p>
  
  <pre><code>&lt;connectionStrings&gt;
      &lt;add name="DefaultConnection" 
           connectionString="Data Source=(LocalDb)\v11.0;AttachDbFilename=|DataDirectory|\aspnet-GetImage-20150411072900.mdf;Initial Catalog=aspnet-GetImage-20150411072900;Integrated Security=True"
           providerName="System.Data.SqlClient" /&gt;
      &lt;!--Own DB Connection--&gt;
      &lt;add name="Spencers" 
           connectionString="Data SourceVIKASHPC\vikash;Initial Catalog=Spencers;" 
           providerName="System.Data.SqlClient"/&gt;
  &lt;/connectionStrings&gt;
  
  &lt;defaultConnectionFactory type="System.Data.Entity.Infrastructure.SqlConnectionFactory, EntityFramework"&gt;
        &lt;parameters&gt;
          &lt;parameter value="mssqllocaldb" /&gt;
        &lt;/parameters&gt;
      &lt;/defaultConnectionFactory&gt;
  </code></pre>
  
  <p><strong>Note:</strong></p>
  
  <p>From the above codes, I am trying to connect with my SQL Server 2014 database.</p>
  
  <p>By default, ASP.NET MVC application is connecting with the <code>localDB</code>. I don't want to connect with <code>localDB</code>. Instead, I want to connect to my SQL Server 2014 database.</p>
  
  <p>Please help me to get rid off this problem.</p>