<?xml version="1.0" encoding="UTF-8" ?>
<?xml-stylesheet type="text/xsl" href="http://sqlblog.com/utility/FeedStylesheets/rss.xsl" media="screen"?><rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/" xmlns:wfw="http://wellformedweb.org/CommentAPI/"><channel><title>Search results matching tags 'SQL Server' and 'Visual Studio 2010'</title><link>http://sqlblog.com/search/SearchResults.aspx?o=DateDescending&amp;tag=SQL+Server,Visual+Studio+2010&amp;orTags=0</link><description>Search results matching tags 'SQL Server' and 'Visual Studio 2010'</description><dc:language>en-US</dc:language><generator>CommunityServer 2.1 SP2 (Build: 61129.1)</generator><item><title>Implementing SQL Server solutions using Visual Studio 2010 Database Projects – a compendium of project experiences</title><link>http://sqlblog.com/blogs/jamie_thomson/archive/2012/01/01/implementing-sql-server-solutions-using-visual-studio-2010-database-projects-a-compendium-of-project-experiences.aspx</link><pubDate>Sun, 01 Jan 2012 18:13:00 GMT</pubDate><guid isPermaLink="false">21093a07-8b3d-42db-8cbf-3350fcbf5496:40711</guid><dc:creator>jamiet</dc:creator><description>&lt;p&gt;Over the past eighteen months I have worked on four separate projects for customers that wanted to make use of Visual Studio 2010 Database projects to manage their database schema.* All the while I have been trying to take lots of notes in order that I can write the blog post that you are reading right now – a compendium of experiences and tips from those eighteen months. I should note that this blog post should not necessarily be taken as a recommendation to actually &lt;i&gt;use&lt;/i&gt; database projects in Visual Studio 2010 – it is intended to be useful for those of you that have already made the decision to use them; having said that, I do make recommendations as to actions I think you should take if you have made that decision.&lt;/p&gt;  &lt;p&gt;First let’s be clear what we’re talking about here. Visual Studio Database Projects have been known by a few different names down the years, some of which you may be familiar with. If you have ever heard the terms datadude, DBPro, teamdata, TSData or Visual Studio Team System for Database Professionals then just know that all of these terms refer to the same thing, namely the project type highlighted below when starting a new project in Visual Studio:&lt;/p&gt;  &lt;blockquote&gt;   &lt;p&gt;&lt;a href="http://sqlblog.com/blogs/jamie_thomson/image_4302F9CA.png"&gt;&lt;img style="border-width:0px;padding-top:0px;padding-right:0px;padding-left:0px;display:inline;background-image:none;" title="image" border="0" alt="image" src="http://sqlblog.com/blogs/jamie_thomson/image_thumb_4079C80C.png" width="748" height="411"&gt;&lt;/a&gt;&lt;/p&gt; &lt;/blockquote&gt;  &lt;p&gt;From here onwards I am going to refer to Visual Studio Database projects and all the features therein simply as datadude because that’s a popular colloquial name (and is also much quicker to type). Know also that at the time of writing the features that I am talking about here are currently undergoing some changes ahead of the next release of SQL Server (i.e. SQL Server 2012) in which these features are mooted to be delivered under a new moniker - SQL Server Developer Tools (SSDT).&lt;/p&gt;  &lt;p&gt;OK, with all those preliminaries out of the way let’s dig in.&lt;/p&gt;  &lt;h1&gt;Continuous Integration&lt;/h1&gt;  &lt;p&gt;&lt;a href="http://www.martinfowler.com/articles/continuousIntegration.html" target="_blank"&gt;Continuous Integration&lt;/a&gt; (CI) is a development practise that has existed for many years but in my experience has not been wholly embraced by the database community. The idea behind CI for databases is that every time a developer checks-in a piece of code be it a stored procedure, a table definition or whatever, the entire database project is built and then deployed to a database instance. Microsoft provide a useful article &lt;a href="http://msdn.microsoft.com/en-us/library/aa833165.aspx" target="_blank"&gt;An Overview of Database Build and Deployment&lt;/a&gt; that goes some way to explaining how to setup your CI deployment.&lt;/p&gt;  &lt;p&gt;CI is one of the fundamental tenets that underpins a lot of the things I talk about later in this blog post and hence gives rise to my first recommendation when using datadude:&lt;/p&gt;  &lt;blockquote&gt;   &lt;p&gt;&lt;font size="4"&gt;Recommendation #1: Use Source Control and implement a Continuous Integration deployment&lt;/font&gt;&lt;/p&gt; &lt;/blockquote&gt;  &lt;p&gt;&lt;i&gt;In an earlier draft of this blog post I outlined in detail the CI configuration from one of the aforementioned projects. Its not suitable for inclusion at this point in the current draft but I still think there is some useful information to be gleaned so I have included it below in “Appendix – An example CI configuration”.&lt;/i&gt;&lt;/p&gt;  &lt;h1&gt;Composite Projects&lt;/h1&gt;  &lt;p&gt;Each of the four aforementioned projects were brownfield projects meaning that each already encompassed some established, deployed, databases and they wanted to bring those databases under the control of datadude. Each project had thousands of objects across multiple databases and in this situation it is very likely that some of the stored procedures, views or functions will refer to objects in one of the other databases. The way to resolve those references is to use &lt;a href="http://blogs.msdn.com/b/gertd/archive/2007/07/26/database-references.aspx" target="_blank"&gt;database references&lt;/a&gt; however once you have applied all of your database references it is still very possible that you will run into a situation where code in database A refers to an object in database B while at the same time database B refers to an object in database A. This is depicted in the following figure:&lt;/p&gt;  &lt;blockquote&gt;   &lt;p&gt;&lt;a href="http://sqlblog.com/blogs/jamie_thomson/image_05B21F36.png"&gt;&lt;img style="border-width:0px;padding-top:0px;padding-right:0px;padding-left:0px;display:inline;background-image:none;" title="image" border="0" alt="image" src="http://sqlblog.com/blogs/jamie_thomson/image_thumb_2BA7CF8C.png" width="435" height="228"&gt;&lt;/a&gt;&lt;/p&gt; &lt;/blockquote&gt;  &lt;p&gt;Here we have a view [DB1]..[View2] that selects data from [DB2]..[Table1] and a view [DB2]..[View1] that selects data from [DB1]..[Table1]. Datadude does not allow a database reference from [DB2] to [DB1] if there is already a database reference from [DB2] to [DB1] and hence will return an error akin to:&lt;/p&gt;  &lt;ul&gt;   &lt;li&gt;SQL03006: View: [dbo].[View1] has an unresolved reference to object [DB1].[dbo].[Table1]. &lt;/li&gt; &lt;/ul&gt;  &lt;blockquote&gt;   &lt;p&gt;&lt;a href="http://sqlblog.com/blogs/jamie_thomson/image_0395206D.png"&gt;&lt;img style="border-width:0px;padding-top:0px;padding-right:0px;padding-left:0px;display:inline;background-image:none;" title="image" border="0" alt="image" src="http://sqlblog.com/blogs/jamie_thomson/image_thumb_096FC406.png" width="574" height="108"&gt;&lt;/a&gt;&lt;/p&gt; &lt;/blockquote&gt;  &lt;p&gt;We have the proverbial chicken-and-egg problem, [DB1] can’t be created before [DB2] and vice versa. This problem is solved by using &lt;i&gt;&lt;b&gt;Composite Projects&lt;/b&gt;&lt;/i&gt; (not to be confused with Partial Projects) which allow you to split objects that are intended to be in the same database over multiple datadude projects. I could go over how you set one of these things up but there’s really no need because there is a rather excellent walkthrough on MSDN at &lt;a href="http://msdn.microsoft.com/en-us/library/dd193415.aspx" target="_blank"&gt;Walkthrough: Partition a Database Project by Using Composite Projects&lt;/a&gt;; the reason for me mentioning it here is to make you aware that composite projects exist and of the problem that they solve. If you are introducing datadude into a brownfield project then it is highly likely that you are going to require composite projects so learn them and learn them good.&lt;/p&gt;  &lt;p&gt;One important last note about composite projects is to answer the question “How does the tool know that the multiple projects refer to the same database?” The answer is given at the walkthrough that I linked to above; namely, it says:&lt;/p&gt;  &lt;blockquote&gt;   &lt;p&gt;&lt;a href="http://sqlblog.com/blogs/jamie_thomson/image_5A3DD86E.png"&gt;&lt;img style="border-width:0px;padding-top:0px;padding-right:0px;padding-left:0px;display:inline;background-image:none;" title="Composite projects - referring to the same database" border="0" alt="Do not specify server variables and values or database variables and values when you define references in a composite project. Because no variables are defined, the referenced project is assumed to share the target server and database of the current project." src="http://sqlblog.com/blogs/jamie_thomson/image_thumb_7509FE7A.png" width="631" height="116"&gt;&lt;/a&gt;&lt;/p&gt; &lt;/blockquote&gt;  &lt;blockquote&gt;   &lt;p&gt;&lt;i&gt;“Do not specify server variables and values or database variables and values when you define references in a composite project. Because no variables are defined, the referenced project is assumed to share the target server and database of the current project.”&lt;/i&gt;&lt;/p&gt; &lt;/blockquote&gt;  &lt;p&gt;So now you know! To put it another way, if you reference one project from another and don’t tell datadude that the two projects refer to different databases then it assumes they refer to the &lt;i&gt;same &lt;/i&gt;database.&lt;/p&gt;  &lt;h1&gt;Code Analysis&lt;/h1&gt;  &lt;p&gt;Datadude provides the ability to analyse your code projects for code in stored procedures and functions that it considers to be inferior and highlight it – this feature is called &lt;b&gt;&lt;i&gt;Code Analysis&lt;/i&gt;&lt;/b&gt;. Note that Code Analysis will not highlight code that is syntactically incorrect (datadude does that already, which may well be considered its core feature), it highlights code that is syntactically correct but may be considered defective when executed. Specifically Code Analysis will highlight the following perceived code defects (click through on the links for explanations of why these are considered code defects):&lt;/p&gt;  &lt;ul&gt;   &lt;li&gt;&lt;a href="http://msdn.microsoft.com/en-us/library/dd193296.aspx" target="_blank"&gt;Use of SELECT *&lt;/a&gt; &lt;/li&gt;    &lt;li&gt;&lt;a href="http://msdn.microsoft.com/en-us/library/dd172121.aspx" target="_blank"&gt;Use of @@IDENTITY rather than SCOPE_IDENTITY()&lt;/a&gt; &lt;/li&gt;    &lt;li&gt;&lt;a href="http://msdn.microsoft.com/en-us/library/dd193263.aspx" target="_blank"&gt;NCHAR &amp;amp; NVARCHAR fields whose maximum length is 1 or 2&lt;/a&gt; &lt;/li&gt;    &lt;li&gt;&lt;a href="http://msdn.microsoft.com/en-us/library/dd172122.aspx" target="_blank"&gt;Deprecated join syntax&lt;/a&gt; &lt;/li&gt;    &lt;li&gt;&lt;a href="http://msdn.microsoft.com/en-us/library/dd172136.aspx" target="_blank"&gt;An output parameter that might not be assigned to&lt;/a&gt; &lt;/li&gt;    &lt;li&gt;&lt;a href="http://msdn.microsoft.com/en-us/library/dd193269.aspx" target="_blank"&gt;Casts that could result in data loss&lt;/a&gt; (in my experience this is the one that shows up most often – particularly in inherited code) &lt;/li&gt;    &lt;li&gt;&lt;a href="http://msdn.microsoft.com/en-us/library/dd172134.aspx" target="_blank"&gt;Use of special characters in object names&lt;/a&gt; &lt;/li&gt;    &lt;li&gt;&lt;a href="http://msdn.microsoft.com/en-us/library/dd193421.aspx" target="_blank"&gt;Use of reserved words&lt;/a&gt; &lt;/li&gt;    &lt;li&gt;&lt;a href="http://msdn.microsoft.com/en-us/library/dd172115.aspx" target="_blank"&gt;Use of sp_ prefix for stored procedures&lt;/a&gt; &lt;/li&gt;    &lt;li&gt;&lt;a href="http://msdn.microsoft.com/en-us/library/dd193249.aspx" target="_blank"&gt;Use of unindexed columns in IN predicates&lt;/a&gt; &lt;/li&gt;    &lt;li&gt;&lt;a href="http://msdn.microsoft.com/en-us/library/dd193273.aspx" target="_blank"&gt;Use of patterns beginning with a wildcard in a LIKE predicate&lt;/a&gt; &lt;/li&gt;    &lt;li&gt;&lt;a href="http://msdn.microsoft.com/en-us/library/dd193264.aspx" target="_blank"&gt;Code that would not use an existing index that might actually be beneficial&lt;/a&gt; &lt;/li&gt;    &lt;li&gt;&lt;a href="http://msdn.microsoft.com/en-us/library/dd193267.aspx" target="_blank"&gt;Use of ISNULL() on nullable columns&lt;/a&gt; &lt;/li&gt;    &lt;li&gt;&lt;a href="http://msdn.microsoft.com/en-us/library/dd193285.aspx" target="_blank"&gt;Deterministic function calls in a WHERE predicate&lt;/a&gt; &lt;/li&gt; &lt;/ul&gt;  &lt;p&gt;In my opinion the best aspect of Code Analysis is that it can be run as part of your Continuous Integration deployment meaning that if anyone checks in some deficient code, BOOM, your CI deployment fails and the developer is left red-faced. Nothing else has increased the code quality on my projects quite like running Code Analysis as part of a CI deployment.&lt;/p&gt;  &lt;p&gt;Hopefully I have convinced you that turning on Code Analysis is a good idea. If you agree then head to the project properties and check the box labelled &lt;b&gt;Enable Code Analysis on Build&lt;/b&gt;. I also recommend checking the &lt;b&gt;Treat warnings as errors&lt;/b&gt; boxes otherwise you’ll find that &lt;a href="http://www.codinghorror.com/blog/2007/08/discipline-makes-strong-developers.html" target="_blank"&gt;undisciplined developers&lt;/a&gt; will simply ignore the warnings.&lt;/p&gt;  &lt;blockquote&gt;   &lt;p&gt;&lt;a href="http://sqlblog.com/blogs/jamie_thomson/image_0CC135E1.png"&gt;&lt;img style="border-width:0px;padding-top:0px;padding-right:0px;padding-left:0px;display:inline;background-image:none;" title="Enable datadude code analysis" border="0" alt="Enable datadude code analysis" src="http://sqlblog.com/blogs/jamie_thomson/image_thumb_129BD97A.png" width="583" height="204"&gt;&lt;/a&gt;&lt;/p&gt; &lt;/blockquote&gt;  &lt;blockquote&gt;   &lt;p&gt;&lt;i&gt;N.B. Incidentally if you have time I highly recommend that you go and read the blog post I linked to there – &lt;/i&gt;&lt;a href="http://www.codinghorror.com/blog/2007/08/discipline-makes-strong-developers.html" target="_blank"&gt;&lt;i&gt;Discipline Makes Strong Developers&lt;/i&gt;&lt;/a&gt;&lt;i&gt; by Jeff Atwood. I’ve read many thousands of blog posts in my time and that is the one that has influenced me more than any other.&lt;/i&gt;&lt;/p&gt; &lt;/blockquote&gt;  &lt;p&gt;Turning on Code Analysis on a greenfield project is a no-brainer. On a brownfield project its not quite so easy – on a recent engagement I moved a single database into datadude and turned on Code Analysis which immediately found over two thousand perceived code defects. I generally abhor the use of that famous maxim &lt;a href="http://en.wikipedia.org/wiki/If_it_ain%27t_broke,_don%27t_fix_it#.22If_it_ain.27t_broke.2C_don.27t_fix_it..22" target="_blank"&gt;if it aint broke, don’t fix it&lt;/a&gt;&lt;i&gt;&lt;/i&gt; in our industry but on occasions like this you may be well advised to heed that advice and leave well alone for fear of breaking code that does what it is supposed to (no matter how inefficiently it does it). Instead you do have the option to suppress Code Analysis warnings/errors:&lt;/p&gt;  &lt;blockquote&gt;   &lt;p&gt;&lt;a href="http://sqlblog.com/blogs/jamie_thomson/image_434EE125.png"&gt;&lt;img style="border-width:0px;padding-top:0px;padding-right:0px;padding-left:0px;display:inline;background-image:none;" title="Suppress datadude code analysis" border="0" alt="Suppress datadude code analysis" src="http://sqlblog.com/blogs/jamie_thomson/image_thumb_492984BE.png" width="585" height="195"&gt;&lt;/a&gt;&lt;/p&gt; &lt;/blockquote&gt;  &lt;p&gt;I advise using Code Analysis suppression sparingly. Recently I discovered that one of the developers on my team had decided it was OK to simply suppress every error that was thrown by Code Analysis without first investigating the cause. I was not amused!&lt;/p&gt;  &lt;blockquote&gt;   &lt;p&gt;&lt;font size="4"&gt;Recommendation #2: Turn on Code Analysis&lt;/font&gt;&lt;/p&gt; &lt;/blockquote&gt;  &lt;h1&gt;Realising the value of idempotency&lt;/h1&gt;  &lt;p&gt;An operation is considered idempotent if it produces the same result no matter how many times that operation is applied; for example, multiplication by a factor of one is an idempotent operation – no matter how many times you multiple a number by one the result will always be the same.&lt;/p&gt;  &lt;p&gt;Idempotency is a vital facet of database deployment using datadude. Datadude tries to ensure that no matter how many times you deploy the same project the state of your database should be the same after each deployment. The implication here is that during a deployment datadude will examine the target database to see what changes (if any) need to be made rather than simply attempting to create lots of objects; if all the objects already exist nothing will be done. In my opinion this is the single biggest benefit of using datadude – you don’t have to determine what needs to be done to change your database schema to the desired state, datadude does it for you.&lt;/p&gt;  &lt;p&gt;If I have convinced you about the value of idempotency within datadude then you should also realise that the same rigour should be applied to data as well. Datadude provides Post-Deployment scripts that allow you to deploy data to your schema however there is no inbuilt magic here – datadude will simply go and run those scripts as-is, it will not try and comprehend the contents of those scripts. What this means is that you, the developer, are responsible for making your Post-Deployment scripts idempotent and the easiest way to do that is to employ the T-SQL MERGE statement.&lt;/p&gt;  &lt;p&gt;T-SQL’s INSERT is not sufficient as it will work once and thereafter fail as it will be attempting to insert already inserted data; this gives rise to my third recommendation:&lt;/p&gt;  &lt;blockquote&gt;   &lt;p&gt;&lt;font size="4"&gt;Recommendation #3: When running your deployment in a test environment, run it more than once.&lt;/font&gt;&lt;/p&gt; &lt;/blockquote&gt;  &lt;h1&gt;No-brainer Recommendations&lt;/h1&gt;  &lt;p&gt;I consider Code Analysis and Idempotency to be so important that I called them out as dedicated headlines. In this section I’ll outline some additional simple measures that you can undertake and which will, if employed correctly, have a profound effect on the success of your datadude projects.&lt;/p&gt;  &lt;h2&gt;Putting a build number into the DB&lt;/h2&gt;  &lt;p&gt;I find it is very useful to maintain a log of deployments that have been made to a database and my chosen method is to use a Post-Deployment script to insert a value into some table. Here’s the definition of the table I use for this:&lt;/p&gt;  &lt;blockquote&gt;   &lt;p&gt;&lt;code style="font-size:12px;"&gt;&lt;span style="color:blue;"&gt;CREATE TABLE &lt;/span&gt;&lt;span style="color:black;"&gt;[dbo].[DeployLog]          &lt;br&gt;&lt;/span&gt;&lt;span style="color:gray;"&gt;(          &lt;br&gt;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;span style="color:black;"&gt;[BuildId]&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;span style="color:blue;"&gt;NVARCHAR&lt;/span&gt;&lt;span style="color:gray;"&gt;(&lt;/span&gt;&lt;span style="color:black;"&gt;50&lt;/span&gt;&lt;span style="color:gray;"&gt;)          &lt;br&gt;,&amp;nbsp; &lt;/span&gt;&lt;span style="color:black;"&gt;[DeployDatetime]&amp;nbsp;&amp;nbsp;&amp;nbsp; SMALLDATETIME          &lt;br&gt;&lt;/span&gt;&lt;span style="color:gray;"&gt;,&amp;nbsp; &lt;/span&gt;&lt;span style="color:blue;"&gt;CONSTRAINT&amp;nbsp; &lt;/span&gt;&lt;span style="color:black;"&gt;PK_dboDeployLog &lt;/span&gt;&lt;span style="color:blue;"&gt;PRIMARY KEY &lt;/span&gt;&lt;span style="color:gray;"&gt;(&lt;/span&gt;&lt;span style="color:black;"&gt;[DeployDatetime]&lt;/span&gt;&lt;span style="color:gray;"&gt;)          &lt;br&gt;)&lt;/span&gt;&lt;/code&gt; &lt;/p&gt; &lt;/blockquote&gt;  &lt;p&gt;In my Post-Deployment script I will use:&lt;/p&gt;  &lt;blockquote&gt;   &lt;p&gt;&lt;code style="font-size:12px;"&gt;&lt;span style="color:blue;"&gt;INSERT &lt;/span&gt;&lt;span style="color:black;"&gt;[dbo].[DeployLog]&lt;/span&gt;&lt;span style="color:gray;"&gt;(&lt;/span&gt;&lt;span style="color:black;"&gt;[BuildId]&lt;/span&gt;&lt;span style="color:gray;"&gt;,&lt;/span&gt;&lt;span style="color:black;"&gt;[DeployDatetime]&lt;/span&gt;&lt;span style="color:gray;"&gt;)          &lt;br&gt;&lt;/span&gt;&lt;span style="color:blue;"&gt;VALUES &lt;/span&gt;&lt;span style="color:gray;"&gt;(&lt;/span&gt;&lt;span style="color:red;"&gt;'$(BuildId)'&lt;/span&gt;&lt;span style="color:gray;"&gt;,&lt;/span&gt;&lt;span style="color:magenta;"&gt;GETDATE&lt;/span&gt;&lt;span style="color:gray;"&gt;());&lt;/span&gt;&lt;/code&gt; &lt;/p&gt; &lt;/blockquote&gt;  &lt;p&gt;to insert a row into that table during every deployment. &lt;font color="#ff0000"&gt;$(BuildId)&lt;/font&gt; is a variable defined in the .sqlcmdvars file of my project:&lt;/p&gt;  &lt;blockquote&gt;   &lt;p&gt;&lt;a href="http://sqlblog.com/blogs/jamie_thomson/image_0ECE0EDD.png"&gt;&lt;img style="border-width:0px;padding-top:0px;padding-right:0px;padding-left:0px;display:inline;background-image:none;" title="image" border="0" alt="image" src="http://sqlblog.com/blogs/jamie_thomson/image_thumb_0D8975FE.png" width="293" height="216"&gt;&lt;/a&gt;&lt;/p&gt; &lt;/blockquote&gt;  &lt;p&gt;Here is what we see inside that file:&lt;/p&gt;  &lt;blockquote&gt;   &lt;p&gt;&lt;a href="http://sqlblog.com/blogs/jamie_thomson/image_5E578A66.png"&gt;&lt;img style="border-width:0px;padding-top:0px;padding-right:0px;padding-left:0px;display:inline;background-image:none;" title="image" border="0" alt="image" src="http://sqlblog.com/blogs/jamie_thomson/image_thumb_64322DFF.png" width="526" height="219"&gt;&lt;/a&gt;&lt;/p&gt; &lt;/blockquote&gt;  &lt;p&gt;The &lt;font color="#ff0000"&gt;$(BuildId)&lt;/font&gt; variable has been defined with a default value of UNKNOWN and hence subsequent deployments from Visual Studio will result in the following:&lt;/p&gt;  &lt;blockquote&gt;   &lt;p&gt;&lt;a href="http://sqlblog.com/blogs/jamie_thomson/image_5BCE58A8.png"&gt;&lt;img style="border-width:0px;padding-top:0px;padding-right:0px;padding-left:0px;display:inline;background-image:none;" title="image" border="0" alt="image" src="http://sqlblog.com/blogs/jamie_thomson/image_thumb_0F964EFA.png" width="513" height="284"&gt;&lt;/a&gt;&lt;/p&gt; &lt;/blockquote&gt;  &lt;p&gt;On first glance that might not seem particularly useful however it comes into its own if you are doing CI deployments (see recommendation #1) because each build in a CI environment will result in a new build identifier. The following command-line call to vsdbcmd.exe is how deployments are generally done using datadude, note the presence of the &lt;b&gt;/p:BuildId&lt;/b&gt; switch:&lt;/p&gt;  &lt;blockquote&gt;   &lt;p&gt;..\Tools\VSDBCMD\vsdbcmd.exe /Action:Deploy /ConnectionString:"Data Source=.;Integrated Security=True;Pooling=False" &lt;b&gt;/p:BuildId="some-value"&lt;/b&gt; /DeployToDatabase:+ /ManifestFile:.\FinanceDB\sql\release\FinanceDB.deploymanifest&lt;/p&gt; &lt;/blockquote&gt;  &lt;p&gt;Your CI tool should be able to replace “some-value” with an identifier for the current build (that’s outside the scope of this blog post but any CI tool worth its salt will be able to do this) – when the deployment executes that value will then make its way into your [dbo].[DeployLog] table and you will have a self-maintaining history of all the deployments (datetime &amp;amp; build identifier) that have been made to your database.&lt;/p&gt;  &lt;blockquote&gt;   &lt;p&gt;&lt;font size="4"&gt;Recommendation #4: Maintain an automated history of your deployments&lt;/font&gt;&lt;/p&gt; &lt;/blockquote&gt;  &lt;h2&gt;Use Schema View&lt;/h2&gt;  &lt;p&gt;It is natural to navigate through all of the objects in your database project using Solution Explorer however datadude provides a better mechanism for doing just that – the Schema View window.&lt;/p&gt;  &lt;blockquote&gt;   &lt;p&gt;&lt;a href="http://sqlblog.com/blogs/jamie_thomson/image_6E36A95D.png"&gt;&lt;img style="border-width:0px;padding-top:0px;padding-right:0px;padding-left:0px;display:inline;background-image:none;" title="image" border="0" alt="image" src="http://sqlblog.com/blogs/jamie_thomson/image_thumb_781B9AC8.png" width="250" height="304"&gt;&lt;/a&gt;&lt;/p&gt; &lt;/blockquote&gt;  &lt;p&gt;Schema View provides a logical view of all the objects defined in your database project regardless of which file they may be defined in. That is very useful for many reasons, not least because it makes it easy to locate whichever object you are after – that’s advantageous if multiple objects are defined in the same file. Moreover if some files have property BuildAction=”Not In Build” (see later) they won’t show up in Schema View (this is a good thing by the way). Schema View is also the place that operations such as refactoring and dependency analysis are launched from.&lt;/p&gt;  &lt;p&gt;Some people think that it is important that the name of each file in a datadude project should accurately reflect the object defined within. I disagree; object renames mean that maintaining the filenames becomes laborious and having the Schema View means you never have to use the filenames to navigate your project anyway.&lt;/p&gt;  &lt;p&gt;One final reason to use Schema View is the External Elements button:&lt;/p&gt;  &lt;blockquote&gt;   &lt;p&gt;&lt;a href="http://sqlblog.com/blogs/jamie_thomson/image_04A947E5.png"&gt;&lt;img style="border-width:0px;padding-top:0px;padding-right:0px;padding-left:0px;display:inline;background-image:none;" title="image" border="0" alt="image" src="http://sqlblog.com/blogs/jamie_thomson/image_thumb_6349A248.png" width="356" height="152"&gt;&lt;/a&gt;&lt;/p&gt; &lt;/blockquote&gt;  &lt;p&gt;Toggling this button on means that objects in referenced projects show up in the project that they are referenced from (this is particularly useful if you are using Composite Projects). Note in the following screenshot how the object [dbo].[t1] in project Database2 appears in the [dbo] schema of Database3 – that’s because Database3 has a reference to Database2.&lt;/p&gt;  &lt;blockquote&gt;   &lt;p&gt;&lt;a href="http://sqlblog.com/blogs/jamie_thomson/image_62050969.png"&gt;&lt;img style="border-width:0px;padding-top:0px;padding-right:0px;padding-left:0px;display:inline;background-image:none;" title="image" border="0" alt="image" src="http://sqlblog.com/blogs/jamie_thomson/image_thumb_47586D50.png" width="243" height="439"&gt;&lt;/a&gt;&lt;/p&gt; &lt;/blockquote&gt;  &lt;p&gt;For those reasons my fifth recommendation is:&lt;/p&gt;  &lt;blockquote&gt;   &lt;p&gt;&lt;font size="4"&gt;Recommendation #5: Use Schema View in preference to Solution Explorer&lt;/font&gt;&lt;/p&gt; &lt;/blockquote&gt;  &lt;p&gt;You will still need Solution Explorer to navigate files that do not contain database objects (e.g. Post-Deployment scripts) but ordinarily you should spend most of your time interacting with Schema View.&lt;/p&gt;  &lt;h2&gt;Make liberal use of PRINT statements in Pre/Post-Deployment Scripts&lt;/h2&gt;  &lt;p&gt;When you deploy a datadude project datadude will take care of telling you what it is up to. For example, the following screenshot shows the output from deploying the already discussed [dbo].[DeplogLog]:&lt;/p&gt;  &lt;blockquote&gt;   &lt;p&gt;&lt;a href="http://sqlblog.com/blogs/jamie_thomson/image_11074541.png"&gt;&lt;img style="border-width:0px;padding-top:0px;padding-right:0px;padding-left:0px;display:inline;background-image:none;" title="image" border="0" alt="image" src="http://sqlblog.com/blogs/jamie_thomson/image_thumb_68F49621.png" width="479" height="117"&gt;&lt;/a&gt;&lt;/p&gt; &lt;/blockquote&gt;  &lt;p&gt;Of course it only does this for objects that it knows about and that doesn’t include anything in your Pre or Post \deployment scripts so you need to take responsibility for outputting pertinent information from those scripts. Here I have amended the script that inserts into [dbo].[DeployLog]:&lt;/p&gt;  &lt;blockquote&gt;   &lt;p&gt;&lt;code style="font-size:12px;"&gt;&lt;span style="color:blue;"&gt;SET NOCOUNT ON&lt;/span&gt;&lt;span style="color:gray;"&gt;;          &lt;br&gt;&lt;/span&gt;&lt;span style="color:blue;"&gt;INSERT &lt;/span&gt;&lt;span style="color:black;"&gt;[dbo].[DeployLog]&lt;/span&gt;&lt;span style="color:gray;"&gt;(&lt;/span&gt;&lt;span style="color:black;"&gt;[BuildId]&lt;/span&gt;&lt;span style="color:gray;"&gt;,&lt;/span&gt;&lt;span style="color:black;"&gt;[DeployDatetime]&lt;/span&gt;&lt;span style="color:gray;"&gt;)          &lt;br&gt;&lt;/span&gt;&lt;span style="color:blue;"&gt;VALUES &lt;/span&gt;&lt;span style="color:gray;"&gt;(&lt;/span&gt;&lt;span style="color:red;"&gt;'$(BuildId)'&lt;/span&gt;&lt;span style="color:gray;"&gt;,&lt;/span&gt;&lt;span style="color:magenta;"&gt;GETDATE&lt;/span&gt;&lt;span style="color:gray;"&gt;());          &lt;br&gt;&lt;/span&gt;&lt;span style="color:blue;"&gt;PRINT &lt;/span&gt;&lt;span style="color:magenta;"&gt;CAST&lt;/span&gt;&lt;span style="color:gray;"&gt;(&lt;/span&gt;&lt;span&gt;@@ROWCOUNT &lt;/span&gt;&lt;span style="color:blue;"&gt;as NVARCHAR&lt;/span&gt;&lt;span style="color:gray;"&gt;(&lt;/span&gt;&lt;span style="color:black;"&gt;5&lt;/span&gt;&lt;span style="color:gray;"&gt;)) + &lt;/span&gt;&lt;span style="color:red;"&gt;N'rows inserted into [dbo].[DeployLog], BuildId=$(BuildId)'&lt;/span&gt;&lt;span style="color:gray;"&gt;;&lt;/span&gt;&lt;/code&gt;&lt;/p&gt; &lt;/blockquote&gt;  &lt;p&gt;This gives us much more useful output:&lt;/p&gt;  &lt;blockquote&gt;   &lt;p&gt;&lt;a href="http://sqlblog.com/blogs/jamie_thomson/image_159D4FFB.png"&gt;&lt;img style="border-width:0px;padding-top:0px;padding-right:0px;padding-left:0px;display:inline;background-image:none;" title="image" border="0" alt="image" src="http://sqlblog.com/blogs/jamie_thomson/image_thumb_46BC8A9B.png" width="475" height="122"&gt;&lt;/a&gt;&lt;/p&gt; &lt;/blockquote&gt;  &lt;p&gt;Adding PRINT statements to your Pre &amp;amp; Post Deployment scripts is so easy it really is a no-brainer and hence my next recommendation is:&lt;/p&gt;  &lt;blockquote&gt;   &lt;p&gt;&lt;font size="4"&gt;Recommendation #6: Any action in a Pre or Post-Deployment Script should use PRINT to state what has been done&lt;/font&gt;&lt;/p&gt; &lt;/blockquote&gt;  &lt;h2&gt;Output variable values in your Pre-Deployment script&lt;/h2&gt;  &lt;p&gt;This is in the same vein as the previous bullet-point – output as much information as is possible. In this case we’re talking about outputting the values of all variables that are stored in the .sqlcmdvars file; first, a reminder of what’s in that file:&lt;/p&gt;  &lt;blockquote&gt;   &lt;p&gt;&lt;a href="http://sqlblog.com/blogs/jamie_thomson/image_73654474.png"&gt;&lt;img style="border-width:0px;padding-top:0px;padding-right:0px;padding-left:0px;display:inline;background-image:none;" title="image" border="0" alt="image" src="http://sqlblog.com/blogs/jamie_thomson/image_thumb_5924DB50.png" width="526" height="219"&gt;&lt;/a&gt;&lt;/p&gt; &lt;/blockquote&gt;  &lt;p&gt;Here is the contents of my amended Pre-Deployment Script:&lt;/p&gt;  &lt;blockquote&gt;   &lt;p&gt;&lt;code style="font-size:12px;"&gt;&lt;span style="color:blue;"&gt;PRINT &lt;/span&gt;&lt;span style="color:red;"&gt;'DefaultDataPath=$(DefaultDataPath)'&lt;/span&gt;&lt;span style="color:gray;"&gt;;          &lt;br&gt;&lt;/span&gt;&lt;span style="color:blue;"&gt;PRINT &lt;/span&gt;&lt;span style="color:red;"&gt;'DatabaseName=$(DatabaseName)'&lt;/span&gt;&lt;span style="color:gray;"&gt;;          &lt;br&gt;&lt;/span&gt;&lt;span style="color:blue;"&gt;PRINT &lt;/span&gt;&lt;span style="color:red;"&gt;'DefaultLogPath=$(DefaultLogPath)'&lt;/span&gt;&lt;span style="color:gray;"&gt;;          &lt;br&gt;&lt;/span&gt;&lt;span style="color:blue;"&gt;PRINT &lt;/span&gt;&lt;span style="color:red;"&gt;'BuildId=$(BuildId)'&lt;/span&gt;&lt;span style="color:gray;"&gt;;&lt;/span&gt;&lt;/code&gt; &lt;/p&gt; &lt;/blockquote&gt;  &lt;p&gt;And the resultant output:&lt;/p&gt;  &lt;blockquote&gt;   &lt;p&gt;&lt;a href="http://sqlblog.com/blogs/jamie_thomson/image_22D3B341.png"&gt;&lt;img style="border-width:0px;padding-top:0px;padding-right:0px;padding-left:0px;display:inline;background-image:none;" title="image" border="0" alt="image" src="http://sqlblog.com/blogs/jamie_thomson/image_thumb_3D9FD94D.png" width="568" height="119"&gt;&lt;/a&gt;&lt;/p&gt; &lt;/blockquote&gt;  &lt;p&gt;This is the sort of simple amendment that will pay off in spades later in your project (especially if you are supplying many values from the command-line) and again, its so easy to do it there really is no reason not to. Just remember to update your Pre-Deployment script whenever you add new variables to .sqlcmdvars.&lt;/p&gt;  &lt;blockquote&gt;   &lt;p&gt;&lt;font size="4"&gt;Recommendation #7: Output the value of all variables in your Pre-Deployment script&lt;/font&gt;&lt;/p&gt; &lt;/blockquote&gt;  &lt;h2&gt;One Object Per File&lt;/h2&gt;  &lt;p&gt;Datadude doesn’t restrict what can go in a file, for example the following file, “t.table.sql”, defines three objects; a table, a primary key and a view:&lt;/p&gt;  &lt;blockquote&gt;   &lt;p&gt;&lt;a href="http://sqlblog.com/blogs/jamie_thomson/image_75721D70.png"&gt;&lt;img style="border-width:0px;padding-top:0px;padding-right:0px;padding-left:0px;display:inline;background-image:none;" title="image" border="0" alt="image" src="http://sqlblog.com/blogs/jamie_thomson/image_thumb_1B67CDC7.png" width="352" height="248"&gt;&lt;/a&gt;&lt;/p&gt; &lt;/blockquote&gt;  &lt;p&gt;Even though they’re all defined in the same file they show up in Schema View separately (one of the aforementioned benefits of using Schema View):&lt;/p&gt;  &lt;blockquote&gt;   &lt;p&gt;&lt;a href="http://sqlblog.com/blogs/jamie_thomson/image_6C35E22F.png"&gt;&lt;img style="border-width:0px;padding-top:0px;padding-right:0px;padding-left:0px;display:inline;background-image:none;" title="image" border="0" alt="image" src="http://sqlblog.com/blogs/jamie_thomson/image_thumb_3D03F698.png" width="314" height="355"&gt;&lt;/a&gt;&lt;/p&gt; &lt;/blockquote&gt;  &lt;p&gt;That said, just because you can doesn’t mean that you should. I prefer to go for one object per file for the simple reason that its easier to track the history of an object via Source Control. Moreover, if an object is no longer required then it is a simple change to just remove the file containing that object from the build (see “Don’t delete anything from your project” later) as opposed to editing a file to remove all traces of an object.&lt;/p&gt;  &lt;blockquote&gt;   &lt;p&gt;&lt;font size="4"&gt;Recommendation #8: Each database object should be defined in a dedicated file&lt;/font&gt;&lt;/p&gt; &lt;/blockquote&gt;  &lt;h2&gt;Time your Pre and Post Deployment Scripts&lt;/h2&gt;  &lt;p&gt;Its always useful to know where time is spent when doing deployments, in my experience the majority of time spent is in the Post-Deployment script (your mileage may vary of course). An easy win is to output the time taken to run your Pre and Post Deployment scripts. Adapt your Pre-Deployment script so that it looks something like this:&lt;/p&gt;  &lt;blockquote&gt;   &lt;p&gt;&lt;code style="font-size:12px;"&gt;&lt;span style="color:blue;"&gt;DECLARE &lt;/span&gt;&lt;span&gt;@vPreDeploymentStartTime &lt;/span&gt;&lt;span style="color:blue;"&gt;DATETIME = &lt;/span&gt;&lt;span style="color:magenta;"&gt;GETDATE&lt;/span&gt;&lt;span style="color:gray;"&gt;();          &lt;br&gt;&lt;/span&gt;&lt;span style="color:blue;"&gt;PRINT &lt;/span&gt;&lt;span style="color:red;"&gt;'****************Begin Pre-Deployment script at ' &lt;/span&gt;&lt;span style="color:gray;"&gt;+&lt;/span&gt;&lt;span style="color:magenta;"&gt;CONVERT&lt;/span&gt;&lt;span style="color:gray;"&gt;(&lt;/span&gt;&lt;span style="color:blue;"&gt;VARCHAR&lt;/span&gt;&lt;span style="color:gray;"&gt;(&lt;/span&gt;&lt;span style="color:black;"&gt;30&lt;/span&gt;&lt;span style="color:gray;"&gt;),&lt;/span&gt;&lt;span style="color:magenta;"&gt;GETDATE&lt;/span&gt;&lt;span style="color:gray;"&gt;(),&lt;/span&gt;&lt;span style="color:black;"&gt;120&lt;/span&gt;&lt;span style="color:gray;"&gt;) + &lt;/span&gt;&lt;span style="color:red;"&gt;'***********************'&lt;/span&gt;&lt;span style="color:gray;"&gt;;          &lt;br&gt;&lt;/span&gt;&lt;span style="color:gray;"&gt;         &lt;br&gt;&lt;/span&gt;&lt;span style="color:green;"&gt;/*Call other scripts from here using SQLCMD's :r syntax          &lt;br&gt;Example:&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; :r .\myfile.sql&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;br&gt;*/           &lt;br&gt;          &lt;br&gt;&lt;/span&gt;&lt;span style="color:blue;"&gt;PRINT &lt;/span&gt;&lt;span style="color:red;"&gt;'Pre-Deployment duration = ' &lt;/span&gt;&lt;span style="color:gray;"&gt;+ &lt;/span&gt;&lt;span style="color:magenta;"&gt;CONVERT&lt;/span&gt;&lt;span style="color:gray;"&gt;(&lt;/span&gt;&lt;span style="color:blue;"&gt;VARCHAR&lt;/span&gt;&lt;span style="color:gray;"&gt;(&lt;/span&gt;&lt;span style="color:black;"&gt;5&lt;/span&gt;&lt;span style="color:gray;"&gt;),&lt;/span&gt;&lt;span style="color:magenta;"&gt;DATEDIFF&lt;/span&gt;&lt;span style="color:gray;"&gt;(&lt;/span&gt;&lt;span style="color:black;"&gt;ss&lt;/span&gt;&lt;span style="color:gray;"&gt;,&lt;/span&gt;&lt;span&gt;@vPreDeploymentStartTime&lt;/span&gt;&lt;span style="color:gray;"&gt;,&lt;/span&gt;&lt;span style="color:magenta;"&gt;GETDATE&lt;/span&gt;&lt;span style="color:gray;"&gt;())) + &lt;/span&gt;&lt;span style="color:red;"&gt;' seconds'&lt;/span&gt;&lt;span style="color:gray;"&gt;;          &lt;br&gt;&lt;/span&gt;&lt;span style="color:blue;"&gt;PRINT &lt;/span&gt;&lt;span style="color:red;"&gt;'****************End Pre-Deployment script at ' &lt;/span&gt;&lt;span style="color:gray;"&gt;+&lt;/span&gt;&lt;span style="color:magenta;"&gt;CONVERT&lt;/span&gt;&lt;span style="color:gray;"&gt;(&lt;/span&gt;&lt;span style="color:blue;"&gt;VARCHAR&lt;/span&gt;&lt;span style="color:gray;"&gt;(&lt;/span&gt;&lt;span style="color:black;"&gt;30&lt;/span&gt;&lt;span style="color:gray;"&gt;),&lt;/span&gt;&lt;span style="color:magenta;"&gt;GETDATE&lt;/span&gt;&lt;span style="color:gray;"&gt;(),&lt;/span&gt;&lt;span style="color:black;"&gt;120&lt;/span&gt;&lt;span style="color:gray;"&gt;) + &lt;/span&gt;&lt;span style="color:red;"&gt;'***********************'&lt;/span&gt;&lt;span style="color:gray;"&gt;;&lt;/span&gt;&lt;/code&gt;&lt;/p&gt; &lt;/blockquote&gt;  &lt;p&gt;then do similar for your Post-Deployment script. When you deploy your output will include the following:&lt;/p&gt;  &lt;blockquote&gt;   &lt;p&gt;&lt;a href="http://sqlblog.com/blogs/jamie_thomson/image_3BBF5DB9.png"&gt;&lt;img style="border-width:0px;padding-top:0px;padding-right:0px;padding-left:0px;display:inline;background-image:none;" title="image" border="0" alt="image" src="http://sqlblog.com/blogs/jamie_thomson/image_thumb_217EF495.png" width="593" height="201"&gt;&lt;/a&gt;&lt;/p&gt; &lt;/blockquote&gt;  &lt;p&gt;Note the lines:&lt;/p&gt;  &lt;blockquote&gt;   &lt;p&gt;&lt;font face="Consolas"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; ****************Begin Pre-Deployment script at 2011-12-31 20:00:34***********************        &lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; Pre-Deployment duration = 0 seconds         &lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; ****************End Pre-Deployment script at 2011-12-31 20:00:34***********************         &lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/font&gt;&lt;/p&gt;    &lt;p&gt;&lt;font face="Consolas"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; ****************Begin Post-Deployment script at 2011-12-31 20:00:34***********************        &lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; Post-Deployment duration = 0 seconds         &lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; ****************End Post-Deployment script at 2011-12-31 20:00:34***********************&lt;/font&gt;&lt;/p&gt; &lt;/blockquote&gt;  &lt;p&gt;In this particular case its not all that useful to know that the deployment took 0 seconds but if and when your deployments snowball to many minutes it will be useful to know how long your scripts are taking at which point you can investigate further by timing each individual step in your Pre and Post Deployment scripts.&lt;/p&gt;  &lt;blockquote&gt;   &lt;p&gt;&lt;font size="4"&gt;Recommendation #9: Time your deployments and output the timings&lt;/font&gt;&lt;/p&gt; &lt;/blockquote&gt;  &lt;h2&gt;Use sqlcmdvars and the command-line as much as possible&lt;/h2&gt;  &lt;p&gt;Hardcoding any value into a piece of code is a fraught practise; you should assume that values previously thought to be constant may not be so in the future. You can protect yourself from future changes by storing all literal values as variables in your .sqlcmdvars file. Sure, you can supply default values for those variables but you have the added advantage that they can be overridden from the command-line when deploying using &lt;a href="http://msdn.microsoft.com/en-us/library/dd193283.aspx" target="_blank"&gt;vsdbcmd.exe&lt;/a&gt;. Moreover, if you have values that are hardcoded in multiple places in your code then specifying those values in .sqlcmdvars ensures that your code adheres to the principle of &lt;a href="http://en.wikipedia.org/wiki/Don%27t_repeat_yourself" target="_blank"&gt;DRY&lt;/a&gt;. Lastly, if values are stored in the .sqlcmdvars file then you can output them at deploy time (see recommendation #7).&lt;/p&gt;  &lt;blockquote&gt;   &lt;p&gt;&lt;font size="4"&gt;Recommendation #10: All literal values should be stored in your .sqlcmdvars file&lt;/font&gt;&lt;/p&gt; &lt;/blockquote&gt;  &lt;h2&gt;Every developer gets their own development database&lt;/h2&gt;  &lt;p&gt;In most SQL Server development shops that I’ve been on all developers work against a single centralised development database. To me this is an antiquated way of working because its possible that work one person is doing can conflict with that of someone else, I find it much better for every developer to work in isolation and then use the CI deployment to check that one’s code is not in conflict with anyone else’s. Datadude supports (nay encourages) this way of working with the notion of an Isolated Development Environment:&lt;/p&gt;  &lt;blockquote&gt;   &lt;p&gt;&lt;a href="http://sqlblog.com/blogs/jamie_thomson/image_79001280.png"&gt;&lt;img style="border-width:0px;padding-top:0px;padding-right:0px;padding-left:0px;display:inline;background-image:none;" title="image" border="0" alt="image" src="http://sqlblog.com/blogs/jamie_thomson/image_thumb_0CACFC15.png" width="541" height="172"&gt;&lt;/a&gt;&lt;/p&gt; &lt;/blockquote&gt;  &lt;p&gt;Every developer should configure their isolated development environment which, typically, would be their local instance. And so to my next recommendation:&lt;/p&gt;  &lt;blockquote&gt;   &lt;p&gt;&lt;font size="4"&gt;Recommendation #11: Every developer should use the Isolated Dev Environment settings in order to author their code&lt;/font&gt;&lt;/p&gt; &lt;/blockquote&gt;  &lt;p&gt;Incidentally, if every developer has their own development database and you are following my earlier recommendation to use a [DeployLog] table then you can track how often a developer is bothering to deploy and test their code. On a recent project we used this evidence in a (ahem) &lt;i&gt;discussion&lt;/i&gt; with a developer who tried to convince us that he was testing his code sufficiently even though he was repeatedly causing the CI deployment to fail.&lt;/p&gt;  &lt;h2&gt;Don’t delete anything from your project&lt;/h2&gt;  &lt;p&gt;When projects are no longer required in your database then intuitively it makes sense to remove the file containing that object from the datadude project, I would however like to suggest a different approach. Rather than removing a file just change the Build property to “Not in Build”:&lt;/p&gt;  &lt;blockquote&gt;   &lt;p&gt;&lt;a href="http://sqlblog.com/blogs/jamie_thomson/image_0B686336.png"&gt;&lt;img style="border-width:0px;padding-top:0px;padding-right:0px;padding-left:0px;display:inline;background-image:none;" title="image" border="0" alt="image" src="http://sqlblog.com/blogs/jamie_thomson/image_thumb_114306CF.png" width="330" height="293"&gt;&lt;/a&gt;&lt;/p&gt; &lt;/blockquote&gt;  &lt;p&gt;This has the advantage that your project maintains some semblance of history of what objects have been removed from your database – that can be useful to anyone inheriting your code in the future.&lt;/p&gt;  &lt;blockquote&gt;   &lt;p&gt;&lt;font size="4"&gt;Recommendation #12: Use “Not in Build” to remove an object from your database&lt;/font&gt;&lt;/p&gt; &lt;/blockquote&gt;  &lt;h2&gt;Build and Deploy your datadude projects outside of Visual Studio&lt;/h2&gt;  &lt;p&gt;Building and deploying your datadude projects within Visual Studio can become a real time hog; in my experience its not unusual for deployments to take many minutes and your Visual Studio environment will be unavailable for further development work during that time. For that reason I recommend investing some time in writing some msbuild scripts that will build and deploy your project(s) from the command-line. Here are some examples that you can adapt for your own use, firstly a script to build a solution:&lt;/p&gt;  &lt;div style="font-size:10pt;"&gt;   &lt;div style="padding:2px 5px;overflow:auto;white-space:nowrap;"&gt;&lt;span&gt;&amp;lt;?&lt;/span&gt;&lt;span&gt;xml&lt;/span&gt;&lt;span&gt; &lt;/span&gt;&lt;span&gt;version&lt;/span&gt;&lt;span&gt;=&lt;/span&gt;"&lt;span&gt;1.0&lt;/span&gt;"&lt;span&gt; &lt;/span&gt;&lt;span&gt;encoding&lt;/span&gt;&lt;span&gt;=&lt;/span&gt;"&lt;span&gt;utf-8&lt;/span&gt;"&lt;span&gt;?&amp;gt;&lt;/span&gt;       &lt;br&gt;&lt;span&gt;&amp;lt;!--&lt;/span&gt; &lt;span&gt;Execute using:&lt;/span&gt;       &lt;br&gt;&lt;span&gt;msbuild SolutionBuild.proj&lt;/span&gt;       &lt;br&gt;&lt;span&gt;--&amp;gt;&lt;/span&gt;       &lt;br&gt;&lt;span&gt;&amp;lt;&lt;/span&gt;&lt;span&gt;Project&lt;/span&gt;&lt;span&gt;&amp;nbsp; &lt;/span&gt;&lt;span&gt;xmlns&lt;/span&gt;&lt;span&gt;=&lt;/span&gt;"&lt;span&gt;http://schemas.microsoft.com/developer/msbuild/2003&lt;/span&gt;"       &lt;br&gt;&lt;span&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;span&gt;DefaultTargets&lt;/span&gt;&lt;span&gt;=&lt;/span&gt;"&lt;span&gt;Build&lt;/span&gt;"&lt;span&gt;&amp;gt;&lt;/span&gt;       &lt;br&gt;&lt;span&gt;&amp;nbsp; &amp;lt;!--&lt;/span&gt; &lt;span&gt;Notes:&lt;/span&gt;       &lt;br&gt;&lt;span&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; When doing .net development Visual Studio Configurations are particularly useful because they can affect&lt;br&gt;&lt;/span&gt;&lt;span&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;span&gt;how the code is executed (i.e. under the Debug configuration&lt;/span&gt;       &lt;br&gt;&lt;span&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; debug symbols can be used to step through the code (something like that anyway - I don't know too much about that &lt;br&gt;&lt;/span&gt;&lt;span&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;span&gt;stuff).&lt;/span&gt;       &lt;br&gt;&lt;span&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; In DBPro, Configurations are less relevant because there is no such thing as debugging symbols. Nonetheless, they &lt;br&gt;&lt;/span&gt;&lt;span&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;span&gt;can still be useful&lt;/span&gt; &lt;span&gt;for times when you want to do different things (e.g. you might want to run Code Analysis in &lt;br&gt;&lt;/span&gt;&lt;span&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;span&gt;a debug situation but not in a release&lt;/span&gt;       &lt;span&gt;situation. There is a useful thread on this here: &lt;br&gt;&lt;/span&gt;&lt;span&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;span&gt;"Debug vs Release" http://social.msdn.microsoft.com/Forums/en-US/vstsdb/thread/a0ec0dc0-a907-45ba-a2ea-d2f0175261a7&lt;/span&gt;       &lt;br&gt;&lt;span&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;      &lt;br&gt;&lt;span&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; Note that Visual Studio Configurations should not be used to maintain different settings per environment. &lt;br&gt;&lt;/span&gt;&lt;span&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;span&gt;The correct way to do that is to maintain&lt;/span&gt;       &lt;br&gt;&lt;span&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; seperate .sqlcmdvars files per environment and then choose which one to use at deployment time when using&lt;/span&gt;       &lt;br&gt;&lt;span&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; vsdbcmd.exe (use syntax "/p:SqlCommandVariablesFile=$(ProjectName)_$(Environment).sqlcmdvars")&lt;/span&gt;       &lt;br&gt;&lt;span&gt;&amp;nbsp; &lt;/span&gt;&lt;span&gt;--&amp;gt;&lt;/span&gt;       &lt;br&gt;&lt;span&gt;&amp;nbsp; &amp;lt;&lt;/span&gt; &lt;span&gt;ItemGroup&lt;/span&gt; &lt;span&gt;&amp;gt;&lt;/span&gt;       &lt;br&gt;&lt;span&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;lt;!--&lt;/span&gt; &lt;span&gt;List all the configurations here that you want to build&lt;/span&gt; &lt;span&gt;--&amp;gt;&lt;/span&gt;       &lt;br&gt;&lt;span&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;lt;&lt;/span&gt;&lt;span&gt;Config&lt;/span&gt;&lt;span&gt; &lt;/span&gt;&lt;span&gt;Include&lt;/span&gt;&lt;span&gt;=&lt;/span&gt;"&lt;span&gt;Debug&lt;/span&gt;"&lt;span&gt; /&amp;gt;&lt;/span&gt;       &lt;br&gt;&lt;span&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;lt;&lt;/span&gt;&lt;span&gt;Config&lt;/span&gt;&lt;span&gt; &lt;/span&gt;&lt;span&gt;Include&lt;/span&gt;&lt;span&gt;=&lt;/span&gt;"&lt;span&gt;Release&lt;/span&gt;"&lt;span&gt; /&amp;gt;&lt;/span&gt;       &lt;br&gt;&lt;span&gt;&amp;nbsp; &amp;lt;/&lt;/span&gt; &lt;span&gt;ItemGroup&lt;/span&gt; &lt;span&gt;&amp;gt;&lt;/span&gt;       &lt;br&gt;&lt;span&gt;&amp;nbsp; &amp;lt;&lt;/span&gt;&lt;span&gt;Target&lt;/span&gt;&lt;span&gt; &lt;/span&gt;&lt;span&gt;Name&lt;/span&gt;&lt;span&gt;=&lt;/span&gt;"&lt;span&gt;Build&lt;/span&gt;"&lt;span&gt;&amp;gt;&lt;/span&gt;       &lt;br&gt;&lt;span&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;lt;&lt;/span&gt;&lt;span&gt;Message&lt;/span&gt;&lt;span&gt; &lt;/span&gt;&lt;span&gt;Text&lt;/span&gt;&lt;span&gt;=&lt;/span&gt;"&lt;span&gt;Building %(Config.Identity) configuration...&lt;/span&gt;"&lt;span&gt;/&amp;gt;&lt;/span&gt;       &lt;br&gt;&lt;span&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;lt;&lt;/span&gt;&lt;span&gt;MSBuild&lt;/span&gt;&lt;span&gt; &lt;/span&gt;&lt;span&gt;Projects&lt;/span&gt;&lt;span&gt;=&lt;/span&gt;"&lt;span&gt;.\Lloyds.UKTax.DB.sln&lt;/span&gt;"&lt;span&gt; &lt;/span&gt;&lt;span&gt;Properties&lt;/span&gt;&lt;span&gt;=&lt;/span&gt;"&lt;span&gt;Configuration=%(Config.Identity)&lt;/span&gt;"&lt;span&gt; /&amp;gt;&lt;/span&gt;       &lt;br&gt;&lt;span&gt;&amp;nbsp; &amp;lt;/&lt;/span&gt; &lt;span&gt;Target&lt;/span&gt; &lt;span&gt;&amp;gt;&lt;/span&gt;       &lt;br&gt;&lt;span&gt;&amp;lt;/&lt;/span&gt; &lt;span&gt;Project&lt;/span&gt; &lt;span&gt;&amp;gt;&lt;/span&gt; &lt;/div&gt; &lt;/div&gt;  &lt;p&gt;and secondly a script that will deploy a datadude project:&lt;/p&gt;  &lt;div style="font-size:10pt;"&gt;   &lt;div style="padding:2px 5px;overflow:auto;white-space:nowrap;"&gt;&lt;span&gt;&amp;lt;?&lt;/span&gt;&lt;span&gt;xml&lt;/span&gt;&lt;span&gt; &lt;/span&gt;&lt;span&gt;version&lt;/span&gt;&lt;span&gt;=&lt;/span&gt;"&lt;span&gt;1.0&lt;/span&gt;"&lt;span&gt; &lt;/span&gt;&lt;span&gt;encoding&lt;/span&gt;&lt;span&gt;=&lt;/span&gt;"&lt;span&gt;utf-8&lt;/span&gt;"&lt;span&gt;?&amp;gt;&lt;/span&gt;      &lt;br&gt;&lt;span&gt;&amp;lt;!--&lt;/span&gt; &lt;span&gt;Execute using:&lt;/span&gt;       &lt;br&gt;&lt;span&gt;msbuild SolutionDeploy.proj /Target:Deploy&lt;/span&gt;       &lt;br&gt;&lt;span&gt;--&amp;gt;&lt;/span&gt;       &lt;br&gt;&lt;span&gt;&amp;lt;&lt;/span&gt;&lt;span&gt;Project&lt;/span&gt;&lt;span&gt;&amp;nbsp; &lt;/span&gt;&lt;span&gt;xmlns&lt;/span&gt;&lt;span&gt;=&lt;/span&gt;"&lt;span&gt;http://schemas.microsoft.com/developer/msbuild/2003&lt;/span&gt;"      &lt;br&gt;&lt;span&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;span&gt;DefaultTargets&lt;/span&gt;&lt;span&gt;=&lt;/span&gt;"&lt;span&gt;Build;Deploy&lt;/span&gt;"&lt;span&gt;&amp;gt;&lt;/span&gt;      &lt;br&gt;&lt;span&gt;&amp;nbsp; &amp;lt;&lt;/span&gt; &lt;span&gt;PropertyGroup&lt;/span&gt; &lt;span&gt;&amp;gt;&lt;/span&gt;       &lt;br&gt;&lt;span&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;lt;!--&lt;/span&gt; &lt;span&gt;At time of writing I don't see a reason for anything else to be used but that may change in the future hence why this &lt;br&gt;&lt;/span&gt;&lt;span&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;span&gt;is a property and hence can be overriden.&lt;/span&gt; &lt;span&gt;--&amp;gt;&lt;/span&gt;       &lt;br&gt;&lt;span&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;lt;&lt;/span&gt;&lt;span&gt;Configuration&lt;/span&gt;&lt;span&gt;&amp;gt;&lt;/span&gt;Debug&lt;span&gt;&amp;lt;/&lt;/span&gt;&lt;span&gt;Configuration&lt;/span&gt;&lt;span&gt;&amp;gt;&lt;/span&gt;      &lt;br&gt;&lt;span&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;lt;&lt;/span&gt;&lt;span&gt;DevServer&lt;/span&gt;&lt;span&gt;&amp;gt;&lt;/span&gt;Data Source=GBS0039182\GLDDEV01;Integrated Security=True;Pooling=False&lt;span&gt;&amp;lt;/&lt;/span&gt;&lt;span&gt;DevServer&lt;/span&gt;&lt;span&gt;&amp;gt;&lt;/span&gt;      &lt;br&gt;&lt;span&gt;&amp;nbsp; &amp;lt;/&lt;/span&gt; &lt;span&gt;PropertyGroup&lt;/span&gt; &lt;span&gt;&amp;gt;&lt;/span&gt;       &lt;br&gt;&lt;span&gt;&amp;nbsp; &lt;/span&gt;       &lt;br&gt;&lt;span&gt;&amp;nbsp; &amp;lt;&lt;/span&gt; &lt;span&gt;ItemGroup&lt;/span&gt; &lt;span&gt;&amp;gt;&lt;/span&gt;       &lt;br&gt;&lt;span&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;lt;&lt;/span&gt;&lt;span&gt;ProjectToBuild&lt;/span&gt;&lt;span&gt; &lt;/span&gt;&lt;span&gt;Include&lt;/span&gt;&lt;span&gt;=&lt;/span&gt;"&lt;span&gt;SolutionBuild.proj&lt;/span&gt;"&lt;span&gt; /&amp;gt;&lt;/span&gt;      &lt;br&gt;&lt;span&gt;&amp;nbsp; &amp;lt;/&lt;/span&gt; &lt;span&gt;ItemGroup&lt;/span&gt; &lt;span&gt;&amp;gt;&lt;/span&gt;       &lt;br&gt;      &lt;br&gt;&lt;span&gt;&amp;nbsp; &amp;lt;!--&lt;/span&gt; &lt;span&gt;Notes:&lt;/span&gt;       &lt;br&gt;&lt;span&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; Add a &amp;lt;DbProj&amp;gt; item for every database project (.dbproj) that needs to be deployed. They will get deployed in the &lt;br&gt;&lt;/span&gt;&lt;span&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;span&gt;order that they are listed&lt;/span&gt;       &lt;br&gt;&lt;span&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; thus it is your responsibility to make sure they are listed in the correct order (respecting dependency order).&lt;/span&gt;       &lt;br&gt;&lt;span&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; %Identity is a metadata reference. It refers to the name of the item (i.e. Include="The bit that goes here is the &lt;br&gt;&lt;/span&gt;&lt;span&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;span&gt;identity")&lt;/span&gt;       &lt;br&gt;&lt;span&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; Note also that whatever you put for Include is important. Include="dev_thomsonj" means the project will only get &lt;br&gt;&lt;/span&gt;&lt;span&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;span&gt;deployed if the&lt;/span&gt;       &lt;span&gt;deployment is being executed by username=dev_thomsonj&lt;/span&gt; &lt;span&gt;--&amp;gt;&lt;/span&gt;       &lt;br&gt;&lt;span&gt;&amp;nbsp; &amp;lt;&lt;/span&gt; &lt;span&gt;ItemGroup&lt;/span&gt; &lt;span&gt;&amp;gt;&lt;/span&gt;       &lt;br&gt;&lt;span&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;lt;&lt;/span&gt;&lt;span&gt;DbProj&lt;/span&gt;&lt;span&gt; &lt;/span&gt;&lt;span&gt;Include&lt;/span&gt;&lt;span&gt;=&lt;/span&gt;"&lt;span&gt;username&lt;/span&gt;"&lt;span&gt;&amp;gt;&lt;/span&gt;      &lt;br&gt;&lt;span&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;lt;&lt;/span&gt;&lt;span&gt;DbName&lt;/span&gt;&lt;span&gt;&amp;gt;&lt;/span&gt;MyDB&lt;span&gt;&amp;lt;/&lt;/span&gt;&lt;span&gt;DbName&lt;/span&gt;&lt;span&gt;&amp;gt;&lt;/span&gt;      &lt;br&gt;&lt;span&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;lt;&lt;/span&gt;&lt;span&gt;ProjectName&lt;/span&gt;&lt;span&gt;&amp;gt;&lt;/span&gt;MySoln.MyDB&lt;span&gt;&amp;lt;/&lt;/span&gt;&lt;span&gt;ProjectName&lt;/span&gt;&lt;span&gt;&amp;gt;&lt;/span&gt;      &lt;br&gt;&lt;span&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;lt;&lt;/span&gt;&lt;span&gt;OutputPath&lt;/span&gt;&lt;span&gt;&amp;gt;\&lt;/span&gt;%(ProjectName)\sql\$(Configuration)\\cf1 &amp;lt;/&lt;span&gt;OutputPath&lt;/span&gt;&lt;span&gt;&amp;gt;&lt;/span&gt;      &lt;br&gt;&lt;span&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;lt;&lt;/span&gt;&lt;span&gt;DeployConnStr&lt;/span&gt;&lt;span&gt;&amp;gt;&lt;/span&gt;Data Source=localhost;Integrated Security=True;Pooling=False&lt;span&gt;&amp;lt;/&lt;/span&gt;&lt;span&gt;DeployConnStr&lt;/span&gt;&lt;span&gt;&amp;gt;&lt;/span&gt;      &lt;br&gt;&lt;span&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;lt;/&lt;/span&gt; &lt;span&gt;DbProj&lt;/span&gt; &lt;span&gt;&amp;gt;&lt;/span&gt;       &lt;br&gt;&lt;span&gt;&amp;nbsp; &amp;lt;/&lt;/span&gt; &lt;span&gt;ItemGroup&lt;/span&gt; &lt;span&gt;&amp;gt;&lt;/span&gt;       &lt;br&gt;      &lt;br&gt;&lt;span&gt;&amp;nbsp; &amp;lt;&lt;/span&gt;&lt;span&gt;Target&lt;/span&gt;&lt;span&gt; &lt;/span&gt;&lt;span&gt;Name&lt;/span&gt;&lt;span&gt;=&lt;/span&gt;"&lt;span&gt;Build&lt;/span&gt;"&lt;span&gt;&amp;gt;&lt;/span&gt;      &lt;br&gt;&lt;span&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;lt;&lt;/span&gt;&lt;span&gt;MSBuild&lt;/span&gt;&lt;span&gt; &lt;/span&gt;&lt;span&gt;Projects&lt;/span&gt;&lt;span&gt;=&lt;/span&gt;"&lt;span&gt;@(ProjectToBuild)&lt;/span&gt;"&lt;span&gt; /&amp;gt;&lt;/span&gt;      &lt;br&gt;&lt;span&gt;&amp;nbsp; &amp;lt;/&lt;/span&gt; &lt;span&gt;Target&lt;/span&gt; &lt;span&gt;&amp;gt;&lt;/span&gt;       &lt;br&gt;&lt;span&gt;&amp;nbsp; &lt;/span&gt;       &lt;br&gt;&lt;span&gt;&amp;nbsp; &amp;lt;&lt;/span&gt;&lt;span&gt;Target&lt;/span&gt;&lt;span&gt; &lt;/span&gt;&lt;span&gt;Name&lt;/span&gt;&lt;span&gt;=&lt;/span&gt;"&lt;span&gt;Deploy&lt;/span&gt;"&lt;span&gt;&amp;gt;&lt;/span&gt;      &lt;br&gt;&lt;span&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;lt;!--&lt;/span&gt; &lt;span&gt;Notes:&lt;/span&gt;       &lt;br&gt;&lt;span&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 09 is the hex code for TAB, hence all of the %09 references that you can see. See http://asciitable.com/ &lt;br&gt;&lt;/span&gt;&lt;span&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;span&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;span&gt;for more details.&lt;/span&gt;       &lt;br&gt;&lt;span&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt; &lt;span&gt;--&amp;gt;&lt;/span&gt;       &lt;br&gt;&lt;span&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;lt;&lt;/span&gt;&lt;span&gt;Message&lt;/span&gt;&lt;span&gt; &lt;/span&gt;&lt;span&gt;Text&lt;/span&gt;&lt;span&gt;=&lt;/span&gt;"&lt;span&gt;USERNAME=$(USERNAME)&lt;/span&gt;"&lt;span&gt; /&amp;gt;&lt;/span&gt;      &lt;br&gt;&lt;span&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;lt;&lt;/span&gt;&lt;span&gt;Message&lt;/span&gt;&lt;span&gt; &lt;/span&gt;&lt;span&gt;Condition&lt;/span&gt;&lt;span&gt;=&lt;/span&gt;"&lt;span&gt;'%(DbProj.Identity)'==$(USERNAME)&lt;/span&gt;"&lt;span&gt; &lt;/span&gt;&lt;span&gt;Text&lt;/span&gt;&lt;span&gt;=&lt;/span&gt;"&lt;span&gt;Deploying:&lt;/span&gt;      &lt;br&gt;&lt;span&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; Project%09%09%09:&amp;nbsp; %(DbProj.ProjectName)&amp;nbsp;&amp;nbsp; &lt;/span&gt;       &lt;br&gt;&lt;span&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; DbName%09%09%09:&amp;nbsp; %(DbProj.DbName)&lt;/span&gt;       &lt;br&gt;&lt;span&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; From OutputPath%09%09:&amp;nbsp; %(DbProj.OutputPath)&lt;/span&gt;       &lt;br&gt;&lt;span&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; To ConnStr%09%09:&amp;nbsp; %(DbProj.DeployConnStr)&lt;/span&gt;       &lt;br&gt;&lt;span&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; By%09%09%09:&amp;nbsp; %(DbProj.Identity)&lt;/span&gt;"      &lt;br&gt;&lt;span&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; /&amp;gt;&lt;/span&gt;       &lt;br&gt;&lt;span&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;lt;&lt;/span&gt;&lt;span&gt;Exec&lt;/span&gt;&lt;span&gt; &lt;/span&gt;&lt;span&gt;Condition&lt;/span&gt;&lt;span&gt;=&lt;/span&gt;"&lt;span&gt;'%(DbProj.Identity)'==$(USERNAME)&lt;/span&gt;"&lt;span&gt; &lt;/span&gt;&lt;span&gt;Command&lt;/span&gt;&lt;span&gt;=&lt;/span&gt;"&lt;span&gt;&amp;amp;quot;&lt;/span&gt;&lt;span&gt;$(VSINSTALLDIR)\vstsdb\deploy\vsdbcmd.exe&lt;/span&gt;&lt;span&gt;&amp;amp;quot;&lt;/span&gt;&lt;span&gt; &lt;br&gt;&lt;/span&gt;&lt;span&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;span&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;span&gt;/Action:Deploy /ConnectionString:&lt;/span&gt;&lt;span&gt;&amp;amp;quot;&lt;/span&gt;&lt;span&gt;%(DbProj.DeployConnStr)&lt;/span&gt;&lt;span&gt;&amp;amp;quot;&lt;/span&gt;&lt;span&gt; /DeployToDatabase+ &lt;br&gt;&lt;/span&gt;&lt;span&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;span&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;span&gt;/manifest:&lt;/span&gt;&lt;span&gt;&amp;amp;quot;&lt;/span&gt;&lt;span&gt;.%(DbProj.OutputPath)%(DbProj.ProjectName).deploymanifest&lt;/span&gt;&lt;span&gt;&amp;amp;quot;&lt;/span&gt;&lt;span&gt; /p:TargetDatabase=%(DbProj.DbName) &lt;br&gt;&lt;/span&gt;&lt;span&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;span&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;span&gt;/p:Build=&lt;/span&gt;&lt;span&gt;&amp;amp;quot;&lt;/span&gt;&lt;span&gt;from cmd line&lt;/span&gt;&lt;span&gt;&amp;amp;quot;&lt;/span&gt;"&lt;span&gt; /&amp;gt;&lt;/span&gt;      &lt;br&gt;&lt;span&gt;&amp;nbsp; &amp;lt;/&lt;/span&gt; &lt;span&gt;Target&lt;/span&gt; &lt;span&gt;&amp;gt;&lt;/span&gt;       &lt;br&gt;&lt;span&gt;&amp;lt;/&lt;/span&gt; &lt;span&gt;Project&lt;/span&gt; &lt;span&gt;&amp;gt;&lt;/span&gt; &lt;/div&gt; &lt;/div&gt;  &lt;p&gt;Writing these scripts may appear to be laborious but they’ll save you heaps of time in the long run.&lt;/p&gt;  &lt;blockquote&gt;   &lt;p&gt;&lt;font size="4"&gt;Recommendation #13: Build and deploy to your development sandbox using scripts&lt;/font&gt;&lt;/p&gt; &lt;/blockquote&gt;  &lt;p&gt;&lt;i&gt;UPDATE: Upon reading this blog post Mordechai Danielov wrote a follow-up in which he published a useful script that builds a series of projects using Powershell. Its at &lt;/i&gt;&lt;a href="http://bitwisemnm.com/2012/01/03/building-your-database-solutions-outside-of-visual-studio/" target="_blank"&gt;&lt;i&gt;building your database solutions outside of Visual Studio&lt;/i&gt;&lt;/a&gt;&lt;i&gt;.&lt;/i&gt;&lt;/p&gt;  &lt;h1&gt;Useful links&lt;/h1&gt;  &lt;p&gt;Over the years I’ve collected some links to MSDN articles that have proved invaluable:&lt;/p&gt;  &lt;ul&gt;   &lt;li&gt;&lt;a href="http://msdn.microsoft.com/en-us/library/dd193409.aspx" target="_blank"&gt;Build and Deploy Databases to an Isolated Development Environment&lt;/a&gt; &lt;/li&gt;    &lt;li&gt;&lt;a href="http://msdn.microsoft.com/en-us/library/aa833165.aspx#CommunityContent" target="_blank"&gt;An Overview of Database Build and Deployment&lt;/a&gt; &lt;/li&gt;    &lt;li&gt;&lt;a href="http://msdn.microsoft.com/en-us/magazine/dvdarchive/cc164243.aspx" target="_blank"&gt;Apply Test-Driven Development to your Database Projects&lt;/a&gt; &lt;/li&gt;    &lt;li&gt;&lt;a href="http://msdn.microsoft.com/en-us/library/dd193415.aspx" target="_blank"&gt;Walkthrough: Partition a Database Project by Using Composite Projects&lt;/a&gt; &lt;/li&gt;    &lt;li&gt;&lt;a href="http://blogs.msdn.com/b/bahill/archive/2009/03/23/right-sizing-the-master-dbschema-file-for-better-design-time-performance.aspx" target="_blank"&gt;Right sizing the master.dbschema file for better design time performance&lt;/a&gt; &lt;/li&gt;    &lt;li&gt;&lt;a href="http://msdn.microsoft.com/en-us/magazine/dd483214.aspx#id0100036" target="_blank"&gt;Referencing for Shared Server-Level Objects&lt;/a&gt; &lt;/li&gt;&lt;li&gt;&lt;span style="text-transform:none;text-indent:0px;letter-spacing:normal;word-spacing:0px;float:none;white-space:normal;orphans:2;widows:2;font-size-adjust:none;font-stretch:normal;-webkit-text-size-adjust:auto;-webkit-text-stroke-width:0px;"&gt;&lt;a href="http://msdn.microsoft.com/en-us/library/dd193258.aspx" target="_blank"&gt;How to: Prepare a Database for Deployment From a Command Prompt by Using VSDBCMD.EXE&lt;/a&gt;&lt;/span&gt;&lt;/li&gt; &lt;/ul&gt;  &lt;h1&gt;Datadude bugs&lt;/h1&gt;  &lt;p&gt;Like any substantial piece of software datadude is not without bugs. Many of the issues I have found are concerned with the datadude interpreter not correctly parsing T-SQL code, here’s a list of some bugs that I have found down the years:&lt;/p&gt;  &lt;ul&gt;   &lt;li&gt;&lt;a href="https://connect.microsoft.com/VisualStudio/feedback/details/688259/refactor-rename-in-schema-view-crashes-visual-studio" target="_blank"&gt;Under certain circumstances a Refactor-&amp;gt;Rename operation can crash Visual Studio&lt;/a&gt; (followed up &lt;a href="https://connect.microsoft.com/VisualStudio/feedback/details/705676/would-like-feedback-on-a-bug-that-has-been-closed-as-wont-fix" target="_blank"&gt;here&lt;/a&gt;) &lt;/li&gt;    &lt;li&gt;&lt;a href="https://connect.microsoft.com/VisualStudio/feedback/details/674391/datadude-valid-merge-syntax-causes-warnings#details" target="_blank"&gt;Valid T-SQL MERGE syntax can cause false warnings&lt;/a&gt; &lt;/li&gt;    &lt;li&gt;&lt;a href="https://connect.microsoft.com/VisualStudio/feedback/details/668651/datadude-refactoring-applies-the-wrong-edits-to-unit-tests" target="_blank"&gt;Refactor-&amp;gt;Rename doesn’t work properly for database unit tests&lt;/a&gt; &lt;/li&gt;    &lt;li&gt;&lt;a href="https://connect.microsoft.com/VisualStudio/feedback/details/657580/datadude-deploy-failure-something-to-do-with-triggers#details" target="_blank"&gt;Removal of triggers from your datadude project may, under certain circumstances, cause a failed deployment&lt;/a&gt; &lt;/li&gt;    &lt;li&gt;&lt;a href="https://connect.microsoft.com/VisualStudio/feedback/details/635058/datadude-derived-table-with-the-same-alias-as-one-of-the-columns-in-that-derived-table-incorrectly-causes-a-warning#details" target="_blank"&gt;Rare naming circumstance can cause false warnings&lt;/a&gt; &lt;/li&gt;    &lt;li&gt;&lt;a href="https://connect.microsoft.com/VisualStudio/feedback/details/624876/datadude-t-sql-parser-throws-warnings-for-valid-t-sql#details" target="_blank"&gt;Valid function definition containing a CTE can cause false warnings&lt;/a&gt; &lt;/li&gt;    &lt;li&gt;&lt;a href="https://connect.microsoft.com/VisualStudio/feedback/details/606656/datadude-datadude-attempts-to-deploy-a-default-constraint-before-deploying-the-function-referenced-by-that-constraint" target="_blank"&gt;A default constraint is attempted to be deployed before a function referenced by that constraint – hence an error occurs&lt;/a&gt; (confirmed as fixed in VS2010 SP1) &lt;/li&gt;    &lt;li&gt;&lt;a href="https://connect.microsoft.com/VisualStudio/feedback/details/605544/datadude-failure-to-recognise-operand-type-clash-when-using-table-types#details" target="_blank"&gt;Datadude doesn’t catch a type mismatch between a table-valued-parameter and a parameter passed to it&lt;/a&gt; &lt;/li&gt;    &lt;li&gt;&lt;a href="https://connect.microsoft.com/VisualStudio/feedback/details/594309/datadude-datetime2-data-generator-doesnt-generate-unique-values-when-the-column-is-part-of-a-composite-key" target="_blank"&gt;DateTime2 Data generator doesn't generate unique values when the column is part of a composite key&lt;/a&gt; &lt;/li&gt;    &lt;li&gt;&lt;a href="https://connect.microsoft.com/VisualStudio/feedback/details/592932/datadude-certain-db-unit-test-class-names-can-throw-errors-when-the-class-is-created" target="_blank"&gt;Unit test class files cannot contain periods&lt;/a&gt; &lt;/li&gt;    &lt;li&gt;&lt;a href="https://connect.microsoft.com/VisualStudio/feedback/details/586040/datadude-valid-create-view-syntax-throws-errors#details" target="_blank"&gt;Valid CREATE VIEW definition throws errors&lt;/a&gt; &lt;/li&gt;    &lt;li&gt;&lt;a href="https://connect.microsoft.com/VisualStudio/feedback/details/573824/datadude-unexplained-warnings-from-dbproj-project" target="_blank"&gt;MERGE syntax in a stored procedure creates false warnings&lt;/a&gt; &lt;/li&gt; &lt;/ul&gt;  &lt;p&gt;Some of these bugs were reported a long time ago and may well have been fixed in later service packs.&lt;/p&gt;  &lt;h1&gt;Previous datadude blog posts&lt;/h1&gt;  &lt;p&gt;I have &lt;a href="http://sqlblog.com/blogs/jamie_thomson/archive/tags/Datadude/default.aspx" target="_blank"&gt;blogged on datadude&lt;/a&gt; quite a bit in the past:&lt;/p&gt;  &lt;ul&gt;   &lt;li&gt;&lt;a href="http://sqlblog.com/blogs/jamie_thomson/archive/2011/11/21/workaround-for-datadude-deployment-bug.aspx"&gt;Workaround for datadude deployment bug – NullReferenceException&lt;/a&gt; &lt;/li&gt;    &lt;li&gt;&lt;a href="http://sqlblog.com/blogs/jamie_thomson/archive/2011/02/10/building-a-database-installer-with-wix-datadude-and-visual-studio-2010.aspx"&gt;Building a database installer with WiX, datadude and Visual Studio 2010&lt;/a&gt; &lt;/li&gt;    &lt;li&gt;&lt;a href="http://sqlblog.com/blogs/jamie_thomson/archive/2011/01/19/generate-multiple-sqlcmdvars-vars-in-your-database-projects.aspx"&gt;Generate multiple SqlCmdVars files in your database projects&lt;/a&gt; &lt;/li&gt;    &lt;li&gt;&lt;a href="http://sqlblog.com/blogs/jamie_thomson/archive/2011/01/17/querying-visual-studio-project-files.aspx"&gt;Querying Visual Studio project files using T-SQL and Powershell&lt;/a&gt; &lt;/li&gt;    &lt;li&gt;&lt;a href="http://sqlblog.com/blogs/jamie_thomson/archive/2010/10/19/maintaining-version-history-in-your-database-using-visual-studio-2010.aspx"&gt;Maintaining version history in your database using Visual Studio 2010&lt;/a&gt; &lt;/li&gt;    &lt;li&gt;&lt;a href="http://sqlblog.com/blogs/jamie_thomson/archive/2010/10/06/enforcing-naming-conventions-using-database-unit-testing.aspx"&gt;Enforcing naming conventions using database unit testing&lt;/a&gt; &lt;/li&gt;    &lt;li&gt;&lt;a href="http://sqlblog.com/blogs/jamie_thomson/archive/2010/09/18/experiences-from-writing-sp-cascadingdataviewer-db-unit-testing-and-code-distribution.aspx"&gt;Experiences from writing sp_CascadingDataViewer – DB unit testing and code distribution&lt;/a&gt; &lt;/li&gt;    &lt;li&gt;&lt;a href="http://sqlblog.com/blogs/jamie_thomson/archive/2010/09/14/some-thoughts-on-visual-studio-database-references-and-how-they-should-be-used-for-sql-server-bi.aspx"&gt;Some thoughts on Visual Studio database references and how they should be used for SQL Server BI&lt;/a&gt; &lt;/li&gt;    &lt;li&gt;&lt;a href="http://sqlblog.com/blogs/jamie_thomson/archive/2010/08/23/microsoft-publish-visual-studio-2010-database-project-guidance.aspx"&gt;Microsoft publish Visual Studio 2010 Database Project Guidance&lt;/a&gt; &lt;/li&gt;    &lt;li&gt;&lt;a href="http://sqlblog.com/blogs/jamie_thomson/archive/2010/08/20/setting-up-database-unit-testing-as-part-of-a-continuous-integration-build-process-vs2010-db-tools-datadude.aspx"&gt;Setting up database unit testing as part of a Continuous Integration build process [VS2010 DB Tools - Datadude]&lt;/a&gt; &lt;/li&gt;    &lt;li&gt;&lt;a href="http://sqlblog.com/blogs/jamie_thomson/archive/2010/07/21/a-strategy-for-managing-security-for-different-environments-using-the-database-development-tools-in-visual-studio-2010.aspx"&gt;A strategy for managing security for different environments using the Database Development Tools in Visual Studio 2010&lt;/a&gt; &lt;/li&gt; &lt;/ul&gt;  &lt;h1&gt;Summing up&lt;/h1&gt;  &lt;p&gt;This has been an inordinately large blog post so if you’ve read this far – well done. For easy reference, here are all the recommendations that I have made:&lt;/p&gt;  &lt;ol&gt;   &lt;li&gt;Use Source Control and implement a Continuous Integration deployment &lt;/li&gt;    &lt;li&gt;Turn on Code Analysis &lt;/li&gt;    &lt;li&gt;When running your deployment in a test environment, run it more than once &lt;/li&gt;    &lt;li&gt;Maintain an automated history of your deployments &lt;/li&gt;    &lt;li&gt;Use Schema View in preference to Solution Explorer &lt;/li&gt;    &lt;li&gt;Any action in a Pre or Post-Deployment Script should use PRINT to state what has been done &lt;/li&gt;    &lt;li&gt;Output the value of all variables in your Pre-Deployment script &lt;/li&gt;    &lt;li&gt;Each database object should be defined in a dedicated file &lt;/li&gt;    &lt;li&gt;Time your deployments and output the timings &lt;/li&gt;    &lt;li&gt;All literal values should be stored in your .sqlcmdvars file &lt;/li&gt;    &lt;li&gt;Every developer should use the Isolated Dev Environment settings in order to author their code &lt;/li&gt;    &lt;li&gt;Use “Not in Build” to remove an object from your database &lt;/li&gt;    &lt;li&gt;Build and deploy to your development sandbox using scripts &lt;/li&gt; &lt;/ol&gt;  &lt;p&gt;I really hope this proves useful because its taken a good long while to get it published &lt;img class="wlEmoticon wlEmoticon-smile" alt="Smile" src="http://sqlblog.com/blogs/jamie_thomson/wlEmoticon-smile_68C424BA.png"&gt; If you have any feedback then please let me know in the comments.&lt;/p&gt;  &lt;p&gt;Thanks for reading!&lt;/p&gt;  &lt;p&gt;&lt;a href="http://twitter.com/jamiet"&gt;@jamiet&lt;/a&gt;&lt;/p&gt;  &lt;p&gt;&lt;i&gt;* When I started writing this blog post the first sentence was “Over the past six months I have worked on two separate projects for customers that wanted to make use of Visual Studio 2010 Database projects to manage their database schema.” as opposed to what it is now: “Over the past eighteen months I have worked on four separate projects…” Yes, that’s how long its taken to write it! &lt;img class="wlEmoticon wlEmoticon-smile" alt="Smile" src="http://sqlblog.com/blogs/jamie_thomson/wlEmoticon-smile_68C424BA.png"&gt;&lt;/i&gt;&lt;/p&gt;  &lt;p&gt;&lt;i&gt;&lt;/i&gt;&lt;/p&gt;      &lt;h1&gt;Appendix – An example CI configuration&lt;/h1&gt;  &lt;p&gt;&lt;i&gt;As stated above, an earlier draft of this blog post included full details of the CI configuration from one of the projects that I have worked on. Although it may repeat some of what has already been said I have included that text below.&lt;/i&gt;&lt;/p&gt;  &lt;p&gt;&lt;i&gt;==============================================================&lt;/i&gt;&lt;/p&gt;  &lt;h2&gt;Introduction&lt;/h2&gt;  &lt;p&gt;This project has invested heavily in using a Continuous Integration (CI) approach to development. What that means, succinctly, is that whenever someone checks-in some code to our source control system an automated build process is kicked off that constructs our entire system from scratch on a dedicated server. CI is not a new concept but it is fairly rare that anyone applies the same rigour to their database objects as they do to so-called “application code” (e.g. the stuff written in .Net code) and on this project we have made a conscious decision to properly build our databases as part of the CI build.&lt;/p&gt;  &lt;p&gt;Datadude employs a &lt;i&gt;declarative&lt;/i&gt; approach to database development. In other words you define what you want database schema to look like and datadude will work out what it needs to do to your target in order to turn it into what you have defined. What this means in practice is that you only ever write CREATE … DDL statements rather than IF &amp;lt;object-exists&amp;gt; THEN ALTER …ELSE CREATE … statements which is what you may have done in the past.&lt;/p&gt;  &lt;p&gt;Here’s our CI environment setup:&lt;/p&gt;  &lt;ul&gt;   &lt;li&gt;SubVersion (SVN) is being used for source control &lt;/li&gt;    &lt;li&gt;&lt;a href="http://hudson-ci.org/"&gt;Hudson&lt;/a&gt;, an open source CI server, is being used to orchestrate our whole CI environment. It basically monitors our SVN repository and when it spots a checked-in file, kicks off the CI build &lt;/li&gt;    &lt;li&gt;Our CI scripts (the stuff that actually does the work) are written using &lt;a href="http://msdn.microsoft.com/en-us/library/0k6kkbsd.aspx"&gt;msbuild&lt;/a&gt; &lt;/li&gt;    &lt;li&gt;We have 2 msbuild scripts:      &lt;ul&gt;       &lt;li&gt;Build.proj which is responsible for:          &lt;ul&gt;           &lt;li&gt;Compiling all our .Net website code &lt;/li&gt;            &lt;li&gt;Building/Compiling our datadude projects&amp;nbsp; (every datadude project file is a msbuild-compliant script) &lt;/li&gt;         &lt;/ul&gt;       &lt;/li&gt;        &lt;li&gt;Deploy.proj which is responsible for:          &lt;ul&gt;           &lt;li&gt;Restoring latest database backups from our production environment into our CI environment &lt;/li&gt;            &lt;li&gt;Deploying our built datadude projects on top of those restored backups &lt;/li&gt;            &lt;li&gt;Build a folder structure to hold all the artefacts that get deployed &lt;/li&gt;            &lt;li&gt;Creating folder shares &lt;/li&gt;            &lt;li&gt;Moving SSIS packages into folder structure &lt;/li&gt;            &lt;li&gt;Deploying SSRS reports to our SSRS server &lt;/li&gt;            &lt;li&gt;Deploy our Analysis Services cube definitions to our Analysis Server &lt;/li&gt;         &lt;/ul&gt;       &lt;/li&gt;     &lt;/ul&gt;   &lt;/li&gt;    &lt;li&gt;Both Build.proj and Deploy.proj get executed by our CI build &lt;/li&gt; &lt;/ul&gt;  &lt;h2&gt;Building datadude projects&lt;/h2&gt;  &lt;p&gt;Datadude makes it very easy to build datadude projects in a CI environment because they are already msbuild-compliant; its simply a call to the MSBuild task, passing in the location of the solution file as an argument. We use the Release configuration (although there is no particular reason for you to do the same – purely your choice):&lt;/p&gt;  &lt;div style="font-size:10pt;"&gt;   &lt;div style="padding:2px 5px;overflow:auto;"&gt;&lt;span&gt;&amp;lt;&lt;/span&gt;&lt;span&gt;Target&lt;/span&gt;&lt;span&gt; &lt;/span&gt;&lt;span&gt;Name&lt;/span&gt;&lt;span&gt;=&lt;/span&gt;"&lt;span&gt;Database&lt;/span&gt;"&lt;span&gt;&amp;gt;&lt;/span&gt;       &lt;br&gt;&lt;span&gt;&amp;nbsp; &amp;lt;!--&lt;/span&gt;&lt;span&gt;Build database projects and copy output to staging &lt;/span&gt;&lt;span&gt;--&amp;gt;&lt;/span&gt;       &lt;br&gt;&lt;span&gt;&amp;nbsp; &amp;lt;&lt;/span&gt;&lt;span&gt;Message&lt;/span&gt;&lt;span&gt; &lt;/span&gt;&lt;span&gt;Text&lt;/span&gt;&lt;span&gt;=&lt;/span&gt;"&lt;span&gt;*****Building database solution&lt;/span&gt;"&lt;span&gt; /&amp;gt;&lt;/span&gt;       &lt;br&gt;&lt;span&gt;&amp;nbsp; &amp;lt;&lt;/span&gt;&lt;span&gt;MSBuild&lt;/span&gt;&lt;span&gt; &lt;/span&gt;&lt;span&gt;Projects&lt;/span&gt;&lt;span&gt;=&lt;/span&gt;"&lt;span&gt;..\src\SQL\DatabaseSolution.sln&lt;/span&gt;"&lt;span&gt; &lt;/span&gt;&lt;span&gt;Properties&lt;/span&gt;&lt;span&gt;=&lt;/span&gt;"&lt;span&gt;Configuration=Release&lt;/span&gt;"&lt;span&gt; /&amp;gt;&lt;/span&gt;       &lt;br&gt;&lt;span&gt;&amp;lt;/&lt;/span&gt;&lt;span&gt;Target&lt;/span&gt;&lt;span&gt;&amp;gt;&lt;/span&gt;&lt;/div&gt; &lt;/div&gt;  &lt;p&gt;That’s it! The output from a datadude build includes a number of files but the most important one is a .dbschema file which is an XML representation of all the objects in your database.&lt;/p&gt;  &lt;h2&gt;Deploying the output from a built datadude project&lt;/h2&gt;  &lt;p&gt;This is a little more difficult. We *&lt;b&gt;could&lt;/b&gt;* simply use the MSBuild task to call our deployment script as we do for build script (see above) but the problem with that is that there are many pre-requisites (including datadude itself) and we don’t want to install Visual Studio and all the assorted paraphernalia onto our various environments. Instead we chose to make use of a command-line tool called &lt;a href="http://msdn.microsoft.com/en-us/library/dd193283.aspx"&gt;VSDBCMD.exe&lt;/a&gt; to deploy datadude projects. VSDBCMD does basically the same job as what happens if you were to right-click on a datadude project in Visual Studio and select “Deploy” i.e. It compares the output of a build (A) to the target database (B) and works out what it needs to do to make B look like A. It then produces a .sql script that will actually make those requisite changes, then goes and executes it.&lt;/p&gt;  &lt;p&gt;The difficulty comes in VSDBCMD.exe having its own list of file dependencies that are listed at MSDN article &lt;a href="http://msdn.microsoft.com/en-us/library/dd193258.aspx"&gt;How to: Prepare a Database for Deployment From a Command Prompt by Using VSDBCMD.EXE&lt;/a&gt;, thankfully a much smaller list then if we were using the MSBuild task.&lt;/p&gt;  &lt;blockquote&gt;   &lt;p&gt;&lt;a href="http://sqlblog.com/blogs/jamie_thomson/image_334B6295.png"&gt;&lt;img style="border-width:0px;padding-top:0px;padding-right:0px;padding-left:0px;display:inline;background-image:none;" title="image" border="0" alt="image" src="http://sqlblog.com/blogs/jamie_thomson/image_thumb_11EBBCF9.png" width="581" height="389"&gt;&lt;/a&gt;&lt;/p&gt; &lt;/blockquote&gt;  &lt;p&gt;Some of those files, namely:&lt;/p&gt;  &lt;ul&gt;   &lt;li&gt;Sqlceer35en.dll &lt;/li&gt;    &lt;li&gt;Sqlceme35.dll &lt;/li&gt;    &lt;li&gt;Sqlceqp35.dll &lt;/li&gt;    &lt;li&gt;Sqlcese35.dll &lt;/li&gt;    &lt;li&gt;System.Data.SqlServerCe.dll &lt;/li&gt; &lt;/ul&gt;  &lt;p&gt;get installed with SQL Server CE. We bundle along the x86 &amp;amp; x64 installers for SQL Server CE along with all the rest of our deployment artefacts and then, as part of Deploy.proj, install them like so:&lt;/p&gt;  &lt;div style="font-size:10pt;"&gt;   &lt;div style="padding:2px 5px;overflow:auto;"&gt;&lt;span&gt;&amp;lt;&lt;/span&gt;&lt;span&gt;Exec&lt;/span&gt;&lt;span&gt; &lt;/span&gt;&lt;span&gt;Command&lt;/span&gt;&lt;span&gt;=&lt;/span&gt;'&lt;span&gt;msiexec /passive /l* "$(SetupLogDirectory)\SSCERuntime_x86-ENU.log" /i "$(BuildDir)\Vendor\SSCERuntime_x86-ENU.msi"&lt;/span&gt;'&lt;span&gt; /&amp;gt;&lt;/span&gt;       &lt;br&gt;&lt;span&gt;&amp;lt;&lt;/span&gt;&lt;span&gt;Exec&lt;/span&gt;&lt;span&gt; &lt;/span&gt;&lt;span&gt;Condition&lt;/span&gt;&lt;span&gt;=&lt;/span&gt;"&lt;span&gt;$(X64)&lt;/span&gt;"&lt;span&gt; &lt;/span&gt;&lt;span&gt;Command&lt;/span&gt;&lt;span&gt;=&lt;/span&gt;'&lt;span&gt;msiexec /passive /l* "$(SetupLogDirectory)\SSCERuntime_x64-ENU.log" /i "$(BuildDir)\Vendor\SSCERuntime_x64-ENU.msi"&lt;/span&gt;'&lt;span&gt; /&amp;gt;&lt;/span&gt;&lt;/div&gt; &lt;/div&gt;  &lt;p&gt;That takes care of some of the dependencies but we still have to take care of:&lt;/p&gt;  &lt;ul&gt;   &lt;li&gt;DatabaseSchemaProviders.Extensions.xml &lt;/li&gt;    &lt;li&gt;Microsoft.Data.Schema.dll &lt;/li&gt;    &lt;li&gt;Microsoft.Data.Schema.ScriptDom.dll &lt;/li&gt;    &lt;li&gt;Microsoft.Data.Schema.ScriptDom.Sql.dll &lt;/li&gt;    &lt;li&gt;Microsoft.Data.Schema.Sql.dll &lt;/li&gt;    &lt;li&gt;Microsoft.SqlServer.BatchParser.dll &lt;/li&gt; &lt;/ul&gt;  &lt;p&gt;as well as the actual VSDBCMD.exe file itself. Quite simply we keep those files in SVN and then bundle them along with all our deployment artefacts (I won’t show you how we do that because its out of the scope of this post and besides if you’re at all proficient with msbuild then you’ll know how to do that and if you’re not, well, why are you reading this?)&lt;/p&gt;  &lt;p&gt;&lt;i&gt;==============================================================&lt;/i&gt;&lt;/p&gt;</description></item><item><title>Maintaining version history in your database using Visual Studio 2010</title><link>http://sqlblog.com/blogs/jamie_thomson/archive/2010/10/19/maintaining-version-history-in-your-database-using-visual-studio-2010.aspx</link><pubDate>Tue, 19 Oct 2010 19:26:14 GMT</pubDate><guid isPermaLink="false">21093a07-8b3d-42db-8cbf-3350fcbf5496:29503</guid><dc:creator>jamiet</dc:creator><description>&lt;p&gt;I have written a few blogs lately explaining how my current project is employing the use of datadude (aka the database development tools in Visual Studio 2010) in order to manage our database code, deployment of that code and also testing of it. In this blog post I’m going to share a little technique that we use in order to store a version history of our deployments. Note that this assumes a working knowledge of datadude so if you don’t know what the terms Post-Deployment script, SQLCMD variables, Continuous Integration &amp;amp; msbuild refer to then maybe this blog post is not for you!&lt;/p&gt;  &lt;p&gt;&amp;#160;&lt;/p&gt;  &lt;h3&gt;&lt;b&gt;Need a table&lt;/b&gt;&lt;/h3&gt;  &lt;p&gt;Firstly, we need a table to store our version history, in our case we have called it &lt;font face="Consolas"&gt;[BuildVersion]&lt;/font&gt; and it looks like this:&lt;/p&gt; &lt;code style="font-size:12px;"&gt;&lt;span style="color:black;"&gt;     &lt;blockquote&gt;       &lt;p&gt;         &lt;br /&gt;&lt;/p&gt;       &lt;span style="color:blue;"&gt;CREATE TABLE &lt;/span&gt;&lt;span style="color:black;"&gt;[dbo].[BuildVersion]         &lt;br /&gt;&lt;/span&gt;&lt;span style="color:gray;"&gt;(         &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160; &lt;/span&gt;&lt;span style="color:black;"&gt;[BuildVersion] &lt;/span&gt;&lt;span style="color:blue;"&gt;NVARCHAR&lt;/span&gt;&lt;span style="color:gray;"&gt;(&lt;/span&gt;&lt;span style="color:black;"&gt;20&lt;/span&gt;&lt;span style="color:gray;"&gt;) NOT NULL,         &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160; &lt;/span&gt;&lt;span style="color:black;"&gt;[Deployed]&amp;#160;&amp;#160;&amp;#160;&amp;#160; &lt;/span&gt;&lt;span style="color:blue;"&gt;DATETIME &lt;/span&gt;&lt;span style="color:gray;"&gt;NOT NULL         &lt;br /&gt;)          &lt;br /&gt;&lt;/span&gt;&lt;/blockquote&gt;   &lt;/span&gt;&lt;/code&gt;  &lt;blockquote&gt;   &lt;p&gt;&lt;a href="http://sqlblog.com/blogs/jamie_thomson/20101019schema_view_722CAE33.png"&gt;&lt;img style="background-image:none;border-bottom:0px;border-left:0px;margin:;padding-left:0px;padding-right:0px;display:inline;border-top:0px;border-right:0px;padding-top:0px;" title="20101019schema_view" border="0" alt="20101019schema_view" src="http://sqlblog.com/blogs/jamie_thomson/20101019schema_view_thumb_0FBE8933.png" width="311" height="277" /&gt;&lt;/a&gt;&lt;/p&gt;    &lt;p&gt;&amp;#160;&lt;/p&gt; &lt;/blockquote&gt;  &lt;h3&gt;&lt;b&gt;Need a project variable&lt;/b&gt;&lt;/h3&gt;  &lt;p&gt;We have a SQLCMD variable declared as part of our project that is intended to hold a version number. In datadude SQLCMD variables are (by default) declared in a file called &lt;strong&gt;Database.sqlcmdvars&lt;/strong&gt;:&lt;/p&gt;  &lt;blockquote&gt;   &lt;p&gt;&lt;a href="http://sqlblog.com/blogs/jamie_thomson/20101019slcmdvars_solnexp_2DBC9727.png"&gt;&lt;img style="background-image:none;border-bottom:0px;border-left:0px;margin:;padding-left:0px;padding-right:0px;display:inline;border-top:0px;border-right:0px;padding-top:0px;" title="20101019slcmdvars_solnexp" border="0" alt="20101019slcmdvars_solnexp" src="http://sqlblog.com/blogs/jamie_thomson/20101019slcmdvars_solnexp_thumb_53461488.png" width="307" height="256" /&gt;&lt;/a&gt;&lt;/p&gt; &lt;/blockquote&gt;  &lt;p&gt;In our case we have a variable called ‘BuildVersion’ that we default to the value of “Unknown”&lt;/p&gt;  &lt;blockquote&gt;   &lt;p&gt;&lt;a href="http://sqlblog.com/blogs/jamie_thomson/20101019sqlcmdvars_vars_55AED07D.jpg"&gt;&lt;img style="background-image:none;border-bottom:0px;border-left:0px;margin:;padding-left:0px;padding-right:0px;display:inline;border-top:0px;border-right:0px;padding-top:0px;" title="20101019sqlcmdvars_vars" border="0" alt="20101019sqlcmdvars_vars" src="http://sqlblog.com/blogs/jamie_thomson/20101019sqlcmdvars_vars_thumb_5391D1B4.jpg" width="476" height="134" /&gt;&lt;/a&gt;&lt;/p&gt;    &lt;p&gt;&amp;#160;&lt;/p&gt; &lt;/blockquote&gt;  &lt;h3&gt;&lt;b&gt;Need to populate the table&lt;/b&gt;&lt;/h3&gt;  &lt;p&gt;We use the value in our ‘BuildVersion’ variable in order to populate our [BuildVersion] table and we do that within a Post-Deployment script using the following simple code:&lt;/p&gt;  &lt;blockquote&gt;   &lt;p&gt;&lt;code style="font-size:12px;"&gt;&lt;span style="color:blue;"&gt;INSERT&amp;#160;&amp;#160; &lt;/span&gt;&lt;span style="color:black;"&gt;[dbo].[BuildVersion]&lt;/span&gt;&lt;span style="color:gray;"&gt;(&lt;/span&gt;&lt;span style="color:black;"&gt;[BuildVersion]&lt;/span&gt;&lt;span style="color:gray;"&gt;, &lt;/span&gt;&lt;span style="color:black;"&gt;[Deployed]&lt;/span&gt;&lt;span style="color:gray;"&gt;)         &lt;br /&gt;&lt;/span&gt;&lt;span style="color:blue;"&gt;VALUES&amp;#160;&amp;#160; &lt;/span&gt;&lt;span style="color:gray;"&gt;(&lt;/span&gt;&lt;span style="color:red;"&gt;'$(BuildVersion)'&lt;/span&gt;&lt;span style="color:gray;"&gt;, &lt;/span&gt;&lt;span style="color:magenta;"&gt;GETDATE&lt;/span&gt;&lt;span style="color:gray;"&gt;())&amp;#160; &lt;/span&gt;&lt;span style="color:green;"&gt;--$(BuildVersion is a SQLCMD variable declared within this project)&lt;/span&gt;&lt;/code&gt; &lt;/p&gt;    &lt;p&gt;&amp;#160;&lt;/p&gt; &lt;/blockquote&gt;  &lt;h3&gt;&lt;b&gt;And of course we need to tell our mechanism what the build number is&lt;/b&gt;&lt;/h3&gt;  &lt;p&gt;We need to make sure that $(BuildVersion) has a value in it. As we are deploying our database as part of a continuous integration build (leveraging msbuild) we can pass in a value from the msbuild script. Here’s the code that we use to do that:&lt;/p&gt;  &lt;blockquote&gt;   &lt;p&gt;&lt;font face="Consolas"&gt;&lt;font color="#0000ff"&gt;&amp;lt;&lt;/font&gt;&lt;font color="#c0504d"&gt;Exec &lt;/font&gt;&lt;font color="#ff0000"&gt;Command&lt;/font&gt;&lt;font color="#0000ff"&gt;=&lt;/font&gt;&amp;quot;&lt;font color="#0000ff"&gt;..\VSDBCMD\vsdbcmd.exe /Action:Deploy /ConnectionString:&lt;/font&gt;&lt;font color="#ff0000"&gt;&amp;amp;quot&lt;/font&gt;&lt;font color="#ff0000"&gt;;&lt;/font&gt;&lt;font color="#0000ff"&gt;Data Source=$(Server);Integrated Security=True&lt;/font&gt;&lt;font color="#ff0000"&gt;&amp;amp;quot;&lt;/font&gt; &lt;font color="#0000ff"&gt;/DeployToDatabase:+ /ManifestFile:&lt;/font&gt;&lt;font color="#ff0000"&gt;&amp;amp;quot;&lt;/font&gt;&lt;font color="#0000ff"&gt;..\MyDB.deploymanifest&lt;/font&gt;&lt;font color="#ff0000"&gt;&amp;amp;quot;&lt;/font&gt; &lt;u&gt;&lt;font color="#0000ff"&gt;/p:BuildVersion=&lt;/font&gt;&lt;/u&gt;&lt;u&gt;&lt;font color="#ff0000"&gt;&amp;amp;quot;&lt;/font&gt;&lt;font color="#0000ff"&gt;$(BuildLabel)&lt;/font&gt;&lt;font color="#ff0000"&gt;&amp;amp;quot;&lt;/font&gt;&lt;/u&gt;&amp;quot; &lt;font color="#0000ff"&gt;/&amp;gt;&lt;/font&gt;&lt;/font&gt;&lt;/p&gt; &lt;/blockquote&gt;  &lt;pre&gt;&lt;font face="Calibri"&gt;The important bit for what we are discussing herein is that last underlined part:&lt;/font&gt;&lt;/pre&gt;

