You finish building a great ASP. NET application, have everything tested and working right on your local system, are taking full advantage of the new ASP. NET 2.0 membership, role and profile features, and are ready to publish it to a remote hosting environment and share it with the world.
Copying. aspx files and compiled assemblies to the remote system is pretty easy (just FTP or copy them up ). the challenge that confronts a lot of developers, though, is how to setup and recreate the database contents-both SchemaAndData-on the remote hosted site. Unfortunately there hasn't historically been a super-easy way to accomplish this.
The good news is that this week the SQL Server team published the release candidate of a new SQL server hosting toolkit that will make it much, much easier to deploy your SQL solutions remotely to a hosted environment. the toolkit allows you to work with SQL Express, SQL Server 2000, and SQL Server 2005 databases locally, and then easily transfer your SchemaAndData and install them into a shared hosting Remote SQL Server account.
The below post describes how you can start using this today.SQL server hosting Toolkit
The SQL server hosting toolkit is available for free, and ships with a database Publishing Wizard that supports two database hosting deployment scenarios:
1) The database publishing wizard enables you to point at a database you are working with on your local system, and then automatically create. SQL script file that contains the setup logic needed to re-create an exact replica of the database on any remote system. this. SQL script schemas des everything needed to create the database schema (tables, views, sprocs, triggers, full-text catalogs, roles, rules, etc-full details here ), as well as populate the new database with the same table row contents as your local database (this is analogous to the MySQL dump utility ). the benefit of having this setup logic encapsulated in a single. SQL file is that most hosters already support the ability for you to upload. SQL files to their hosted environments and run these scripts via their hosting admin control panels. assuming you have a web Hoster that supports this today, you can immediately start using the database Publishing Wizard to easily deploy your sites without requiring anything to be installed or configured by the Hoster.
2) The database Publishing Wizard also enables you to point at a database you are working with on your local system, and then use web-services to transfer and recreate the database in your remote Hoster environment (without you having to create. SQL file or use the Hoster Admin Control Panel to run it ). this publishing option does require that a SQL Publishing Web-service be exposed in the hosting environment, and the SQL server hosting Toolkit provided des a free implementation of this SQL Publishing Web-service that we'll be working with hosters to aggressively deploy.
The database publishing wizard enables you to use either SQL express or SQL Server 2000/2005 locally, and then use either SQL 2000 or SQL 2005 in the remote Hoster environment. ItDoes notRequire that the versions of SQL match-so you can use SQL express 2005 locally and then upload to a SQL 2000 server in the hosting environment without having to change any of your code.
The database Publishing Wizard also supports handling the built-in ASP. NET 2.0 membership, role management, profile and health monitoring schemas. A lot of people have run into issues because the built-in. SQL scripts that ship by default with ASP. net for setting up these schemas require DBO permissions at install-time for the SQL scripts -- which a lot of hosters don't support (note: the scriptsDo notRequire DBO permissions at runtime-only for install time, but this can sometimes still be a blocker in itself unless the Hoster is willing to install them for you ). the database Publishing Wizard on the other-handDoes notRequire DBO permissions when installing the ASP. net membership, roles and profile schemas/data, and shocould enable you to deploy the aspnetdb tables + sprocs just as easily as any other database using the database Publishing Wizard.First Tutorial: deploying a SQL express database to a SQL server hosting account (using. SQL files)
I'll be doing a series of posts over the next few weeks showing how to use the varous features within the SQL server hosting toolkit. this first tutorial in the series covers how to use it to easily generate. SQL installation file of a local SQL express database that you can then copy to a remote hosting account and use to re-create a SQL Server database for you to use with your hosted site.
Step 0: download and install the database Publishing Wizard
The first step we'll need to-do is to make sure we have the database Publishing Wizard from the SQL hosting toolkit installed. Click here to download it and install it.
The database Publishing Wizard comes with support for both a GUI based wizard, as well as a command-line utility. the GUI based wizard can be run either standalone or via context-menu support that it adds to the Server Explorer in both Visual Studio 2005 and Visual Web Developer Express. for the purposes of this tutorial we'll be using this later Server Explorer integration-which makes publishing really easy.
Step 1: Create an ASP. NET web-site that uses a local SQL express or SQL Server database
To help with this demo, we will use the built-in personal starter kit template that ships with both VS 2005 and Visual Web Developer Express. to create a new web project based on it, select File-> new web site within vWD or Vs and choose the "personal Starter Kit" template in the new web-site dialog. by default the personal starter kit application is configured to use SQL Express (which is free and can be downloaded here ). when run the sample looks like below:
After creating the application, you can then run the Web Admin Tool (choose the website-> Asp. net configuration menu item in vWD/VS) and create a new user and add them to the "admin" role for the site. you can then login as this new admin user and try uploading new pictures and/or customizing the existing ones on the site (note that both the picture meta-data, as well as the raw image binaries are stored in a database when you do this ):
Once you are all done with the above steps we'll have two SQL express databases installed within the \ app_data directory for our project. One of the SQL express databases is namedPersonal. MDFAnd contains the tables and stored procedures specific to our web-site (photo and album tables, as well as basic content management support). The other SQL express database is namedAspnetdb. MDFAnd contains the database storage for the default ASP. NET 2.0 membership, role and profile providers (which the application above is using for login and admin purposes ).
Step 2: Creating. SQL installation scripts for our database
Now that we 've created a new application + local database, and added custom data to it (new users + their role membership, as well as new photos and albums ), we want to deploy the application to a remote hosting server.
The first step we'll take is to create. SQL script files that will enable us to automate re-creating the exact same database schema + database content on our remote hosting account. to-Do this we'll use the database Publishing Wizard we installed as part of the SQL hosting toolkit.
To begin, click on the "Server Explorer" tab within Visual Studio or visual web developer to see the databases that the application is using:
As you can see in the above picture, we have two SQL express databases that we are using: aspnetdb. MDF and personal. MDF. to generate. SQL installation files for each one, simply select the database in the Solution Explorer, then right-click and select the new "Publish to provider" context menu item (added by the database Publishing Wizard) setup on it:
This will launch the database Publishing Wizard and allow us to walkthrough scripting the installation of our database. as I mentioned in the intro of this blog post, the database Publishing Wizard supports two deployment options: 1) to generate. SQL install script files that you can copy to your remote Hoster and run using their existing Web Admin Control Panel tools, or 2) to upload the database directly using database publishing Web-services on the Hoster web-site.
For this first tutorial, we'll be using the. SQL script file approach-So keep the default radio button selected and provide a name for the. SQL install script file you want to generate:
When you click "Next" you'll be given the option to customize some of preferences when creating. SQL setup file. note that you can control whether to drop existing objects within the target database, whether you want to target SQL 2000 or SQL 2005 with the script, and whether you want to setup both the schema and data, or just the schema, or just the data:
For this tutorial just keep the defaults selected, and hit next and generate the. SQL script:
You now have a personal. SQL file that contains a script that you can run on any SQL Server to re-create all the tables, sprocs, views, triggers, full-text catalogs, etc. for a database, as well as import and add all of the table row data that was in the database at the time. SQL file was created.
The. SQL file itself is just plain text-so you can open it up with any text editor to see it and/or customize it with your own statements:
Notice above how. SQL file names des both the SQL DDL needed to create the photos table (including all of its constraints and primary-key/foreign-key relationships ), as well as the SQL to insert data within the table once it is created (in the case abve it is even inserting binary data for the photos-since they are stored in the database ).
Once you repeat these steps for the aspnetdb SQL express database as well you'll have two. SQL installation scripts that you can use to automatically re-create your SQL database on any SQL Server:
Note that the. SQL files we built can be used to create two separate databases on a server,OrThey can both be run against the same database to create a single database that has a unified set of tables, sprocs, and data for the application. to accomplish this, simply run both scripts against the same database, and assuming no table or sproc names conflict, you'll have a single database containing everything. this later option is very useful when you have a hosting account that only provides 1 database instance for you to use!
Step 3: using our. SQL files to create our remote databases
Now that we have our. SQL files, we can go about using them to install our database at our Hoster. exactly how we use. SQL files to install the database will vary depending on how the Hoster gives us access to our SQL account. some hosters provide an HTML based file-upload tool that allows you to provide. SQL file-which they will then execute against the SQL database you own.
Other hosters provide an online query tool (like below) that allows you to copy/paste SQL statements to run against your database. if you have a Hoster which provides an online query tool like this, then you can open. SQL file with a text-Editor and copy/paste the contents into the query textbox and run it.
The quality of the SQL tools that different hosters provide varies quite a bit. in testing the database Publishing Wizard we found that some custom-made SQL admin tools provided by hosters had issues where they incorrectly parsed valid SQL statements (in particle goto statements ). this page describes one issue you might see some hosters have with Goto statements, along with a workaround you can use. to help improve the overall quality of SQL hosting Admin Tools, the SQL Server team early next year is going to be shipping the source to a free SQL HTML admin tool that hosters will be able to integrate into their experiences. hopefully this will help improve the standard experience with all windows hosters.
If your Hoster has no usable HTML Web Admin Tool for allowing you to easily manage your SQL database, then you can also just write a simple ASP. NET page that you FTP (along with your. SQL file) to your web-site and then hit to read. SQL file on the server in as text, and then pass it as a string to ADO. net to execute. this will give you the same result as the query analyzer above-and fully create your database for you.
Step 4: updating our connection-string within web. config
Once we 've got our data uploaded within a database at our Hoster, we'll want to upload our. aspx files, assemblies and content to the remote site (typically this is done over FTP ).
The last step we'll need to take is to open up our web. config File and update the <connectionstrings> section to point at our new database location at the remote Hoster. note that you'll need to get the exact SQL Server, database name, and username/password account to use from the Hoster.
Using our personal starter kit example above, we 'd change the <connectionstrings> section within its web. config file from the default connection-string (which uses two SQL express database in the Local \ app_data directory ):<Connectionstrings>
To instead use a single SQL Server 2000 database (the "scottgudb" database on the "server123" box ).<Connectionstrings>
We were able to use a single database (instead of the two above) Because we ran both. SQL files against the single database-which merged all schema and data into a single database instance.
Step 5: We are done
Now we can run the application remotely in a hosted environment, and it shoshould just work.Summary
The database Publishing Wizard that ships as part of the SQL hosting toolkit shocould make creating. SQL files for any database (SQL express or full SQL Server) really easy. you can use this to easily dump your local database and then use it to re-create the exact same database on a remote system.
In future tutorials I'll also show how you can actually re-create your database remotely without even having to generate. SQL file (Instead you can publish the database directly from vs to your Hoster over a web-service ). stay tuned for details on how to-do this soon.
Hope this helps,
P.s. we are planning on adding the database Publishing Wizard into Visual Studio "orcas" (which is the next release of VS), which means you won't need to download it separately in that timeframe. but we wanted to make sure you didn't have to wait until then, which is why we are making it available today for Visual Studio 2005 and Visual Web Developer express 2005.