none
localdb code first database name RRS feed

  • Question

  • Hi,

    I Setup a Project in VS2013 which is using EF6 with localdb.

    I selected code first and created the data class.

    Everything is working fine and the database is created automaticaly.

    But, the Name of the database gets an extention.

    publicclassAnzeigeDB: DbContext

        {  

          publicAnzeigeDB() : base("ANZEIGEDB")

            {        }  ....

    The Name of the automatic created database is ANZEIGEDB_xxxxxxxxx.

    xxxxxxxx is changing each time I delete and re-create the database.

    Why is this happen and how can I avoid this?

    I want to code also a backup function.

    There I will need the exact database Name.

    Thanks

    Wednesday, July 9, 2014 11:19 PM

Answers

  • Hello,

    What database are you working with?

    As far as I know, the rule for generating the database name is that if your context does not inherent from base class, it will be the namespace + your context class name. If specifying the database name as your code, it would just be the string value you write in base method “base("EmployeeDBContext")”.

    What happens to your project is strange. Do you have a try to write a connection string in your app/web config file and specify the database name in it as:

    <connectionStrings>
    
        <add name="EmployeeDBContext" connectionString="data source=(localdb)\v11.0; Database=EmployeeDatabase; Integrated Security=True;MultipleActiveResultSets=True;" providerName="System.Data.SqlClient" />
    
      </connectionStrings>
    

    If you do not, please have a try this way.

    Regards.


    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click HERE to participate the survey.

    Thursday, July 10, 2014 10:03 AM
    Moderator