&lt;blockquote&gt;
  &lt;p&gt;&lt;font face="Consolas"&gt;&lt;u&gt;&lt;font color="#0000ff"&gt;/p:BuildVersion=&lt;/font&gt;&lt;/u&gt;&lt;u&gt;&lt;font color="#ff0000"&gt;&amp;amp;quot;&lt;/font&gt;&lt;font color="#0000ff"&gt;$(BuildLabel)&lt;/font&gt;&lt;font color="#ff0000"&gt;&amp;amp;quot;&lt;/font&gt;&lt;/u&gt;&lt;/font&gt;&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;The /p directive is used to populate a named variable (in our case &lt;font color="#0000ff" face="Consolas"&gt;BuildVersion&lt;/font&gt;) with a value. In our case than value is taken from an msbuild property which, in our case, is referred to by &lt;font color="#0000ff"&gt;$(BuildLabel)&lt;/font&gt;. [Note that managing msbuild properties is outside the scope of this blog post.]&lt;/p&gt;

&lt;p&gt;&lt;b&gt;&lt;/b&gt;&lt;/p&gt;

&lt;h3&gt;Wrap-up&lt;/h3&gt;

&lt;p&gt;That’s pretty much all you need. If it all hangs together correctly then &lt;font face="Consolas"&gt;[BuildVersion]&lt;/font&gt; will contain a nice history of all your deployments like so:&lt;/p&gt;

