Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

C# Entity Framework Basics Entity Framework and Databases Changing the Database Name

purva mishra
PLUS
purva mishra
Courses Plus Student 125 Points

In App.config set the "Context" database connection string's Data Source value to the SQL Server LocalDB default instanc

In App.config set the "Context" database connection string's Data Source value to the SQL Server LocalDB default instance name.,

i have set the datasource value to (localdb)\MSSQLLocaldb , still its throwing me error : (did you include suffix (localdb)

App.config
<?xml version="1.0" encoding="utf-8"?>
<configuration>
  <configSections>
    <!-- For more information on Entity Framework configuration, visit http://go.microsoft.com/fwlink/?LinkID=237468 -->
    <section name="entityFramework" type="System.Data.Entity.Internal.ConfigFile.EntityFrameworkSection, EntityFramework, Version=6.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" requirePermission="false" />
  </configSections>
  <startup>
    <supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.6.1" />
  </startup>
  <entityFramework>
    <defaultConnectionFactory type="System.Data.Entity.Infrastructure.LocalDbConnectionFactory, EntityFramework">
      <parameters>
        <parameter value="mssqllocaldb" />
      </parameters>
    </defaultConnectionFactory>
    <providers>
      <provider invariantName="System.Data.SqlClient" type="System.Data.Entity.SqlServer.SqlProviderServices, EntityFramework.SqlServer" />
    </providers>
  </entityFramework>
  <connectionStrings>
    <add name="Context" 
         connectionString="Data Source=(localdb)\MSSQLLocaldb;Initial Catalog=;Integrated Security=True;MultipleActiveResultSets=True" 
         providerName="System.Data.SqlClient"/>
  </connectionStrings>
</configuration>

3 Answers

Steven Parker
Steven Parker
231,198 Points

The instance name is case-sensitive.

You wrote "MSSQLLocaldb" (little "db") instead of "MSSQLLocalDB" (capital "DB").

S.Amir Nahravan
S.Amir Nahravan
4,008 Points

I think you have to write (localdb)\MSSQLLocalDB

Steven Parker
Steven Parker
231,198 Points

Wow, what a long-delay echo there is in here! :smirk:

Asaad Khattab
Asaad Khattab
38,121 Points

You forgot to capitalize DB => MSSQLLocalDB

<?xml version="1.0" encoding="utf-8"?>
<configuration>
  <configSections>
    <!-- For more information on Entity Framework configuration, visit http://go.microsoft.com/fwlink/?LinkID=237468 -->
    <section name="entityFramework" type="System.Data.Entity.Internal.ConfigFile.EntityFrameworkSection, EntityFramework, Version=6.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" requirePermission="false" />
  </configSections>
  <startup>
    <supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.6.1" />
  </startup>
  <entityFramework>
    <defaultConnectionFactory type="System.Data.Entity.Infrastructure.LocalDbConnectionFactory, EntityFramework">
      <parameters>
        <parameter value="mssqllocaldb" />
      </parameters>
    </defaultConnectionFactory>
    <providers>
      <provider invariantName="System.Data.SqlClient" type="System.Data.Entity.SqlServer.SqlProviderServices, EntityFramework.SqlServer" />
    </providers>
  </entityFramework>
  <connectionStrings>
    <add name="Context" 
         connectionString="Data Source=(localdb)\MSSQLLocalDB;Initial Catalog=;Integrated Security=True;MultipleActiveResultSets=True" 
         providerName="System.Data.SqlClient"/>
  </connectionStrings>
</configuration>