I have an asp.net MVC website making extensive use of ef and migrations.
i have tried deploying it to a system running windows 10 on a local network but seems like ms has removed that options from the latest release and now deployment using web deploy is only possible on server os's.
No trying to do the same using FTP.
whats the ay to deploy using ftp on a local server. I have already setup FTP publishing but cant seem to figure out how to deploy the db and configure the app to run code first migration after every deploy.
The accepted answer in this forum post helped me out with this exact issue. I added the code given there to Application_Start in my Global.asax.cs
Database.SetInitializer(new MigrateDatabaseToLatestVersion<MyObjectContext, MyObjextContextMigration>());
MyObjectContext contexttest= new MyObjectContext();
contexttest.Database.Initialize(true);
Just be aware that this will run your seed method every time you visit your site (at least it did for me). In my configuration.cs I put in a check to see if data existed in my tables, if that data was null then it was ok to seed that table, etc.
Related
I have deployed my ASP.NET MVC application using FTP publishing method, application was working fine until i republished it after making some changes, i used code first migration to update database locally and it was working fine. When i published it again i am getting the error saying:"Model backing a DB Context has changed; Consider Code First Migrations". When using web deploy publishing method there is no problem database is updated, problem is when using FTP or File System publishing.
I would like to know how can remote database be updated when using FTP or File System publishing method. My current host doesn't offer web deploy publishing, is either i use FTP or File system.
Can anyone assist?
If you are using the File System publishing method and happen to make changes to your Models, then you will have to re-publish your project and just replace it with the one existing on the Server.
I found solution, all i have to do was to add the following code in DbContext like:
public InvoiceContext()
: base("InvoiceContext")
{
System.Data.Entity.Database.SetInitializer(new
MigrateDatabaseToLatestVersion<InvoiceContext,
Identity2Example.Migrations.InvoiceContext.Configuration>());
}
I hope it will also help somebody.
Our team works on a website with ASP MVC5 & EF5. there are 3 machines involved in my question:
Developer's machine
Test server
Production server
So a regular work cycle is: the developer adding features & puts them on the test server when there are some approved tested features they goes to the Production server.
When there are no model changes - everything works great.
But, when there are model changes - sometimes the migration gets wrong.
and the DB get so messed up so we need to backit up, clear everything & copy the data from the backup.
what we do is:
Add migration on dev-env.
Copy all the source to the test/production (Model & Migration folders).
Update database.
when doing this basic cycle some times the migration failes to update because of table already exists; I guess im doing something wrong in the process.
Another bad thing:
we have copy of the development environment on the Test & Production servers - my guess is that we dont need VS on the server in order to update version (we use the VS to run the EF commands from the package manager.
My question is
Is there any best practice/manual regarding dev->test->production process & how to do it right with code first & no visual studio on the servers?
I've been working for a client's website over the past year. I usually test things locally and then deploy straight to the production website. This has caused us some issues lately so I thought I should create a test/staging environment in which we could thoroughly test new features before pushing them into production.
Anyway, we have a VPS hosting account. I usually use remote desktop to manage the website in IIS. So in order to create a test environment, I copy pasted the folder of the production website inside the same directory (so they are both at the same level) and changed the name of the folder. Then I created a new website in IIS and mapped the physical path to the httpdocs folder inside the copied folder. After that, I setup a new application pool which basically has the same settings of the production website's application pool. I also changed the connection string of the test website.
But then when I tried to view the test website, it did not work the way I expected it to do. I keep getting &ReturnUrl=%2f appended to the query string, and the website is stripped out of its styles (the CSS). I remember this used to happen before when we were still using a shared hosting account, but I have no idea how to fix that.
I really do not know what's wrong. I basically have the same exact setup except I'm using a different port and a different database. I even tried running the test website with the application pool of the production website, but that did not work either...
Any suggestions?
looks like permission problem to me, check if your user has correct privileges in the new folder/app pool :)
The situation at the moment is that we have a sharepoint server which started out as a pilot but now actually runs as the production environment. The server on which sharepoint runs is an old machine which does not conforms the standard requirements so I want to move the current environment to the shiny new server.
I've red a lot about migrating the MOSS services, databases and content and stuff but to be honest I am kinda lost in a sea of information and I can't find the right method to do this, I've tried to install MOSS 2007 on the new server as a clean install, restored the databasses on the new server, restored the backup on the new server which I made with Sharepoint Central Administration, alas, I did not worked :-(
Lots of "Can't find this" and "Can't find that" errors...
It should be possible to grab all the data/sites/subsites/databasses/content/documents and everything else and restore that to the new server right?
Anyways, I was hoping for some step-by-step information... :-)
Regards
Erik404
I think I found a way to do a complete migration...
Install a fresh version of MOSS 2007 on the new server (Server_B). Install the features and solutions you have on Server_A. Then use the SPContentDeploymentWizard which can be downloaded for free from CodePlex to make an export of all site content and import these on Server_B. Also backup custom databases needed by features and create these on Server_B.
I do have a almost completly equal server running now, some funky errors pop up now and then so I don't think it's the best way to do it...
Also, custom developed webparts need to be deployed manually to the new server, I didn't find a way to migrate these
You are on the right track. The CodePlex solution is just a wizard GUI of what you would have to do at the command line via stsadm.
Essentially you:
Build the new server w/ all the patches, Service Packs etc that are on the old.
You will want to run a command at the cmd line to scan for and resolve any orphaned sites in your databases on Server A (command slips my mind but you can find it in TechNet - I think it's repair database - something like that)
Limit access to Server A - so you don't have user changes during your migration.
Prepare the databases for migration - another stsadm command - stsadm -o preparetomove
Detach the databases from Server A. Horrible command of -o deletedatabase - it deletes the reference but not the actual database (but still!)
Attach the databases to Server B
You should be good at that point.
As you've discovered - you can't migrate custom code, webparts etc. These need to be reinstalled. One of the reasons that solutions / features are really recommend for customizations.
Also - the search dbs, indexes etc. need to be recreated. You can't bring those over. But that's fairly straightforward - and makes sense when you think about it.
Use these scripts if you need.
http://globaldeploymentmoss2007.blogspot.ca/
What is the correct proceedure when deploying an ASP.net MVC application? I am using the built in forms based authentication and deploying using the publish function in VS2008 but when deploying it doesn't seem to deploy the ASPNETDB to the server and I end up with errors like
An error occurred during the execution of the SQL file 'InstallCommon.sql'. The SQL error number is 1802 and the SqlException message is: CREATE DATABASE failed. Some file names listed could not be created. Check related errors.
CREATE FILE encountered operating system error 5(Access is denied.) while attempting to open or create the physical file 'C:\INETPUB\WWWROOT\HOURS3\APP_DATA\ASPNETDB_TMP.MDF'.
I looked this up and attempted to change the sql server to run under the local system account as per
http://forums.asp.net/t/984436.aspx
but that doesn't seem to have helped.
When you try to publish this way, I believe you're going to overwrite your database with the one you are currently developing with. This means if you had any changes in your web environment, such as new users, you would lose them when you overwrote them in a publish. Additionally the reason you're probably getting permission denied, is because the file is already in use by the website, and Windows doesn't like it if you try deleting a file that is in use.
Typically I set my databases to publish in a different methodology than the ASP.net files. I often generate an upgrade script using a tool such as RedGate SQL Compare. This allows me to upgrade the one live on the server instead of copying a new file.