Search code examples
asp.net-mvcasp.net-mvc-5web-configconnection-string

Changing connection strings in an ASP.NET MVC application


I tried to run a project from GitHub: https://github.com/MarlabsInc/SocialGoal

It says "Open the web.config and change the connecting string "SocialGoalEntities" for working with your system."

<connectionStrings>
      <add name="SocialGoalEntities" connectionString="Data Source=.\;Initial Catalog=SocialGoal;Integrated Security=True" providerName="System.Data.SqlClient" />
  </connectionStrings>

What am I supposed to do in order to fix it?


Solution

  • It means change the connection string according to your system.

    For example,

    <connectionString><add name="DefaultConnection" connectionString="data source=Your data source; initial catalog=your db name;Integrated Security=True" providerName="System.Data.SqlClient" /></connectionString>
    

    You can replace DefaultConnection with any name you like, replace Your data source (your sql server instance name) and your db name according to your system.For more information about connection string please visit connectionstrings.com

    Then enable migration if it is not already enabled for the projects from the package manager console using the following command:

    Enable-Migrations

    Add a migration from package manager console using the following command:

    Add-Migration migrationName

    Then update the database from package manager console using the following command:

    Update-Database