Create database connectionStrings ASP.NET

Copper Contributor

Summarizing a little what I have, the app creates a sql database, if it is already created, it deletes it and recreates it.
I would like to understand the part of the code where it does this, which if I'm not mistaken is this.

 

 

 

 

public class ApplicationDbContext : IdentityDbContext<ApplicationUser>
    {
        public ApplicationDbContext()
            : base("DefaultConnection", throwIfV1Schema: false)
        {
            Database.SetInitializer(new IdentityDropCreateInitializer());
        }

        public static ApplicationDbContext Create()
        {
            return new ApplicationDbContext();
        }
    }

 

 

 

 

 

Could you help me understand this part of asp.net code?
In the end, what I would like to do is tell the program not to create the database, just insert tables and data, but the database neither creates nor deletes it.
Thank you.

5 Replies

Hi @apenaranda,

Thanks for posting your issue here.

However this platform is used for how-to discussions and sharing best practices for building any app with .NET.Since your issue is a technical question, welcome to post it in Microsoft Q&A forum, the support team and communities on Microsoft Q&A will help you for any technical questions.
Besides, it will be appreciated if you can share it here once you post this technical question Microsoft Q&A.
Best Regards,
Lan Huang

Thank you very much, I will do so and as soon as I have a resolution I will share it.
Cheers

Hi, @apenaranda thank you for sharing such amazing info. this code is work perfectly but I have one question how do we insert the delete the database again with the same name or the same file in SQL? 

Hello, indeed the code works perfectly, what I would be interested in knowing is precisely what you are asking, where is it told to delete and create the database again? In the end, the problem I have is that I don't always want to create the database again, just update it.