&lt;blockquote&gt;
  &lt;p&gt;&lt;a href="http://sqlblog.com/blogs/jamie_thomson/20101019results_074A8E0F.png"&gt;&lt;img style="background-image:none;border-bottom:0px;border-left:0px;margin:;padding-left:0px;padding-right:0px;display:inline;border-top:0px;border-right:0px;padding-top:0px;" title="20101019results" border="0" alt="20101019results" src="http://sqlblog.com/blogs/jamie_thomson/20101019results_thumb_184EBBF2.png" width="461" height="215" /&gt;&lt;/a&gt;&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;Hope this is useful! I suspect the same technique will work in earlier versions of datadude but I don’t have any to hand so can’t find out.&lt;/p&gt;

&lt;p&gt;&lt;a href="http://twitter.com/jamiet"&gt;@Jamiet&lt;/a&gt;&lt;/p&gt;</description></item><item><title>Experiences from writing sp_CascadingDataViewer – DB unit testing and code distribution</title><link>http://sqlblog.com/blogs/jamie_thomson/archive/2010/09/18/experiences-from-writing-sp-cascadingdataviewer-db-unit-testing-and-code-distribution.aspx</link><pubDate>Sat, 18 Sep 2010 16:41:55 GMT</pubDate><guid isPermaLink="false">21093a07-8b3d-42db-8cbf-3350fcbf5496:28849</guid><dc:creator>jamiet</dc:creator><description>&lt;p&gt;Its now been a month since I &lt;a href="http://sqlblog.com/blogs/jamie_thomson/archive/2010/08/11/introducing-sp-cascadingdataviewer.aspx" target="_blank"&gt;introduced sp_CascadingDataViewer&lt;/a&gt; and I wanted to take the opportunity to talk about a couple of my experiences while writing it.&lt;/p&gt;  &lt;p&gt;&amp;#160;&lt;/p&gt;  &lt;h2&gt;SQL Server needs packages&lt;/h2&gt;  &lt;p&gt;Version 1 of sp_CascadingDataViewer is an 899 line stored procedure (view the code at &lt;a href="http://cascadingdataviewer.codeplex.com/SourceControl/changeset/view/58999#1568990" target="_blank"&gt;changeset 58999&lt;/a&gt;), that’s a lot of code and much of it is repeated. I would have loved to have hived off different parts into dedicated functions but I couldn’t do that because my aim was to keep everything in a single stored procedure thus making it as easy as possible for someone to add it to their SQL Server instance. That is an unfortunate trade-off that we have to make with SQL Server.&lt;/p&gt;  &lt;p&gt;Oracle has a solution to this problem called packages. A package is ostensibly a collection of stored procedures and functions that can be distributed and installed as a single unit. That makes them extremely portable and would be an ideal mechanism for me to distribute a collection of stored procedures and functions that make up Cascading Data Viewer.&lt;/p&gt;  &lt;p&gt;SQL Server needs something equivalent to Oracle packages.&lt;/p&gt;  &lt;p&gt;&amp;#160;&lt;/p&gt;  &lt;h2&gt;You need to be doing automated database unit testing&lt;/h2&gt;  &lt;p&gt;sp_CascadingDataViewer wouldn’t exist without automated database unit testing in Visual Studio. Period.&lt;/p&gt;  &lt;p&gt;With something as complicated as sp_CascadingDataViewer there were many many combinations of code, schema and data that could cause is to break. I had to deal with all those combinations and have a way of ensuring that any changes that I made did not break something else and automated testing was the means with which I did that.&lt;/p&gt;  &lt;p&gt;I wrote the code for sp_CascadingDataViewer in Visual Studio rather than SQL Server Management Studio (as I do for all my T-SQL code these days) which meant that my code and the tests lived in the same solution. At the time of writing that solution includes 30 tests and all are available in &lt;a href="http://cascadingdataviewer.codeplex.com/SourceControl/list/changesets" target="_blank"&gt;the source code on Codeplex&lt;/a&gt;:&lt;/p&gt;  &lt;blockquote&gt;   &lt;p&gt;&lt;a href="http://sqlblog.com/blogs/jamie_thomson/image_5F31D6E2.png"&gt;&lt;img style="background-image:none;border-right-width:0px;margin:;padding-left:0px;padding-right:0px;display:inline;border-top-width:0px;border-bottom-width:0px;border-left-width:0px;padding-top:0px;" title="image" border="0" alt="image" src="http://sqlblog.com/blogs/jamie_thomson/image_thumb_79CE4D2E.png" width="529" height="628" /&gt;&lt;/a&gt;&lt;/p&gt; &lt;/blockquote&gt;  &lt;p&gt;With a simple key chord (CTRL+R, CTRL+A) I could deploy my code and run all my tests against it – that’s an incredibly powerful mechanism and I actually find it to be very productive method of development even if you have many tests that need to be run.&lt;/p&gt;  &lt;p&gt;Writing sp_CascadingDataViewer switched me on to the value of automated database unit testing and I now advocate its use wherever I go.&lt;/p&gt;  &lt;p&gt;&lt;a href="http://twitter.com/jamiet"&gt;@jamiet&lt;/a&gt;&lt;/p&gt;</description></item><item><title>Microsoft publish Visual Studio 2010 Database Project Guidance</title><link>http://sqlblog.com/blogs/jamie_thomson/archive/2010/08/23/microsoft-publish-visual-studio-2010-database-project-guidance.aspx</link><pubDate>Mon, 23 Aug 2010 11:33:00 GMT</pubDate><guid isPermaLink="false">21093a07-8b3d-42db-8cbf-3350fcbf5496:28174</guid><dc:creator>jamiet</dc:creator><description>&lt;SPAN class=Apple-style-span style="WORD-SPACING:0px;FONT:medium 'Times New Roman';TEXT-TRANSFORM:none;TEXT-INDENT:0px;WHITE-SPACE:normal;LETTER-SPACING:normal;BORDER-COLLAPSE:separate;orphans:2;widows:2;-webkit-border-horizontal-spacing:0px;-webkit-border-vertical-spacing:0px;-webkit-text-decorations-in-effect:none;-webkit-text-size-adjust:auto;-webkit-text-stroke-width:0px;"&gt;
&lt;DIV style="PADDING-RIGHT:8px;PADDING-LEFT:8px;FONT-SIZE:10pt;PADDING-BOTTOM:8px;PADDING-TOP:8px;FONT-FAMILY:Arial, Helvetica, sans-serif;"&gt;Three days ago I wrote a blog post entitled&amp;nbsp;&lt;A class="" href="http://sqlblog.com/blogs/jamie_thomson/archive/2010/08/20/setting-up-database-unit-testing-as-part-of-a-continuous-integration-build-process-vs2010-db-tools-datadude.aspx"&gt;Setting up database unit testing as part of a Continuous Integration build process [VS2010 DB Tools - Datadude]&lt;/A&gt;&amp;nbsp;which goes through some of the intracasies of using Visual Studio 2010 Database projects (aka datadude projects) and database unit testing as part of a continuous integration build. Well it turns out I needn't have bothered because today Microsoft have (or, more accurately, Jens Suessmeyer has) published a 91-page guidance document on using datadude projects and on page 57&amp;nbsp;it covers exactly what I covered in my blog post (plus a lot more besides). Ah well...&lt;/DIV&gt;
&lt;DIV style="PADDING-RIGHT:8px;PADDING-LEFT:8px;FONT-SIZE:10pt;PADDING-BOTTOM:8px;PADDING-TOP:8px;FONT-FAMILY:Arial, Helvetica, sans-serif;"&gt;Anyway, if you want to take a read of this tome head to &lt;A href="http://vsdatabaseguide.codeplex.com/"&gt;http://vsdatabaseguide.codeplex.com/&lt;/A&gt;&amp;nbsp;and/or go and read Jens' blog post on the matter &lt;A class="" href="http://blogs.msdn.com/b/jenss/archive/2010/08/21/alm-visual-studio-database-projects-guidance-is-out-in-the-wild.aspx"&gt;ALM Visual Studio Database Projects Guidance is out in the wild !&lt;/A&gt;&lt;/DIV&gt;
&lt;DIV style="PADDING-RIGHT:8px;PADDING-LEFT:8px;FONT-SIZE:10pt;PADDING-BOTTOM:8px;PADDING-TOP:8px;FONT-FAMILY:Arial, Helvetica, sans-serif;"&gt;&lt;A class="" href="http://twitter.com/jamiet"&gt;@Jamiet&lt;/A&gt;&lt;/DIV&gt;&lt;/SPAN&gt;</description></item><item><title>Setting up database unit testing as part of a Continuous Integration build process [VS2010 DB Tools - Datadude]</title><link>http://sqlblog.com/blogs/jamie_thomson/archive/2010/08/20/setting-up-database-unit-testing-as-part-of-a-continuous-integration-build-process-vs2010-db-tools-datadude.aspx</link><pubDate>Fri, 20 Aug 2010 18:41:00 GMT</pubDate><guid isPermaLink="false">21093a07-8b3d-42db-8cbf-3350fcbf5496:28103</guid><dc:creator>jamiet</dc:creator><description>&lt;P&gt;&lt;I&gt;&lt;FONT face=Consolas&gt;[This blog post assumes a familiarity with the terms Continuous Integration (CI), MSBuild &amp;amp; MSTest. If you don’t have a good appreciation of those terms then this blog post probably isn’t for you anyway so don’t worry about it!]&lt;/FONT&gt;&lt;/I&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT face=Consolas&gt;Over the past few days I have been working to get database unit tests executing as part of our Continuous Integration (CI) build and in this blog post I’ll explain how I went about it because it is decidedly &lt;I&gt;not&lt;/I&gt; straightforward.&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT face=Consolas&gt;We are using the &lt;STRONG&gt;DB Tools in Visual Studio 2010&lt;/STRONG&gt; (aka &lt;STRONG&gt;DBPro&lt;/STRONG&gt; or &lt;STRONG&gt;Datadude&lt;/STRONG&gt; - I will refer to it as Datadude from here on in) which includes unit testing functionality. The rest of this blog post also assumes a familiarity with database unit testing in Datadude although if you want to do some background reading an excellent place to start is Jamie Laflen’s whitepaper &lt;/FONT&gt;&lt;A href="http://msdn.microsoft.com/en-us/magazine/cc164243.aspx"&gt;&lt;FONT face=Consolas&gt;Apply Test-Driven Development to your Database Projects&lt;/FONT&gt;&lt;/A&gt;&lt;FONT face=Consolas&gt; on MSDN.&lt;/FONT&gt;&lt;/P&gt;&lt;FONT face=Consolas&gt;
&lt;HR&gt;
&lt;/FONT&gt;
&lt;P&gt;&lt;FONT face=Consolas&gt;We got to the point where we had a C# test project containing database unit tests that executed successfully inside Visual Studio. For demonstration purposes I have put together a solution that contains a simple database project and a test project containing a database unit test:&lt;/FONT&gt;&lt;/P&gt;
&lt;BLOCKQUOTE&gt;
&lt;P&gt;&lt;A href="http://sqlblog.com/blogs/jamie_thomson/cid_image001_png01CB4075_1B0AD4EE.png"&gt;&lt;FONT face=Consolas&gt;&lt;IMG title="Solution Explorer screenshot" style="BORDER-TOP-WIDTH:0px;PADDING-RIGHT:0px;DISPLAY:inline;PADDING-LEFT:0px;BORDER-LEFT-WIDTH:0px;BACKGROUND-IMAGE:none;BORDER-BOTTOM-WIDTH:0px;PADDING-TOP:0px;BORDER-RIGHT-WIDTH:0px;" height=433 alt="solution explorer" src="http://sqlblog.com/blogs/jamie_thomson/cid_image001_png01CB4075_thumb_7DC4E149.png" width=506 border=0&gt;&lt;/FONT&gt;&lt;/A&gt;&lt;/P&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;&lt;FONT face=Consolas&gt;And just to prove that the test executes successfully in Visual Studio:&lt;/FONT&gt;&lt;/P&gt;
&lt;BLOCKQUOTE&gt;
&lt;P&gt;&lt;A href="http://sqlblog.com/blogs/jamie_thomson/cid_image002_png01CB4075_10D5E829.png"&gt;&lt;FONT face=Consolas&gt;&lt;IMG title="Visual Studio Test Results screenshot" style="BORDER-TOP-WIDTH:0px;PADDING-RIGHT:0px;DISPLAY:inline;PADDING-LEFT:0px;BORDER-LEFT-WIDTH:0px;BACKGROUND-IMAGE:none;BORDER-BOTTOM-WIDTH:0px;PADDING-TOP:0px;BORDER-RIGHT-WIDTH:0px;" height=249 alt="Visual Studio Test Results screenshot" src="http://sqlblog.com/blogs/jamie_thomson/cid_image002_png01CB4075_thumb_1DCFC83A.png" width=856 border=0&gt;&lt;/FONT&gt;&lt;/A&gt;&lt;/P&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;&lt;FONT face=Consolas&gt;N.B. The code for the database object(s) and the unit test itself are not important, that is outside the scope of this blog post.&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT face=Consolas&gt;At this point we have some tests that run in our development sandbox, the configuration for which is done using the Database Test Configuration dialog:&lt;/FONT&gt;&lt;/P&gt;
&lt;BLOCKQUOTE&gt;
&lt;P&gt;&lt;A href="http://sqlblog.com/blogs/jamie_thomson/cid_image003_png01CB4076_14938CF9.png"&gt;&lt;FONT face=Consolas&gt;&lt;IMG title="database test configuration choice" style="BORDER-TOP-WIDTH:0px;PADDING-RIGHT:0px;DISPLAY:inline;PADDING-LEFT:0px;BORDER-LEFT-WIDTH:0px;BACKGROUND-IMAGE:none;BORDER-BOTTOM-WIDTH:0px;PADDING-TOP:0px;BORDER-RIGHT-WIDTH:0px;" height=382 alt="database test configuration choice" src="http://sqlblog.com/blogs/jamie_thomson/cid_image003_png01CB4076_thumb_057CAE1F.png" width=786 border=0&gt;&lt;/FONT&gt;&lt;/A&gt;&lt;/P&gt;&lt;/BLOCKQUOTE&gt;
&lt;BLOCKQUOTE&gt;
&lt;P&gt;&lt;A href="http://sqlblog.com/blogs/jamie_thomson/cid_image004_png01CB4076_70AAB59E.png"&gt;&lt;FONT face=Consolas&gt;&lt;IMG title="database test configuration dialog" style="BORDER-TOP-WIDTH:0px;PADDING-RIGHT:0px;DISPLAY:inline;PADDING-LEFT:0px;BORDER-LEFT-WIDTH:0px;BACKGROUND-IMAGE:none;BORDER-BOTTOM-WIDTH:0px;PADDING-TOP:0px;BORDER-RIGHT-WIDTH:0px;" height=638 alt="database test configuration dialog" src="http://sqlblog.com/blogs/jamie_thomson/cid_image004_png01CB4076_thumb_4FB742F7.png" width=508 border=0&gt;&lt;/FONT&gt;&lt;/A&gt;&lt;/P&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;&lt;FONT face=Consolas&gt;Those config settings are stored in the app.config file which exists as part of our test project (screenshot of which is at the top of this blog post). If we take a look inside that file we can see the&lt;/FONT&gt; &lt;FONT face="Courier New"&gt;ConnectionString&lt;/FONT&gt; &lt;FONT face=Consolas&gt;that we defined in the Database Test Configuration dialog:&lt;/FONT&gt;&lt;/P&gt;
&lt;BLOCKQUOTE&gt;
&lt;P&gt;&lt;A href="http://sqlblog.com/blogs/jamie_thomson/cid_image005_png01CB4076_5F76D7FB.png"&gt;&lt;IMG title="app config connectionString DatabaseUnitTesting" style="BORDER-TOP-WIDTH:0px;PADDING-RIGHT:0px;DISPLAY:inline;PADDING-LEFT:0px;BORDER-LEFT-WIDTH:0px;BACKGROUND-IMAGE:none;BORDER-BOTTOM-WIDTH:0px;PADDING-TOP:0px;BORDER-RIGHT-WIDTH:0px;" height=271 alt="app config connectionString DatabaseUnitTesting" src="http://sqlblog.com/blogs/jamie_thomson/cid_image005_png01CB4076_thumb_17491C1F.png" width=959 border=0&gt;&lt;/A&gt;&lt;/P&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;&lt;FONT face=Consolas&gt;Note the&lt;/FONT&gt; &lt;FONT face="Courier New"&gt;&lt;FONT color=#0000ff&gt;&amp;lt;&lt;/FONT&gt;&lt;FONT color=#c0504d&gt;DatabaseUnitTesting&lt;/FONT&gt;&lt;FONT color=#0000ff&gt;&amp;gt;&lt;/FONT&gt; &lt;/FONT&gt;&lt;FONT face=Consolas&gt;element, we’re going to be coming back to that a little later!!&lt;/FONT&gt;&lt;/P&gt;&lt;FONT face=Consolas&gt;
&lt;HR&gt;
&lt;/FONT&gt;
&lt;P&gt;&lt;FONT face=Consolas&gt;Once we have the tests running in Visual Studio the next step is to get them running inside a CI build and for that we call out to MSTest.exe from inside an MSBuild script:&lt;/FONT&gt;&lt;/P&gt;
&lt;BLOCKQUOTE&gt;
&lt;P&gt;&lt;A href="http://sqlblog.com/blogs/jamie_thomson/cid_image006_png01CB407D_54F603DB.png"&gt;&lt;FONT face=Consolas&gt;&lt;IMG title="msbuild script mstest" style="BORDER-TOP-WIDTH:0px;PADDING-RIGHT:0px;DISPLAY:inline;PADDING-LEFT:0px;BORDER-LEFT-WIDTH:0px;BACKGROUND-IMAGE:none;BORDER-BOTTOM-WIDTH:0px;PADDING-TOP:0px;BORDER-RIGHT-WIDTH:0px;" height=155 alt="msbuild script mstest" src="http://sqlblog.com/blogs/jamie_thomson/cid_image006_png01CB407D_thumb_733FF92A.png" width=1069 border=0&gt;&lt;/FONT&gt;&lt;/A&gt;&lt;/P&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;&lt;FONT face=Consolas&gt;When we execute that script we get some positive results and all looks peachy:&lt;/FONT&gt;&lt;/P&gt;
&lt;BLOCKQUOTE&gt;
&lt;P&gt;&lt;A href="http://sqlblog.com/blogs/jamie_thomson/cid_image007_png01CB407D_380C1D5F.png"&gt;&lt;FONT face=Consolas&gt;&lt;IMG title="msbuild mstest output" style="BORDER-TOP-WIDTH:0px;PADDING-RIGHT:0px;DISPLAY:inline;PADDING-LEFT:0px;BORDER-LEFT-WIDTH:0px;BACKGROUND-IMAGE:none;BORDER-BOTTOM-WIDTH:0px;PADDING-TOP:0px;BORDER-RIGHT-WIDTH:0px;" height=534 alt="msbuild mstest output" src="http://sqlblog.com/blogs/jamie_thomson/cid_image007_png01CB407D_thumb_4837E558.png" width=650 border=0&gt;&lt;/FONT&gt;&lt;/A&gt;&lt;/P&gt;&lt;/BLOCKQUOTE&gt;&lt;FONT face=Consolas&gt;
&lt;HR&gt;
&lt;/FONT&gt;
&lt;P&gt;&lt;FONT face=Consolas&gt;OK, we now have a test that runs successfully both in Visual Studio and by calling MSTest.exe directly from MSBuild. The problem I have to solve now though (and this is the real crux of this blog post) is that the test is still running against the server I specified in app.config; I don’t want this, I want the test to run against a server of my choosing, namely my build server. For this I had to call on the help of the aforementioned Jamie Laflen (who, luckily, I have met in the past) and he gave me guidance on how to achieve it. Below are the steps that you need to take.&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT face=Consolas&gt;Firstly you need to tell Datadude that you want to specify some different credentials and that is done by adding an attribute&lt;/FONT&gt; &lt;FONT face="Courier New"&gt;&lt;FONT color=#ff0000&gt;AllowConfigurationOverride&lt;/FONT&gt;&lt;FONT color=#0000ff&gt;=&lt;/FONT&gt;"&lt;FONT color=#0000ff&gt;true&lt;/FONT&gt;"&lt;/FONT&gt;&lt;FONT face=Consolas&gt; to the&lt;/FONT&gt; &lt;FONT face="Courier New"&gt;&lt;FONT color=#0000ff&gt;&amp;lt;&lt;/FONT&gt;&lt;FONT color=#c0504d&gt;DatabaseUnitTesting&lt;/FONT&gt;&lt;FONT color=#0000ff&gt;&amp;gt;&lt;/FONT&gt; &lt;/FONT&gt;&lt;FONT face=Consolas&gt;element of app.config like so:&lt;/FONT&gt;&lt;/P&gt;
&lt;BLOCKQUOTE&gt;
&lt;P&gt;&lt;A href="http://sqlblog.com/blogs/jamie_thomson/cid_image008_png01CB407E_32F9B9E3.png"&gt;&lt;FONT face=Consolas&gt;&lt;IMG title="app config DatabaseUnitTesting AllowConfigurationOverride" style="BORDER-TOP-WIDTH:0px;PADDING-RIGHT:0px;DISPLAY:inline;PADDING-LEFT:0px;BORDER-LEFT-WIDTH:0px;BACKGROUND-IMAGE:none;BORDER-BOTTOM-WIDTH:0px;PADDING-TOP:0px;BORDER-RIGHT-WIDTH:0px;" height=345 alt="app config DatabaseUnitTesting AllowConfigurationOverride" src="http://sqlblog.com/blogs/jamie_thomson/cid_image008_png01CB407E_thumb_23E2DB09.png" width=643 border=0&gt;&lt;/FONT&gt;&lt;/A&gt;&lt;/P&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;&lt;I&gt;&lt;FONT face=Consolas&gt;Don’t forget to build your test project after changing the app.config file!!!&lt;/FONT&gt;&lt;/I&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT face=Consolas&gt;This will cause datadude unit testing framework to go and search for a file called&lt;/FONT&gt; &lt;FONT face="Courier New"&gt;*.dbunittest.config&lt;/FONT&gt; &lt;FONT face=Consolas&gt;where the * indicates either:&lt;/FONT&gt;&lt;/P&gt;
&lt;UL&gt;
&lt;LI&gt;&lt;FONT face=Consolas&gt;The name of machine upon which the tests are being run or&lt;/FONT&gt; &lt;/LI&gt;
&lt;LI&gt;&lt;FONT face=Consolas&gt;The name of the user running the tests&lt;/FONT&gt; &lt;/LI&gt;&lt;/UL&gt;
&lt;P&gt;&lt;FONT face=Consolas&gt;According to Jamie L datadude runs the following precedence checks:&lt;/FONT&gt;&lt;/P&gt;
&lt;OL&gt;
&lt;LI&gt;&lt;FONT face=Consolas&gt;Is an override specified in app.config? If not, use app.config&lt;/FONT&gt; &lt;/LI&gt;
&lt;LI&gt;&lt;FONT face=Consolas&gt;Does an override file exist called &amp;lt;machinename&amp;gt;.dbunittest.config? If so, use it, if not…&lt;/FONT&gt; &lt;/LI&gt;
&lt;LI&gt;&lt;FONT face=Consolas&gt;Does an override file exist called &amp;lt;username&amp;gt;.dbunittest.config? If so, use it, if not…&lt;/FONT&gt; &lt;/LI&gt;
&lt;LI&gt;&lt;FONT face=Consolas&gt;Fail!&lt;/FONT&gt; &lt;/LI&gt;&lt;/OL&gt;
&lt;P&gt;&lt;FONT face=Consolas&gt;“So”, you may be asking, “what goes in this &lt;/FONT&gt;&lt;FONT face="Courier New"&gt;*.dbunittest.config&lt;/FONT&gt; file then?”. &lt;FONT face=Consolas&gt;Fair question, that’s where the&lt;/FONT&gt; &lt;FONT face="Courier New"&gt;&lt;FONT color=#0000ff&gt;&amp;lt;&lt;/FONT&gt;&lt;FONT color=#c0504d&gt;DatabaseUnitTesting&lt;/FONT&gt;&lt;FONT color=#0000ff&gt;&amp;gt;&lt;/FONT&gt; &lt;/FONT&gt;&lt;FONT face=Consolas&gt;element that I mentioned earlier comes in. Copy that element from the app.config file into your &lt;FONT face="Courier New"&gt;*.dbunittest.config&lt;/FONT&gt; file, remove the&lt;/FONT&gt;&amp;nbsp;&lt;FONT face="Courier New"&gt;&lt;FONT color=#ff0000&gt;AllowConfigurationOverride&lt;/FONT&gt;&lt;FONT color=#0000ff&gt;=&lt;/FONT&gt;"&lt;FONT color=#0000ff&gt;true&lt;/FONT&gt;"&lt;/FONT&gt;&lt;FONT face=Consolas&gt; attribute and change the&lt;/FONT&gt; &lt;FONT face="Courier New"&gt;ConnectionString&lt;/FONT&gt; &lt;FONT face=Consolas&gt;property accordingly:&lt;/FONT&gt;&lt;/P&gt;
&lt;BLOCKQUOTE&gt;
&lt;P&gt;&lt;A href="http://sqlblog.com/blogs/jamie_thomson/cid_image009_png01CB4081_20ED7656.png"&gt;&lt;FONT face=Consolas&gt;&lt;IMG title="dbunittest.config ConnectionString" style="BORDER-TOP-WIDTH:0px;PADDING-RIGHT:0px;DISPLAY:inline;PADDING-LEFT:0px;BORDER-LEFT-WIDTH:0px;BACKGROUND-IMAGE:none;BORDER-BOTTOM-WIDTH:0px;PADDING-TOP:0px;BORDER-RIGHT-WIDTH:0px;" height=236 alt="dbunittest.config ConnectionString" src="http://sqlblog.com/blogs/jamie_thomson/cid_image009_png01CB4081_thumb_7464466F.png" width=847 border=0&gt;&lt;/FONT&gt;&lt;/A&gt;&lt;/P&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;&lt;FONT face=Consolas&gt;The next step is to tell MSTest.exe that there is another file that it needs to be aware of when it runs the tests and to do that we need to create a custom testsettings file that will be used instead of the default Local.testsettings. To create a new testsettings file use the Add New Item dialog:&lt;/FONT&gt;&lt;/P&gt;
&lt;BLOCKQUOTE&gt;
&lt;P&gt;&lt;A href="http://sqlblog.com/blogs/jamie_thomson/cid_image010_png01CB4083_7D049EFB.png"&gt;&lt;FONT face=Consolas&gt;&lt;IMG title="add new test settings" style="BORDER-TOP-WIDTH:0px;PADDING-RIGHT:0px;DISPLAY:inline;PADDING-LEFT:0px;BORDER-LEFT-WIDTH:0px;BACKGROUND-IMAGE:none;BORDER-BOTTOM-WIDTH:0px;PADDING-TOP:0px;BORDER-RIGHT-WIDTH:0px;" height=466 alt="add new test settings" src="http://sqlblog.com/blogs/jamie_thomson/cid_image010_png01CB4083_thumb_1BDB12DA.png" width=825 border=0&gt;&lt;/FONT&gt;&lt;/A&gt;&lt;/P&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;&lt;FONT face=Consolas&gt;In the Test Settings dialog go to ‘Deployment’, click ‘Enable deployment’, then ‘Add File…’. Browse to your&lt;/FONT&gt;&lt;FONT face="Courier New"&gt; *.dbunittest.config &lt;/FONT&gt;&lt;FONT face=Consolas&gt;file and add it to the project:&lt;/FONT&gt;&lt;/P&gt;
&lt;BLOCKQUOTE&gt;
&lt;P&gt;&lt;A href="http://sqlblog.com/blogs/jamie_thomson/cid_image011_png01CB4083_39D920CE.png"&gt;&lt;FONT face=Consolas&gt;&lt;IMG title="test settings dialog" style="BORDER-TOP-WIDTH:0px;PADDING-RIGHT:0px;DISPLAY:inline;PADDING-LEFT:0px;BORDER-LEFT-WIDTH:0px;BACKGROUND-IMAGE:none;BORDER-BOTTOM-WIDTH:0px;PADDING-TOP:0px;BORDER-RIGHT-WIDTH:0px;" height=655 alt="test settings dialog" src="http://sqlblog.com/blogs/jamie_thomson/cid_image011_png01CB4083_thumb_3FB3C467.png" width=892 border=0&gt;&lt;/FONT&gt;&lt;/A&gt;&lt;/P&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;&lt;FONT face=Consolas&gt;At this point you’re good to go and all you need to do edit your call to MSTest.exe and tell it to use your new testsettings file:&lt;/FONT&gt;&lt;/P&gt;
&lt;BLOCKQUOTE&gt;
&lt;P&gt;&lt;A href="http://sqlblog.com/blogs/jamie_thomson/cid_image012_png01CB4084_5CD96C71.png"&gt;&lt;FONT face=Consolas&gt;&lt;IMG title="msbuild script mstest testsettings" style="BORDER-TOP-WIDTH:0px;PADDING-RIGHT:0px;DISPLAY:inline;PADDING-LEFT:0px;BORDER-LEFT-WIDTH:0px;BACKGROUND-IMAGE:none;BORDER-BOTTOM-WIDTH:0px;PADDING-TOP:0px;BORDER-RIGHT-WIDTH:0px;" height=163 alt="msbuild script mstest testsettings" src="http://sqlblog.com/blogs/jamie_thomson/cid_image012_png01CB4084_thumb_70865605.png" width=1011 border=0&gt;&lt;/FONT&gt;&lt;/A&gt;&lt;/P&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;&lt;FONT face=Consolas&gt;Notice the extra information in the output:&lt;/FONT&gt;&lt;/P&gt;
&lt;BLOCKQUOTE&gt;
&lt;P&gt;&lt;A href="http://sqlblog.com/blogs/jamie_thomson/cid_image013_png01CB4084_2F0BA3AC.png"&gt;&lt;FONT face=Consolas&gt;&lt;IMG title="msbuild script output" style="BORDER-TOP-WIDTH:0px;PADDING-RIGHT:0px;DISPLAY:inline;PADDING-LEFT:0px;BORDER-LEFT-WIDTH:0px;BACKGROUND-IMAGE:none;BORDER-BOTTOM-WIDTH:0px;PADDING-TOP:0px;BORDER-RIGHT-WIDTH:0px;" height=577 alt="msbuild script output" src="http://sqlblog.com/blogs/jamie_thomson/cid_image013_png01CB4084_thumb_4DE2178A.png" width=702 border=0&gt;&lt;/FONT&gt;&lt;/A&gt;&lt;/P&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;&lt;FONT face=Consolas&gt;You’ll have to trust me that it used the new config file and therefore the new &lt;/FONT&gt;&lt;FONT face="Courier New"&gt;ConnectionString&lt;/FONT&gt;&lt;FONT face=Consolas&gt;, although having said that you do get some useful information in the test results file (*.trx) that MSTest.exe creates:&lt;/FONT&gt;&lt;/P&gt;
&lt;BLOCKQUOTE&gt;
&lt;P&gt;&lt;A href="http://sqlblog.com/blogs/jamie_thomson/cid_image014_png01CB4085_248ACF8C.png"&gt;&lt;FONT face=Consolas&gt;&lt;IMG title="mstest test results trx output" style="BORDER-TOP-WIDTH:0px;PADDING-RIGHT:0px;DISPLAY:inline;PADDING-LEFT:0px;BORDER-LEFT-WIDTH:0px;BACKGROUND-IMAGE:none;BORDER-BOTTOM-WIDTH:0px;PADDING-TOP:0px;BORDER-RIGHT-WIDTH:0px;" height=255 alt="mstest test results trx output" src="http://sqlblog.com/blogs/jamie_thomson/cid_image014_png01CB4085_thumb_2A657325.png" width=991 border=0&gt;&lt;/FONT&gt;&lt;/A&gt;&lt;/P&gt;&lt;/BLOCKQUOTE&gt;&lt;FONT face=Consolas&gt;
&lt;HR&gt;
&lt;/FONT&gt;
&lt;P&gt;&lt;FONT face=Consolas&gt;I think its fair to say that this process is a little fiddly to say the least so I’m hoping that Microsoft come up with a better solution in the future, one that integrates better into the whole testing infrastructure. Meanwhile you can download the demo that I put together for this blog post from my &lt;/FONT&gt;&lt;A href="http://bit.ly/cYYIdq" target=_blank&gt;&lt;FONT face=Consolas&gt;SkyDrive&lt;/FONT&gt;&lt;/A&gt;&lt;FONT face=Consolas&gt;.&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT face=Consolas&gt;Hope that helps! Comments are welcome.&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;A href="http://twitter.com/jamiet" target=_blank&gt;&lt;FONT face=Consolas&gt;Jamiet&lt;/FONT&gt;&lt;/A&gt;&lt;/P&gt;&lt;SPAN class=Apple-style-span style="WORD-SPACING:0px;FONT:medium 'Times New Roman';TEXT-TRANSFORM:none;TEXT-INDENT:0px;WHITE-SPACE:normal;LETTER-SPACING:normal;BORDER-COLLAPSE:separate;orphans:2;widows:2;-webkit-border-horizontal-spacing:0px;-webkit-border-vertical-spacing:0px;-webkit-text-decorations-in-effect:none;-webkit-text-size-adjust:auto;-webkit-text-stroke-width:0px;"&gt;&lt;SPAN class=Apple-style-span style="FONT-SIZE:13px;FONT-FAMILY:Arial, Helvetica, sans-serif;"&gt;
&lt;P&gt;UPDATE: Atul Verma has written a 3-part blog series on how to write your database unit tests so if Jamie Laflen's whitepaper (linked to above) doesn't tickle your fancy try reading Atul's series instead:&lt;/P&gt;
&lt;UL&gt;
&lt;LI&gt;&lt;A class="" href="http://blogs.msdn.com/b/atverma/archive/2010/07/28/how-to-unit-test-sql-server-2008-database-using-visual-studio-2010.aspx"&gt;How to unit test SQL Server 2008 database using Visual Studio 2010&lt;/A&gt;&lt;/LI&gt;
&lt;LI&gt;&lt;A class="" href="http://blogs.msdn.com/b/atverma/archive/2010/08/22/how-to-unit-test-sql-server-2008-database-using-visual-studio-2010-part-2.aspx"&gt;How to unit test SQL Server 2008 database using Visual Studio 2010 – Part 2&lt;/A&gt;&lt;/LI&gt;
&lt;LI&gt;&lt;A class="" href="http://blogs.msdn.com/b/atverma/archive/2010/08/22/how-to-unit-test-sql-server-2008-database-using-visual-studio-2010-part-3.aspx"&gt;How to unit test SQL Server 2008 database using Visual Studio 2010 – Part 3&lt;/A&gt;&lt;/LI&gt;&lt;/UL&gt;&lt;/SPAN&gt;&lt;/SPAN&gt;</description></item><item><title>A strategy for managing security for different environments using the Database Development Tools in Visual Studio 2010</title><link>http://sqlblog.com/blogs/jamie_thomson/archive/2010/07/21/a-strategy-for-managing-security-for-different-environments-using-the-database-development-tools-in-visual-studio-2010.aspx</link><pubDate>Wed, 21 Jul 2010 20:59:00 GMT</pubDate><guid isPermaLink="false">21093a07-8b3d-42db-8cbf-3350fcbf5496:27217</guid><dc:creator>jamiet</dc:creator><description>&lt;h3&gt;Intro&lt;/h3&gt;
&lt;p&gt;Of late I have been getting down and dirty with the Database Development tools in Visual Studio 2010. You may know this feature set by one of the plethora of other names it has had over recent years such as:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;Visual Studio Team System for Database Professionals &lt;/li&gt;
&lt;li&gt;DBPro &lt;/li&gt;
&lt;li&gt;Datadude &lt;/li&gt;&lt;/ul&gt;
&lt;p&gt;For the rest of this post I’ll stick with the colloquial name that most people seem to recognise – datadude.&lt;/p&gt;
&lt;p&gt;Regardless of which moniker you prefer I’m hoping you recognise the feature set that I am referring to here which includes:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;Schema Compare &lt;/li&gt;
&lt;li&gt;Data Compare &lt;/li&gt;
&lt;li&gt;Offline database development &lt;/li&gt;
&lt;li&gt;T-SQL refactoring &lt;/li&gt;
&lt;li&gt;Database unit testing/Data generation &lt;/li&gt;
&lt;li&gt;MSBuild integration &lt;/li&gt;
&lt;li&gt;various other things… &lt;/li&gt;&lt;/ul&gt;
&lt;p&gt;I plan to write a detailed blog post in the coming weeks talking about my overall experiences with datadude but in the meantime I’m writing this blog post to focus on how I have chosen to manage security; by which I mean:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;logins &lt;/li&gt;
&lt;li&gt;users &lt;/li&gt;
&lt;li&gt;role membership &lt;/li&gt;
&lt;li&gt;user and role permissions &lt;/li&gt;&lt;/ul&gt;
&lt;hr&gt;

