Question

What is the best way to develop on SQL Server 2005 machine locally while you get your database design and application design smoothed out and then deploy to a shared host?

In the MySQL / phpMyAdmin world you have an option to export the table as the DDL Statement with the data represented as a bunch of inserts following the DDL. Using this you can drop a table, recreate it, and load it with data all from a query window.

Is there anything close to this in the Microsoft world? Is there any free/open source tools to help with this migration of data?

Was it helpful?

Solution

SQL Server Management Studio Express (which is free) includes the "Generate Scripts" option that TheTXI referred to.

The Database Publication Wizard is a more lightweight product (also free) that is specifically for generating export scripts for both schema and data.

Caveat — neither is 100% reliable. I've sometimes had to tinker with the scripts to get them to run, particularly regarding the order of dependent objects. It's a pain, but still better than starting from scratch.

As RedBeard mentioned, you should be keeping track of your DDL scripts, in particular the "diff" scripts that will upgrade you from one revision of the database to the next. In that case, these tools would not be useful during the normal development cycle. However, if you haven't been managing your scripts this way, these tools can help you get started, and are also good for creating new instances, migrating instances, comparing snapshots, and a host of other things.

OTHER TIPS

Generate Scripts of all your database schema (tables, stored procedures, views, etc.) and also do exports of your data (if necessary) and then run those scripts and import the data into your shared host. Depending on that host, you could get access through Management Studio and it would be an even easier process.

A couple of options:

Keep track of your database's DDL scripts

You have a set of scripts that can be executed to create or update your database. You could actually pull DDL statements from your SQL Server database itself. Look in the INFORMATION_SCHEMA system views.

Example, to get information about stored procedures and their definitions, look at the ROUTINE_DEFINITION field (keep in mind you'll find some other procedures that you didn't define, but come built-in to sql server):

SELECT SPECIFIC_SCHEMA,SPECIFIC_CATALOG, SPECIFIC_NAME, ROUTINE_DEFINITION 
FROM INFORMATION_SCHEMA.ROUTINES

Use Visual Studio Database Team Edition (Comes with Developer Team Edition)

Basically it does the above for you and streamlines the setup and revision control of your database. It allows you to define data and structure, has a lot of Unit testing features as well.

Backup and Restore of your local database

Backup your local database, upload it to your host, restore the database there.

Copy/Move your MDF/LDF files

Similar to the backup/restore, you need to detach your database, copy or move the files to your web host and then reattach there.

Use the SQL Server engine to attach MDF/LDF files in the App_Data folder of ASP.NET

There should be a few examples of how this is done. It treats the database as a file, but it does require a SQL Server engine to be installed on the web host.

As an example, taken from an ASP.NET MVC template (web.config):

<connectionStrings>
  <add name="ApplicationServices" connectionString="data source=.\SQLEXPRESS;Integrated Security=SSPI;AttachDBFilename=|DataDirectory|aspnetdb.mdf;User Instance=true" providerName="System.Data.SqlClient"/>
</connectionStrings> 

TheTXI's solution is good. Making a backup and restoring it also works, and is sometimes (depending on the ISP/host's lockdown of MS SQL) the only option.

You can also choose a shared hosting company that provides a tool like myLittleBackup (www.mylittlebackup.com) so that you can easily install/restore your db on the shared server.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top