1

After publishing the complete ASP.NET MVC App, with FTP, with Visual Studio 2019, and everything working fine, database is cleared whenever I just upload one program change (DLL file publish)

I have published my first ASP.NET MVC Web App on a server. I published with FTP. All works fine but when I do a change on the code and try to upload/publish the one DLL file that changed, my database is cleared/reset.

Startup.cs will create the first user with generic password if not created yet. And this user is being created every time I upload the DLL file.

Is there anything I am missing on the web.config file? Or any other file?

If the Web App is in Production and I need to do a change, I was hoping not to have to save the database in order to do a minor update.

UPDATE ON ISSUE Thanks to @Logarr's comments below I realised that I had to look elsewhere for an answer - not a problem with the way I was publishing but a Entity Framework issue. Checked the code again and I realised that DBContext definition had the default database.initializer:

    Database.SetInitializer(new MySqlInitializer());'

So I changed it to:

    Database.SetInitializer<ApplicationDbContext>(new CreateDatabaseIfNotExists<ApplicationDbContext>());

A rookie mistake, I am sure but if anyone has any comment on this solution, please let me know.

S.Machado
  • 11
  • 3
  • Are you by chance using Entity Framework to work with your database? It sounds like you have code that initializes your database set to run every time the "program" starts. In this case, publishing a change to a site will cause it to restart and that code will execute. – Logarr Jun 13 '19 at 15:42
  • Yes, I am using EF. Wouldn't this happen also in localhost if it was something in the code to force it? – S.Machado Jun 13 '19 at 15:51
  • Depends on what you're updating on the server exactly. If it's the DLL that holds the AppStart function then yes it should happen on both. If you're updating a separate DLL perhaps the code you have deployed doesn't match your local copy. – Logarr Jun 13 '19 at 18:57
  • Thanks, @Logarr ! I will check it out and will let you know. Thanks for your help – S.Machado Jun 14 '19 at 15:12

0 Answers0