Data in database is not visible despite migrations - c#

I have a project that I developed with Asp.Net MVC5. I created the database of the project with the CodeFirst approach. When I finished I uploaded my project to github.
However, after downloading the project from github and saying "enable -migrations" and "update-database", the data in my tables is not coming.
If my internship teacher wants to test this project on his computer, he will create the database, but he will have problems because there is no data in the tables. How can I solve this problem?

You could use code first migrations to seed the database. See link for more information on it. Documentation This should make your database start with data.

Related

Applying existing migrations for ApplicationDbContext - cannot open database requested

So I have an ASP.NET MVC application that I deploy on the IIS using the Publish feature inside of Visual Studio. I have performed some changes to the existing version of the database and the application - this is what I did: I made very little changes to the database on the production server (just added a single column to two tables and made them FK to another table). Then I took the generate script from this production DB, went to the local (development) SQL server and ran the generate script to create the database locally. After this, scaffolded this local DB instance into VS (to get the modified model classes locally). Then, after some smaller modifications to the app (I was basically just adding some document upload functionality), I did the Publish and deployed that on the production server.
However, I ran into the following error when I tried to log in the website: error screenshot
Why does this happen? How can applying the migrations work through Visual Studio package manager command if I run the suggested Update-Database command locally (and from there I cannot reach the target database)?
Thank you very much for your help.
You need to add migration for your changes, as below :
Add-Migration Version2
it generates migration files, then you can run
Update-Database
to apply changes in the database.
You can not manually migrate the database changes. It should be under Add-Migration command to create a new migration version.

Trouble connecting to local SQL server database with Asp.Net Core

Just downloaded the vs community edition 2019 version 16.7.7 and it flag off an error saying couldn't download microsoft.net.4.7.targetingpack/resources however I launched the vs community 2019, started a asp.netcore web application and wrote a single class and scallfolded a controller with a CRUD view but my problem is I can not connect to the database.
My connection string is fine at the appjson setting also my startup.cs because I have checked all the suggestions offered here, and I implemented them! Please help! Is my vs-2019 corrupted.
I want to say thank you everyone for listening to me, however I figured out that I didn't generate a database creation code by enabling migration and adding a migration which will do that automatically and save a snapshot schema that will be used to create the actual database in the database management environment. Please that was my mistake. Add migration and update database and your good to code some more

Is it possible to edit a project once is published on Azure?

I'm testing an application I just published using the free option that Azure gives us.
In this process I found out that I need to make a change to a Controller (ASP.NET Core 2.0) and I've been looking for the options to do so.
I've encountered with Azure App Service Editor and I'm reading some documentation about it. However, it does not seem the way to do this kind of change since I can't access the *.cs files thru this service. This is the list of files that are shown:
So, my question is:
Is there a way to edit these files (controllers, views) with Azure App Service Editor?
If no, what would be the way to reflect this changes on my already published application? Also, in the case the answer is "republish the project", is it possible to do so without alter the information contained in the database that has been added during this test process and only update the modified files?
I apoligize if these questions are very basic but I'm just getting started to know about Azure. Thanks in advance.
How I publish it:
In order to publish this project I used the option Visual Studio gives us:
Now, if I go to the same option, this windows shows up:
Question: If I hit the 'Publish' button I believe it will republish, the whole project, correct (the database included)? If this is the case, I believe there will be conflicts about the databases, since I have already information in the project published and other information in the local project. Is it possible to reflect the update for everything but the databases?
No, you can't update the files there as this is a compiled web app, so you have to publish the update.
I'm assuming you're using EntityFramework and originally publishing the database via the web publish.
If you click "settings" on the publish dialogue, on the second page (settings tab) you'll see the options for publishing the database.
Here you'll see options as to whether to update the database during deployment, this I believe is to apply migrations. But if you uncheck these it should not update your database at all.
You should verify this after saving the publish by looking at the generated publish profile (you don't have to do a publish to see this)
It will be located at "YourApp\Properties\PublishProfiles" and should have been added to your solution, and will be called something like "Your App - Web Deploy.pubxml"
Within this you will see a <PublishDatabaseSettings> section, where the Enabled properties should be set to False
However I would advice that before publishing any update:
Test the deployment to a new server
Back up the database before deploying and test you can restore from it.

Uploading databases to a server for an ASP.NET MVC application?

I have uploaded the website files using the publishing wizard in Visual Studio. I used FTP to transfer those files. Now I'm not sure how to get my databases hooked up.
I used Code First Migrations in Entity Framework for my databases. I have three databases in my project that have been stored locally. I am trying to add them through cPanel. HostGator is the provider.
I have created 3 MySQL databases in cPanel, but I'm not sure where to go from there and I'm having trouble finding information online.
here is how you can create the DB in code first migration:
https://stackoverflow.com/a/16322232/2072676
hope it helps

ASP MVC5 deployment from TeamCity

I have a website built with ASP MVC5.
Also I use Entity Framework 6 with Database First approach and edmx.
On production I already have database with a lot of data.
I'm using TeamCity for CI and would like to perform auto deployments.
I found Web Deployments and also tried to configure Publish profiles.
But 1 have some questions:
1. What about database? how to migrate, upgrade schema and data automatically? Are there any tools for that?
2. Could you describe how publish via Web Deploy works? I see connection string definition, etc. How it copies files to remote box, and how applies DB (schema, data migration?)
3. Also I configured IIS website for FTP upload deployment. How it connected with previous cases?

Categories

Resources