Maintaining Hosting and Local Copies of Web Applications


Maintaining Hosting and Local Copies of Web Applications

 

Here are tips and tricks to help you maintain code consistency between your application on your local machine and your host.

 

Updating the Application

 

When I update the application on my host I typically wipe out (delete) the entire directory and then re-upload the entire package from my local machine. This is best done using an FTP tool (rather than the host tools). If you are not using FileZilla for this - you should download and use

 

http://filezilla-project.org/ - Use the client download for FileZilla. 

 

Updating the Database

 

Keeping the database up to date is a bit trickier. One option for the database is to completely delete all database objects and then recreate them. A good script to do this is available from Stack Overflow http://stackoverflow.com/questions/536350/sql-server-2005-drop-all-the-tables-stored-procedures-triggers-constriants-a 

 

Simply paste this into to the query analyzer and execute - and voila - the entire database is wiped out. It is easy to script the database objects locally to re-insert. Right click on Database, Tasks, Generate Scripts ... - select script all objects and it will generate a script to create the entire database that can be executed at your remote host.

 

In addition to this you will also want to have a script (in this case a stored procedure) generate inserts for data that you want to transfer from your local machine to your host. I use a script avaliable here = http://www.malgreve.net/2008/11/how-to-script-data-generate-insert-t.html . This script will place the script in the master database, making it available to all databases for generating insert scripts. 

 

When using - remember to use the USE command prior to executing the script to specify the database that you want to script data for. Then simple execute it as

USE YourDatabase
GO
EXEC sp_generate_inserts Your_Table_Name

 

As a note - be sure to right click on the Query Analyzer Screen and select Results, To Text ...

 

that will make the results easy to copy and paste. If you have identity fields in the database you are scripting you may have to manually change the insert script OR possibly change your IDENTITY INSERT to OFF to be able to use the insert script.

 

For example running this script would look like

USE MyDailyMath
GO
EXEC sp_generate_inserts Roles
GO 

 

 

 

GO
  
PRINT 'Inserting values into [Roles]'
----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
INSERT INTO [Roles] ([id],[RoleNameText],[RoleDescriptionText])
VALUES(1,'Administrator','Full rights to all parts of system')
INSERT INTO [Roles] ([id],[RoleNameText],[RoleDescriptionText])
VALUES(2,'Contributor','Allow users to contribute content to the site.')
PRINT 'Done'
  
SET IDENTITY_INSERT [dbo].[Roles] OFF
GO
SET NOCOUNT OFF 

 

I normally remove the identity insert - so the Insert looks like

 

INSERT INTO [Roles] ([RoleNameText],[RoleDescriptionText])
VALUES('Administrator','Full rights to all parts of system')
INSERT INTO [Roles] ([RoleNameText],[RoleDescriptionText])
VALUES('Contributor','Allow users to contribute content to the site.')