Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8452391
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T11:29:16+00:00 2026-06-10T11:29:16+00:00

I’m very new to MVC 3 and I’m having problem with the Code First

  • 0

I’m very new to MVC 3 and I’m having problem with the Code First approach. I created 2 models, a context, view, etc and everything works perfect (able to add, delete, etc.)

But when I check in Microsoft SQL Management Studio, I see 2 databases. One of them is the one I asked for in my web.config. This one contain only the membership table

<connectionStrings>
<add name="RecettesMaison" connectionString="Data Source=.\SQLEXPRESS;Initial Catalog=RecettesMaison;User Id=user;Password=password;"
     providerName="System.Data.SqlClient"/>

The second one has a strange name: “RecettesMaison.DB.RecettesMaisonContext”. It’s the one containing the generated table…

I would like to know where this name come from and how can I do so all the generated table goes into my connectionstring only with the name I specified. I just want one database. I’m sure it’s just one tag somewhere in the context but I can’t find this information on google.

EDIT: In a nutshel, I want my database to keep using the DropCreateDatabaseIfModelChanges<RecettesMaisonContext> but I want it to create the database with the name specified in the connection string, which is not the case (It creates a name using the namespace and the name of the database context)

Thanks!

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-10T11:29:17+00:00Added an answer on June 10, 2026 at 11:29 am

    It’s because the connectionString that you have didnt find the file for your database so CodeFirst create one automaticaly by using the full namespace of where your DbContext is for the filename.

    Insert this text in the connectionString by changing the filename.mdf by the filename that you want: AttachDBFilename=|DataDirectory|filename.mdf. The database file will be in your project\App_Data folder.

    you will have something like this:

    <connectionStrings>
        <add name="RecettesMaison" connectionString="Data Source=.\SQLEXPRESS;Initial catalog=RecettesMaison;AttachDBFilename=|DataDirectory|filename.mdf;User Id=user;Password=password;" providerName="System.Data.SqlClient"/>
    </connectionStrings>
    

    Be sure that your DbContext is using the right connectionString by passing the connectionStringName in the DbContext constructor like this:

    public class RecettesMaisonContext : DbContext
    {
        public RecettesMaisonContext()
            : base("RecettesMaison")
        {
        }
    
        protected override void OnModelCreating(DbModelBuilder modelBuilder)
        {
            var typesToRegister =
                Assembly.GetExecutingAssembly().GetTypes().Where(
                    type =>
                    type.BaseType.IsGenericType &&
                    type.BaseType.GetGenericTypeDefinition() == typeof(EntityTypeConfiguration<>));
    
            foreach (object configurationInstance in typesToRegister.Select(Activator.CreateInstance))
            {
                modelBuilder.Configurations.Add((dynamic)configurationInstance);
            }
        }
    
        ...
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

link Im having trouble converting the html entites into html characters, (&# 8217;) i
We're building an app, our first using Rails 3, and we're having to build
I have an MVC Razor view @{ ViewBag.Title = Index; var c = (char)146;
I ran into a problem. Wrote the following code snippet: teksti = teksti.Trim() teksti
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I have this code to decode numeric html entities to the UTF8 equivalent character.
I want use html5's new tag to play a wav file (currently only supported
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
I have this code: - (void)parser:(NSXMLParser *)parser foundCDATA:(NSData *)CDATABlock { NSString *someString = [[NSString
I am currently running into a problem where an element is coming back from

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.