none
Detect if the required database doesn;t exist ? RRS feed

  • Question

  • Hello !

    I'm using SQL server 2008R2 , VB.net 2013 , Entity Framework 6.1 , DBcontext , Database First.

    I have created the model using wizard form an existing database.

    I want to know :

    When  my application run , Is there any way to detect that the database related with Model doesn't exist , so I can display an appropriate message when need it ?

    Thank you !

    Tuesday, June 16, 2015 3:55 AM

Answers

  • Hello,

    >>When  my application run , Is there any way to detect that the database related with Model doesn't

    Using DbContext.Database.Exists() as below:

    using (TestDBEntities db = new TestDBEntities())
    
                {
    
                    Console.WriteLine(db.Database.Exists().ToString());
    
                }
    

    If the depended database is deleted somehow, it would show false.

    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.

    Wednesday, June 17, 2015 2:03 AM
    Moderator