&lt;h3&gt;Security in Post-Deployment scripts&lt;/h3&gt;
&lt;p&gt;Datadude has built-in support for managing all of this stuff as we can see from this screenshot:&lt;/p&gt;
&lt;p&gt;&lt;a href="http://sqlblog.com/blogs/jamie_thomson/image_4F758EED.png"&gt;&lt;img style="border-width:0px;display:inline;" class="wlDisabledImage" title="users roles logins in datadude" border="0" alt="users roles logins in datadude" src="http://sqlblog.com/blogs/jamie_thomson/image_thumb_0D8EA99F.png" width="676" height="433"&gt;&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;Notice that we have created a &lt;strong&gt;user&lt;/strong&gt;, a &lt;strong&gt;login &lt;/strong&gt;for that user and a &lt;strong&gt;role &lt;/strong&gt;into which we later want to add the user. They exist as explicit objects within our project which means that datadude “knows” about them and that has a number of advantages including:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;Datadude can include these objects in a schema compare &lt;/li&gt;
&lt;li&gt;Datadude can do dependency tracking thus enabling offline development (e.g. If the login that is referenced in the CREATE USER statement does not exist then a design-time error will be raised) &lt;/li&gt;&lt;/ul&gt;
&lt;p&gt;That should be enough to justify using datadude to manage users and roles however I have come across a limitation that prohibits us from doing so; we do not deploy the same security model to each of our environments. The reasons for this are very familiar to you I’m sure, we have people that require different permissions on different environments (e.g. our developers will want to be able to issue DDL and UPDATE/INSERT/DELETE on our development environment but we definitely don’t want them to have the same on production).&lt;/p&gt;
&lt;p&gt;As far as I can discern datadude does not have a good solution for dealing with this situation. I have not found a way of conditionally deploying objects depending on which environment we are deploying to. Actually that is not altogether true, we could have a Visual Studio configuration for each environment and include/exclude objects as we choose but that doesn’t play well with the build and deploy model of msbuild which requires that you build each one of those configurations; each of our builds takes about 10 minutes which, when multiplied by the number of environments, results in a total build time that takes too long for our continuous integration (CI) usage.&lt;/p&gt;
&lt;p&gt;Hence we needed a better way to deploy our security model – we chose to use PostDeployment scripts. PostDeployment scripts do exactly what they say on the tin – they are scripts that get run after datadude has deployed the objects that it knows about. They get called (using SQLCMD syntax) from the &lt;font face="Courier New"&gt;Script.PostDeployment.sql &lt;/font&gt;file that exists in every datadude project:&lt;/p&gt;
&lt;p&gt;&lt;a href="http://sqlblog.com/blogs/jamie_thomson/cid_image002_png01CB274D_4ACF5E66.png"&gt;&lt;img style="border-width:0px;display:inline;" class="wlDisabledImage" title="post deployment script solution explorer" border="0" alt="post deployment script solution explorer" src="http://sqlblog.com/blogs/jamie_thomson/cid_image002_png01CB274D_thumb_6A120539.png" width="303" height="221"&gt;&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;My chosen approach is to have a script called &lt;font face="Courier New"&gt;SecurityAdditionsWrapper.sql&lt;/font&gt; that gets called from &lt;font face="Courier New"&gt;Script.PostDeployment.sql&lt;/font&gt;. &lt;font face="Courier New"&gt;SecurityAdditionsWrapper.sql &lt;/font&gt;checks a SQLCMD variable to determine which environment is being deployed to and then calls the appropriate &lt;font face="Courier New"&gt;SecurityAdditionsXXX.sql &lt;/font&gt;script that is responsible for deploying the security model for that environment (where XXX is the environment).&lt;/p&gt;
&lt;p&gt;I then have 3 subfolders that contain all the individual CREATE USER, role membership and permissions scripts that get called from &lt;font face="Courier New"&gt;SecurityAdditionsXXX.sql&lt;/font&gt; as and when required.&lt;/p&gt;
&lt;p&gt;The screenshot below shows the contents of &lt;font face="Courier New"&gt;Script.PostDeployment.sql &lt;/font&gt;&amp;amp; &lt;font face="Courier New"&gt;SecurityAdditionsWrapper.sql&lt;/font&gt; and also the files as they exist in Solution Explorer:&lt;/p&gt;
&lt;p&gt;&lt;a href="http://sqlblog.com/blogs/jamie_thomson/cid_image003_png01CB274F_7DBEEECD.png"&gt;&lt;img style="border-width:0px;display:inline;" class="wlDisabledImage" title="!cid_image003_png@01CB274F" border="0" alt="!cid_image003_png@01CB274F" src="http://sqlblog.com/blogs/jamie_thomson/cid_image003_png01CB274F_thumb_5969E47E.png" width="778" height="614"&gt;&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;Some things to notice:&lt;/p&gt;
&lt;ol&gt;
&lt;li&gt;I have a SQLCMD variable called $(DeployType) that will contain the value “DEV”, “UAT” or “PRD” &lt;/li&gt;
&lt;li&gt;All of my security scripts exist in Post-Deployment&amp;nbsp; -&amp;gt; SecurityAdditions &lt;/li&gt;
&lt;li&gt;In the commented-out code you can see that I was trying to be clever and dynamically build the name of the file to be executed using the $(DeployType) variable – the thinking being that if we later added a new environment type I wouldn’t need to change this script. Unfortunately even though this is valid SQLCMD syntax it does not work in datadude; I have reported that issue on Connect as a bug (with repro) at &lt;a href="https://connect.microsoft.com/VisualStudio/feedback/details/575383/datadude-valid-sqlcmd-syntax-throws-error-at-build-time"&gt;[Datadude] Valid SQLCMD syntax throws error at build time&lt;/a&gt;. &lt;/li&gt;&lt;/ol&gt;
&lt;p&gt;You may be wondering how we get a value into that $(DeployType) variable when using msbuild. Well, its pretty simple when you know how. First you need to include the variable in the sqlcmdvars file for your datadude project:&lt;/p&gt;
&lt;p&gt;&lt;a href="http://sqlblog.com/blogs/jamie_thomson/cid_image004_png01CB2755_5A129AA8.png"&gt;&lt;img style="border-width:0px;display:inline;" class="wlDisabledImage" title="!cid_image004_png@01CB2755" border="0" alt="!cid_image004_png@01CB2755" src="http://sqlblog.com/blogs/jamie_thomson/cid_image004_png01CB2755_thumb_0E46C3EF.png" width="430" height="272"&gt;&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;You then need to pass in the appropriate value to that variable at deploy-time. We are using &lt;a href="http://msdn.microsoft.com/en-us/library/dd193258.aspx"&gt;VSDBCMD.exe&lt;/a&gt; to run our deployments and the &lt;a href="http://msdn.microsoft.com/en-us/library/dd193283.aspx"&gt;syntax to pass in a value for a variable&lt;/a&gt; is /p:PropertyName=PropertyValue. We are calling VSDBCMD.exe from inside an msbuild script which therefore looks like this:&lt;/p&gt;
&lt;p&gt;&lt;font face="Courier New"&gt;&lt;font color="#0000ff"&gt;&amp;lt;Exec&lt;/font&gt; &lt;font color="#ff0000"&gt;Command&lt;/font&gt;&lt;font color="#9b00d3"&gt;="..\Tools\VSDBCMD\vsdbcmd.exe /Action:Deploy /ConnectionString:'Data Source=$(DatabaseServer);Integrated Security=True;Pooling=False' /DeployToDatabase:+ /ManifestFile:.\MyDB.deploymanifest &lt;strong&gt;/p:DeployType=&amp;amp;quot;$(DeployType)&amp;amp;quot&lt;/strong&gt;; "&lt;/font&gt; &lt;font color="#0000ff"&gt;/&amp;gt;&lt;/font&gt;&lt;/font&gt;&lt;/p&gt;
&lt;p&gt;$(DeployType) is of course also a property within our msbuild file, which I am drawing attention to in the bold section above.&lt;/p&gt;
&lt;h3&gt;Wrap-Up&lt;/h3&gt;
&lt;p&gt;In conclusion, I am not saying that this is the &lt;i&gt;correct&lt;/i&gt; way to deploy a SQL Server security model using datadude, it just happens to be the method that I have chosen. I would really like to how people have solved this using datadude so if you have any anecdotes to share please put them in the comments.&lt;/p&gt;
&lt;hr&gt;

