Visual Studio 2008 Database Edition GDR release - Createdeployment
Whilst preparing for my session at SQLBits next weekend I was re-watched Gert Drapers' PDC session (TL45) where he used a command tool to deploy a database via a USB pen drive (about 30 minutes into the session). Now it seems that the createdeployment command line tool he used is not currently available outside Microsoft, but the same effect can be achieved use the VSDBCMD command.
Step 1 - get the files onto the distribution device
The first step is to build the distribution media, this is just an XCOPY process. As the MSDN documentation says you need to end up with the following directory structure on your USB drive; for this example I used G: for USB drive letter and Database1 for the name of the database I want to distribute
G: copy the contents of [Program Files]Microsoft Visual Studio 9.0VSTSDBDeploy & sub directories
G: copy the dlls from[Program Files]Microsoft SQL Server Compact Editionv3.5 folder
G:Database1 copy the contents of [ProjectsFolder]DataBase1SolutionDatabase1sqldebug or release directory after the DB project is built
Step 2 - A script to do the deploy
It is now a simple process of running the command line tool, but this is a bit long to type each time so I used a batch file. My command usage was
deploy [DB name] [SQL server instance]
e.g. deploy database1 .sqlexpress
The contents of the actual deploy.bat batch file is as follows. Note there are many more options you can set but this seems to be the basic minimum
VSDBCMD /a:Deploy /dsp:Sql /cs:"Server=%2;Database=%1;Trusted_Connection=yes;" /model:%1%1.dbschema /manifest:%1%1.deploymanifest /script:%1%.sql /dd
Using this batch file a new instance of a database can be created or an existing one updated.
Note: When I first tried to get this going I keep getting SQL file create errors which appears as TSD01268 errors in the deployment log. Eventually I realised the problem. I was running on a 64Bit Windows 7 PC. My default SQLExpress instance, running as the Network Service account, was setup to and had rights to create files in C:Program Files (x86)Microsoft SQL ServerMSSQL.1MSSQLData but not in C:Program FilesMicrosoft SQL ServerMSSQL.1MSSQLData. Unfortunately the VSDBCMD tried to use the second location. Once the SQL instance was set to default to the second location and suitable rights provided all worked correctly.