&lt;h3&gt;One more thing…&lt;/h3&gt;
&lt;p&gt;Cranking all of those files out by hand is a laborious undertaking, especially if you have lots of users with lots of permissions. In our case we introduced datadude to be used with an existing system hence we already had all our security setup on existing servers but we had no good way of getting it into the structure that I explained above. Powershell and SQLCMD to the rescue!&lt;/p&gt;
&lt;p&gt;I have produced a series of scripts that interrogate a named instance and produce all of the files that I explain above. Namely:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;A file for each user which gets dropped into %SolutionRoot%\%ProjectName%\Scripts\Post-Deployment\Users\ &lt;/li&gt;
&lt;li&gt;A file for each principle that issues all the GRANT/DENY EXECUTE/SELECT/INSERT/UPDATE/DELETE for that principle, it gets dropped into %SolutionRoot%\%ProjectName%\Scripts\Post-Deployment\PermissionsSets\ &lt;/li&gt;
&lt;li&gt;A file that specifies all of the role memberships, for all database principles. &lt;/li&gt;&lt;/ul&gt;
&lt;p&gt;Creating the CREATE USER file and the file containing the permissions for each principle is&amp;nbsp;quite involved. For that we need some nested loops that loop over (a) all the databases for which you want to scripts users and (b) all the principles in each database. It then dumps the appropriate files into the appropriate folders and then you have the simple task of adding them to your project and calling them from your Post Deployment script.&lt;/p&gt;
&lt;p&gt;The files are stored in a zip folder on my SkyDrive at &lt;a title="http://cid-550f681dad532637.office.live.com/self.aspx/Public/BlogShare/20100721/GeneratePermissions.zip" href="http://cid-550f681dad532637.office.live.com/self.aspx/Public/BlogShare/20100721/GeneratePermissions.zip"&gt;http://cid-550f681dad532637.office.live.com/self.aspx/Public/BlogShare/20100721/GeneratePermissions.zip&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;To run the Powershell script simply unzip all the files into the root folder of your solution and issue:&lt;/p&gt;
&lt;blockquote&gt;
&lt;p&gt;&lt;font face="Courier New"&gt;&amp;gt;GeneratePermissions.ps1 -SQLInstance instanceName -Environment XXX&lt;/font&gt;&lt;/p&gt;&lt;/blockquote&gt;
&lt;p&gt;changing SQLInstance &amp;amp; XXX accordingly (the &lt;font face="Courier New"&gt;$Environment&lt;/font&gt; variable is simply a suffix that is added to the names of some of the generated files). The Powershell script contains more detailed notes within it in the comments section at the top.&lt;/p&gt;
&lt;p&gt;&lt;a href="http://sqlblog.com/blogs/jamie_thomson/image_0A78F952.png"&gt;&lt;img style="border-width:0px;display:inline;" class="wlDisabledImage" title="powershell script comments" border="0" alt="powershell script comments" src="http://sqlblog.com/blogs/jamie_thomson/image_thumb_62664A32.png" width="739" height="273"&gt;&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;Hope this helps!&lt;/p&gt;
&lt;p&gt;Disclaimer: I’m giving this away for free and I won’t be supporting it so use at your own peril (in other words, don’t come here complaining that it doesn’t work on your environment). On the other hand if you find a problem and are able to fix it – please let me know &lt;img class="wlEmoticon wlEmoticon-smile" alt="Smile" src="http://sqlblog.com/blogs/jamie_thomson/wlEmoticonsmile_19CC5B61.png"&gt;&lt;/p&gt;
&lt;p&gt;UPDATE: I did actually find some problems with the scripts and have now uploaded a new set. I'm confident that they'll work this time.&lt;/p&gt;
&lt;p&gt;UPDATE 2: I've updated the scripts again. They now create the SecurityAdditionsXXX.sql file as well as the individual CREATE USER &amp;amp; permissions files;&amp;nbsp;SecurityAdditionsXXX.sql contains all of the calls to the relevant scripts for environment XXX.&lt;/p&gt;
&lt;p&gt;SecurityAdditionsXXX.sql also issues all of the role membership statements as well. So just to clarify - you now no longer have a need to run the script that generates the role memberships - GeneratePermissions.ps1 takes care of everything.&lt;/p&gt;&lt;p&gt;UPDATE 3: Peter Schott has taken this, adapted it for hiw own needs, and sent it back to me so that I can share it here. His modified version of the scripts is at &lt;a href="http://cid-550f681dad532637.office.live.com/self.aspx/Public/BlogShare/20100721/GeneratePermissions%5E_PeterSchott.zip"&gt;http://cid-550f681dad532637.office.live.com/self.aspx/Public/BlogShare/20100721/GeneratePermissions%5E_PeterSchott.zip&lt;/a&gt;&amp;nbsp;and includes these changes (mainly to deal with roles):&lt;/p&gt;&lt;p&gt;1. Changed the Powershell script:&lt;br&gt;&amp;nbsp; * Added a section to handle role permissions. (really don't care for the way VS does it)&lt;br&gt;&amp;nbsp; * Tweaked the Database Principle section - for some reason, the variable in the PS script I extracted wasn't set properly so I just changed the names around&lt;br&gt;&amp;nbsp; * Added a bunch of lines of code to add to the Array. My Powershell's not too strong so wasn't sure about the best way to add new DBs/Projects to the DB Array. I ended up doing a bunch of sets. I know it's not ideal, but I just wanted to get it done one time.&lt;br&gt;&amp;nbsp; * Tweaked the section that creates the Users. If one of those logins doesn't exist, the grant permissions script would stop. Now I check to make sure that the login exists before the script runs.&amp;nbsp;I sometimes get empty (Login = [])&amp;nbsp; sections. No ideas on that yet. I fix or delete that file as appropriate.&lt;br&gt;&lt;br&gt;2. Added a "GetDatabaseRoleList.sql" file.&amp;nbsp; Gets the roles for the DB so we can run it through the Permissions file&lt;br&gt;&lt;br&gt;3. Permissions SQL file. I tweaked this with a query that UNIONs the object permissions with the Schema permissions. I didn't break it down further &lt;br&gt;like you did, but our permissions are so messed up right now that it doesn't matter much to me. (we have &lt;i&gt;far&lt;/i&gt; too many permissions granted to &lt;br&gt;individual users instead of roles because the prior DBA didn't understand the point of DB Roles for permissions and even then far too many permissions because we had a job that nightly granted all permissions on all objects to certain usernames :-P&amp;nbsp; )&lt;br&gt;&lt;/p&gt;&lt;p&gt;And one more change that needs to be made which Peter informed me of later: &lt;/p&gt;&lt;p&gt;Ended up changing the GeneratePermissions.ps1 file to change all of the Out-File &lt;br&gt;to "Out-File -width 500 ".&lt;br&gt;&lt;br&gt;After doing that, the permissions weren't truncated at 80 characters.&amp;nbsp; Also tweaked the Invoke-SQLCmd functions to use -MaxCharLength 500 so the output line would be long enough. That may have been overkill or there may be a better way to handle, but some of my permission lines were definitely longer than the allowed line lengths.&lt;/p&gt;
&lt;p&gt;&lt;a href="http://twitter.com/jamiet"&gt;@Jamiet&lt;/a&gt;&lt;/p&gt;P.S. I have used Powershell in the past but this is the first time I have really got into the inner workings of it and I’ve got to tell you – its just fantastic. The productivity you get is just incredible – if you don’t believe me have a look at the script herein and see how easy it is to generate a dataset from SQL Server and then loop over it inside your script. Its two lines of code - really fantastic stuff – I recommend any SQL Server pro go out and spend some time getting to know Powershell. </description></item></channel></rss>