<?xml version="1.0" encoding="UTF-8" ?>
<?xml-stylesheet type="text/xsl" href="http://sqlblogcasts.com/utility/FeedStylesheets/atom.xsl" media="screen"?><feed xmlns="http://www.w3.org/2005/Atom" xml:lang="en"><title type="html">Anthony Brown</title><subtitle type="html">various sql server stuff</subtitle><id>http://sqlblogcasts.com/blogs/antxxxx/atom.aspx</id><link rel="alternate" type="text/html" href="http://sqlblogcasts.com/blogs/antxxxx/default.aspx" /><link rel="self" type="application/atom+xml" href="http://sqlblogcasts.com/blogs/antxxxx/atom.aspx" /><generator uri="http://communityserver.org" version="3.1.20917.1142">Community Server</generator><updated>2006-11-24T14:47:00Z</updated><entry><title>Scripting replication with powershell</title><link rel="alternate" type="text/html" href="http://sqlblogcasts.com/blogs/antxxxx/archive/2011/04/04/scripting-replication-with-powershell.aspx" /><id>http://sqlblogcasts.com/blogs/antxxxx/archive/2011/04/04/scripting-replication-with-powershell.aspx</id><published>2011-04-04T19:46:00Z</published><updated>2011-04-04T19:46:00Z</updated><content type="html">&lt;p class="MsoNormal"&gt;One of the great things with powershell is the ability to
easily script out sql server objects. With a bit of work you can also use it to
script out replication objects, such as publications, articles and subscribers. This can be used as part of a disaster recovery plan so that you always have a script available to recreate replication. You can do all of this from management studio, but when you have lots of publications, this can take a long time &lt;/p&gt;

&lt;p class="MsoNormal"&gt;This article explains how to script transactional push scriptions. It is very easy to change the objects to script out other types of replication as well (eg merge, snapshot, pull) &lt;br /&gt;&lt;/p&gt;

&lt;p class="MsoNormal"&gt;First you need to start off with either by starting sqlps,
or by loading the appropriate sql server assemblies. How to do that is detailed
on Martin Bells blog at &lt;a href="http://sqlblogcasts.com/blogs/martinbell/archive/2009/09/06/Using-SQL-Server-in-Powershell-outside-of-SQLPS.aspx"&gt;http://sqlblogcasts.com/blogs/martinbell/archive/2009/09/06/Using-SQL-Server-in-Powershell-outside-of-SQLPS.aspx&lt;/a&gt;&lt;/p&gt;

&lt;p class="MsoNormal"&gt;&amp;nbsp;&lt;/p&gt;

&lt;p class="MsoNormal"&gt;The next thing you need to do is load the RMO assembly. This
is the assembly that encapsulates replication functionality for SQL Server&lt;/p&gt;

&lt;p class="MsoNormal"&gt;&amp;nbsp;&lt;/p&gt;

&lt;p style="font-style:italic;" class="MsoNormal"&gt;[System.Reflection.Assembly]::LoadWithPartialName(&amp;quot;Microsoft.SqlServer.Rmo&amp;quot;)
&lt;/p&gt;

&lt;p class="MsoNormal"&gt;&amp;nbsp;&lt;/p&gt;

&lt;p class="MsoNormal"&gt;Now you need to create a new replication server object and
connect to it. One thing to note is that even if your server or database is set to a case insensitive collation, most of these objects need the variables to be defined with the same case. So if you have a publication called SalesTables, it wont show up if you use the examples below and set the publication name to be salestables.&lt;/p&gt;&lt;p class="MsoNormal"&gt;&amp;nbsp;&lt;/p&gt;&lt;p class="MsoNormal"&gt;&amp;nbsp;&lt;/p&gt;

&lt;p style="font-style:italic;" class="MsoNormal"&gt;$servername=”NAME OF PUBLISHER SERVER”&lt;/p&gt;

&lt;p style="font-style:italic;" class="MsoNormal"&gt;$repserver = New-Object &amp;quot;Microsoft.SqlServer.Replication.ReplicationServer&amp;quot;&lt;/p&gt;

&lt;p style="font-style:italic;" class="MsoNormal"&gt;$srv = New-Object
&amp;quot;Microsoft.SqlServer.Management.Common.ServerConnection&amp;quot; $servername&lt;/p&gt;

&lt;p style="font-style:italic;" class="MsoNormal"&gt;$srv.connect()&lt;/p&gt;

&lt;p style="font-style:italic;" class="MsoNormal"&gt;$repserver.ConnectionContext = $srv&lt;/p&gt;

&lt;p class="MsoNormal"&gt;&amp;nbsp;&lt;/p&gt;&lt;p class="MsoNormal"&gt;So now we have a $repserver which represents a replication object at a server level. But we are interested in scripting replication, which must
be done at a database level, so we create a new object to be the database 

&lt;/p&gt;&lt;p class="MsoNormal"&gt;&amp;nbsp;&lt;/p&gt;

&lt;p style="font-style:italic;" class="MsoNormal"&gt;$databasename=”DATABASE PUBLISHED FOR REPLICATION”&lt;/p&gt;

&lt;p style="font-style:italic;" class="MsoNormal"&gt;$repdb = $repserver.ReplicationDatabases[$databasename]&lt;/p&gt;

&lt;p class="MsoNormal"&gt;&amp;nbsp;&amp;nbsp;

&lt;/p&gt;&lt;p class="MsoNormal"&gt;From this object, we can then list out the transactional publications using&lt;/p&gt;

&lt;p class="MsoNormal"&gt;&amp;nbsp;&lt;/p&gt;

&lt;p style="font-style:italic;" class="MsoNormal"&gt;$repdb.transpublications&lt;/p&gt;

&lt;p class="MsoNormal"&gt;&amp;nbsp;&lt;/p&gt;

&lt;p class="MsoNormal"&gt;If you want to get an individual publication, you can use
this&lt;/p&gt;

&lt;p class="MsoNormal"&gt;&amp;nbsp;&lt;/p&gt;

&lt;p style="font-style:italic;" class="MsoNormal"&gt;$publication_name = “PUBLICATION NAME”&lt;/p&gt;

&lt;p style="font-style:italic;" class="MsoNormal"&gt;$publication_object=$repdb.transpublications[$publication_name]&lt;/p&gt;

&lt;p class="MsoNormal"&gt;&amp;nbsp;&lt;/p&gt;

&lt;p class="MsoNormal"&gt;From this $publication_object we can then see articles, by
looking at&lt;/p&gt;

&lt;p class="MsoNormal"&gt;&amp;nbsp;&lt;/p&gt;

&lt;p style="font-style:italic;" class="MsoNormal"&gt;$publication_object.TransArticles&lt;/p&gt;

&lt;p class="MsoNormal"&gt;&amp;nbsp;&lt;/p&gt;

&lt;p class="MsoNormal"&gt;And subscriptions&lt;/p&gt;

&lt;p class="MsoNormal"&gt;&amp;nbsp;&lt;/p&gt;

&lt;p style="font-style:italic;" class="MsoNormal"&gt;$publication_object.TransSubscriptions&lt;/p&gt;

&lt;p class="MsoNormal"&gt;&amp;nbsp;&lt;/p&gt;

&lt;p class="MsoNormal"&gt;So now we have the 3 things that we would want to script for
replication, the publication (in $publication_object), a collection of articles
(in $publication_object.TransArticles) and a collection of subscriptions (in $publication_object.TransSubscriptions)&lt;/p&gt;

&lt;p class="MsoNormal"&gt;We can set various scripting options using the ScriptOptions
enumeration. These vary slightly between different versions of sql server, but
you can see the values for all versions at &lt;a href="http://msdn.microsoft.com/en-us/library/microsoft.sqlserver.replication.scriptoptions.aspx"&gt;http://msdn.microsoft.com/en-us/library/microsoft.sqlserver.replication.scriptoptions.aspx&lt;/a&gt;&lt;/p&gt;

&lt;p class="MsoNormal"&gt;&amp;nbsp;&lt;/p&gt;

&lt;p class="MsoNormal"&gt;To include which options you want, you just need to create a
variable like&lt;/p&gt;

&lt;p class="MsoNormal"&gt;&amp;nbsp;&lt;/p&gt;

&lt;p style="font-style:italic;" class="MsoNormal"&gt;$script_val =
[Microsoft.SqlServer.Replication.ScriptOptions]::Creation -bxor&lt;/p&gt;

&lt;p style="font-style:italic;" class="MsoNormal"&gt;&lt;span style="mso-tab-count:2;"&gt;&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;/span&gt;[Microsoft.SqlServer.Replication.ScriptOptions]::IncludeGo&lt;/p&gt;

&lt;p class="MsoNormal"&gt;&amp;nbsp;&lt;/p&gt;

&lt;p class="MsoNormal"&gt;So this option will include creation and a go seperator. To
include more options, you just need to separate them using a -bxor statement,&lt;/p&gt;

&lt;p class="MsoNormal"&gt;&amp;nbsp;&lt;/p&gt;

&lt;p class="MsoNormal"&gt;Finally we can now script our replication objects using a
simple&lt;/p&gt;

&lt;p class="MsoNormal"&gt;&amp;nbsp;&lt;/p&gt;

&lt;p style="font-style:italic;" class="MsoNormal"&gt;$publication_object.Script($script_val)&lt;/p&gt;

&lt;p style="font-style:italic;" class="MsoNormal"&gt;&amp;nbsp;&lt;/p&gt;

&lt;p style="font-style:italic;" class="MsoNormal"&gt;Foreach ($article in $publication_object.TransArticles) {&lt;/p&gt;

&lt;p style="font-style:italic;" class="MsoNormal"&gt;&lt;span style="mso-tab-count:1;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;$article.Script($script_val)&lt;/p&gt;

&lt;p style="font-style:italic;" class="MsoNormal"&gt;}&lt;/p&gt;

&lt;p style="font-style:italic;" class="MsoNormal"&gt;&amp;nbsp;&lt;/p&gt;

&lt;p style="font-style:italic;" class="MsoNormal"&gt;Foreach ($subscription in $publication_object.TransSubscriptions)
{&lt;/p&gt;

&lt;p style="font-style:italic;" class="MsoNormal"&gt;&lt;span style="mso-tab-count:1;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;$subscription.Script($script_val)&lt;/p&gt;

&lt;p style="font-style:italic;" class="MsoNormal"&gt;}&lt;/p&gt;

&lt;p class="MsoNormal"&gt;&amp;nbsp;&lt;/p&gt;&lt;p class="MsoNormal"&gt;One thing to note is that if you have a seperate publisher and distributor, then some of the job properties (such as profiles and schedules) may not be scripted correctly. This is due to problems with RMO and not this technique. You get the same issue if you script replication from management studio. &lt;br /&gt;&lt;/p&gt;

&lt;p class="MsoNormal"&gt;You now have the basis for creating a script which can be
scheduled to run and automatically create a script of all your replication
enviroment. You can customise this as much as you like - for instance to make the output re-runnable, or just more human readable. &lt;/p&gt;

&lt;p class="MsoNormal"&gt;&amp;nbsp;&lt;/p&gt;

&lt;p class="MsoNormal"&gt;&amp;nbsp;&lt;/p&gt;

&lt;p class="MsoNormal"&gt;&amp;nbsp;&lt;/p&gt;

&lt;img src="http://sqlblogcasts.com/aggbug.aspx?PostID=15541" width="1" height="1"&gt;</content><author><name>antxxxx</name><uri>http://sqlblogcasts.com/members/antxxxx.aspx</uri></author></entry><entry><title>Leeds user group presentation on replication</title><link rel="alternate" type="text/html" href="http://sqlblogcasts.com/blogs/antxxxx/archive/2011/03/04/leeds-user-group-presentation-on-replication.aspx" /><id>http://sqlblogcasts.com/blogs/antxxxx/archive/2011/03/04/leeds-user-group-presentation-on-replication.aspx</id><published>2011-03-04T09:40:00Z</published><updated>2011-03-04T09:40:00Z</updated><content type="html">&lt;p&gt;Last night I gave a presentation on replication at the Leeds sql server user group. You can find the slides and scripts I used from the presentation &lt;a href="http://sqlblogcasts.com/blogs/antxxxx/replication.zip"&gt;here&lt;/a&gt;&lt;br /&gt;&lt;/p&gt;&lt;img src="http://sqlblogcasts.com/aggbug.aspx?PostID=15459" width="1" height="1"&gt;</content><author><name>antxxxx</name><uri>http://sqlblogcasts.com/members/antxxxx.aspx</uri></author><category term="replication" scheme="http://sqlblogcasts.com/blogs/antxxxx/archive/tags/replication/default.aspx" /></entry><entry><title>SQLBits presentation - database projects in visual studio 2010</title><link rel="alternate" type="text/html" href="http://sqlblogcasts.com/blogs/antxxxx/archive/2010/10/04/sqlbits-presentation-database-projects-in-visual-studio-2010.aspx" /><id>http://sqlblogcasts.com/blogs/antxxxx/archive/2010/10/04/sqlbits-presentation-database-projects-in-visual-studio-2010.aspx</id><published>2010-10-04T13:02:00Z</published><updated>2010-10-04T13:02:00Z</updated><content type="html">&lt;p&gt;This weekend saw sqlbits 7 in York. This was a great conference and i learned a lot and met some really great people. A huge thanks to all the organisers and sponsors of the event&lt;/p&gt;

&lt;p&gt;You can find the slides from my presentation on database projects &lt;a href="http://sqlblogcasts.com/blogs/antxxxx/Database_projects.zip"&gt;here.&lt;/a&gt;&lt;/p&gt;&lt;img src="http://sqlblogcasts.com/aggbug.aspx?PostID=14878" width="1" height="1"&gt;</content><author><name>antxxxx</name><uri>http://sqlblogcasts.com/members/antxxxx.aspx</uri></author><category term="database projects" scheme="http://sqlblogcasts.com/blogs/antxxxx/archive/tags/database+projects/default.aspx" /><category term="visual studio" scheme="http://sqlblogcasts.com/blogs/antxxxx/archive/tags/visual+studio/default.aspx" /><category term="sqlbits" scheme="http://sqlblogcasts.com/blogs/antxxxx/archive/tags/sqlbits/default.aspx" /></entry><entry><title>Unpack decimal for SSIS 2008</title><link rel="alternate" type="text/html" href="http://sqlblogcasts.com/blogs/antxxxx/archive/2010/09/17/unpack-decimal-for-ssis-2008.aspx" /><link rel="enclosure" type="application/x-zip-compressed" length="198567" href="http://sqlblogcasts.com/blogs/antxxxx/attachment/14862.ashx" /><id>http://sqlblogcasts.com/blogs/antxxxx/archive/2010/09/17/unpack-decimal-for-ssis-2008.aspx</id><published>2010-09-17T15:18:00Z</published><updated>2010-09-17T15:18:00Z</updated><content type="html">&lt;p&gt;
Microsoft released a component for SSIS 2005 to convert a packed decimal (comp 3 format) into a decimal so you can use it in a data flow. Details of it are at &lt;a href="http://www.microsoft.com/downloads/en/details.aspx?familyid=0e4bba52-cc52-4d89-8590-cda297ff7fbd&amp;amp;displaylang=en"&gt;http://www.microsoft.com/downloads/en/details.aspx?familyid=0e4bba52-cc52-4d89-8590-cda297ff7fbd&amp;amp;displaylang=en&lt;/a&gt;
&lt;/p&gt;&lt;p&gt;
Unfortunately , this doesnt work in SSIS 2008, but with a few simple changes to use SSIS 2008 types rather than 2005 ones it does.
&lt;/p&gt;&lt;p&gt;
&lt;a href="http://sqlblogcasts.com/blogs/antxxxx/UnpackDecimal.zip"&gt;Here&lt;/a&gt; is the source code with these modifications and compiled dlls (in debug and release configurations)
&lt;/p&gt;

&lt;img src="http://sqlblogcasts.com/aggbug.aspx?PostID=14862" width="1" height="1"&gt;</content><author><name>antxxxx</name><uri>http://sqlblogcasts.com/members/antxxxx.aspx</uri></author><category term="ssis unpackdecimal" scheme="http://sqlblogcasts.com/blogs/antxxxx/archive/tags/ssis+unpackdecimal/default.aspx" /></entry><entry><title>formatting xml files in visual studio</title><link rel="alternate" type="text/html" href="http://sqlblogcasts.com/blogs/antxxxx/archive/2010/02/23/formatting-xml-files-in-visual-studio.aspx" /><id>http://sqlblogcasts.com/blogs/antxxxx/archive/2010/02/23/formatting-xml-files-in-visual-studio.aspx</id><published>2010-02-23T10:02:00Z</published><updated>2010-02-23T10:02:00Z</updated><content type="html">&lt;p&gt;This is not strictly a sql post, but it is to do with xml which is used in sql server.&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;p&gt;xml files do not need to have any formatting in them. That means that when viewing an xml file produced by an application, all the data can be one line. Although this is valid xml and can be processed by sql server or ssis, sometimes it is useful to view the data in a human readable format.&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;p&gt;You can use an xml editor for this, or you can open the file in visual studio and use the shortcut ctrl+k, ctrl+d which formats it all nicely with indents to make it easier to read.&lt;/p&gt;&lt;img src="http://sqlblogcasts.com/aggbug.aspx?PostID=13126" width="1" height="1"&gt;</content><author><name>antxxxx</name><uri>http://sqlblogcasts.com/members/antxxxx.aspx</uri></author><category term="visual studio" scheme="http://sqlblogcasts.com/blogs/antxxxx/archive/tags/visual+studio/default.aspx" /><category term="xml" scheme="http://sqlblogcasts.com/blogs/antxxxx/archive/tags/xml/default.aspx" /></entry><entry><title>Leeds user group Service Broker presentation</title><link rel="alternate" type="text/html" href="http://sqlblogcasts.com/blogs/antxxxx/archive/2009/12/11/leeds-user-group-service-broker-presentation.aspx" /><link rel="enclosure" type="application/x-zip-compressed" length="46324" href="http://sqlblogcasts.com/blogs/antxxxx/attachment/12715.ashx" /><id>http://sqlblogcasts.com/blogs/antxxxx/archive/2009/12/11/leeds-user-group-service-broker-presentation.aspx</id><published>2009-12-11T11:09:00Z</published><updated>2009-12-11T11:09:00Z</updated><content type="html">Thanks for all who came to see my service broker presentation last night. It was my first time presenting to a user group and i really enjoyed it&lt;/p&gt;&lt;p&gt;&lt;/p&gt;&lt;p&gt;

As i promised, the presentation and demos from it should be in the attached zip file &lt;a href="http://sqlblogcasts.com/blogs/antxxxx/leeds_user_group_10_dec.zip"&gt;here&lt;/a&gt;



&lt;img src="http://sqlblogcasts.com/aggbug.aspx?PostID=12715" width="1" height="1"&gt;</content><author><name>antxxxx</name><uri>http://sqlblogcasts.com/members/antxxxx.aspx</uri></author><category term="service broker" scheme="http://sqlblogcasts.com/blogs/antxxxx/archive/tags/service+broker/default.aspx" /></entry><entry><title>How to find out what procedure is doing a data modification</title><link rel="alternate" type="text/html" href="http://sqlblogcasts.com/blogs/antxxxx/archive/2009/10/13/how-to-find-out-what-procedure-is-doing-an-insert.aspx" /><id>http://sqlblogcasts.com/blogs/antxxxx/archive/2009/10/13/how-to-find-out-what-procedure-is-doing-an-insert.aspx</id><published>2009-10-13T16:30:00Z</published><updated>2009-10-13T16:30:00Z</updated><content type="html">&lt;p&gt;Here is a little trick to find out what stored procedures or statements are causing data modifications. You could use a trace for this, and in most situations this will be preferable as you can filter what is captured, and get more information&amp;nbsp;This is another method that uses a trigger and dbcc inputbuffer&lt;/p&gt;
&lt;p&gt;First create a table to store the results&lt;/p&gt;&lt;font color="#0000ff" size="2"&gt;&lt;font color="#0000ff" size="2"&gt;
&lt;p&gt;create&lt;/font&gt;&lt;/font&gt;&lt;font size="2"&gt; &lt;/font&gt;&lt;font color="#0000ff" size="2"&gt;&lt;font color="#0000ff" size="2"&gt;table&lt;/font&gt;&lt;/font&gt;&lt;font size="2"&gt; dbcc_monitor&lt;/font&gt;&lt;font color="#0000ff" size="2"&gt;&lt;font color="#0000ff" size="2"&gt; &lt;/font&gt;&lt;/font&gt;&lt;font color="#808080" size="2"&gt;&lt;font color="#808080" size="2"&gt;(&lt;/p&gt;&lt;/font&gt;&lt;/font&gt;&lt;font size="2"&gt;
&lt;p&gt;EventType &lt;/font&gt;&lt;font color="#0000ff" size="2"&gt;&lt;font color="#0000ff" size="2"&gt;nvarchar&lt;/font&gt;&lt;/font&gt;&lt;font color="#808080" size="2"&gt;&lt;font color="#808080" size="2"&gt;(&lt;/font&gt;&lt;/font&gt;&lt;font size="2"&gt;60&lt;/font&gt;&lt;font color="#808080" size="2"&gt;&lt;font color="#808080" size="2"&gt;),&lt;/p&gt;&lt;/font&gt;&lt;/font&gt;&lt;font color="#008000" size="2"&gt;&lt;font color="#008000" size="2"&gt;
&lt;p&gt;Parameters&lt;/font&gt;&lt;/font&gt;&lt;font size="2"&gt; &lt;/font&gt;&lt;font color="#0000ff" size="2"&gt;&lt;font color="#0000ff" size="2"&gt;int&lt;/font&gt;&lt;/font&gt;&lt;font color="#808080" size="2"&gt;&lt;font color="#808080" size="2"&gt;,&lt;/p&gt;&lt;/font&gt;&lt;/font&gt;&lt;font size="2"&gt;EventInfo &lt;/font&gt;&lt;font color="#0000ff" size="2"&gt;&lt;font color="#0000ff" size="2"&gt;nvarchar&lt;/font&gt;&lt;/font&gt;&lt;font color="#808080" size="2"&gt;&lt;font color="#808080" size="2"&gt;(&lt;/font&gt;&lt;/font&gt;&lt;font size="2"&gt;510&lt;/font&gt;&lt;font color="#808080" size="2"&gt;&lt;font color="#808080" size="2"&gt;)&lt;/font&gt;&lt;/font&gt;&lt;/font&gt;&lt;font color="#808080" size="2"&gt;&lt;font color="#808080" size="2"&gt; )&lt;/font&gt;&lt;/font&gt;&lt;font size="2"&gt; &lt;/font&gt;&lt;/font&gt;&lt;/font&gt;&lt;font size="2"&gt;
&lt;p&gt;&lt;/font&gt;&lt;br /&gt;&amp;nbsp;&lt;/p&gt;
&lt;p&gt;You then create a trigger on the table you want to monitor that runs dbcc inputbuffer for the current @@spid&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;&lt;font color="#0000ff" size="2"&gt;&lt;font color="#0000ff" size="2"&gt;
&lt;p&gt;create&lt;/font&gt;&lt;/font&gt;&lt;font size="2"&gt; &lt;/font&gt;&lt;font color="#0000ff" size="2"&gt;&lt;font color="#0000ff" size="2"&gt;trigger&lt;/font&gt;&lt;/font&gt;&lt;font size="2"&gt; some_table_trigger &lt;/p&gt;&lt;/font&gt;&lt;font color="#0000ff" size="2"&gt;&lt;font color="#0000ff" size="2"&gt;on&lt;/font&gt;&lt;/font&gt;&lt;font size="2"&gt; some_table &lt;/font&gt;&lt;font color="#0000ff" size="2"&gt;&lt;font color="#0000ff" size="2"&gt;for&lt;/font&gt;&lt;/font&gt;&lt;font size="2"&gt; &lt;/font&gt;&lt;font color="#0000ff" size="2"&gt;&lt;font color="#0000ff" size="2"&gt;insert&lt;/font&gt;&lt;/font&gt;&lt;font color="#808080" size="2"&gt;&lt;font color="#808080" size="2"&gt;,&lt;/font&gt;&lt;/font&gt;&lt;font size="2"&gt; &lt;/font&gt;&lt;font color="#0000ff" size="2"&gt;&lt;font color="#0000ff" size="2"&gt;update&lt;/font&gt;&lt;/font&gt;&lt;font color="#808080" size="2"&gt;&lt;font color="#808080" size="2"&gt;,&lt;/font&gt;&lt;/font&gt;&lt;font size="2"&gt; &lt;/font&gt;&lt;font color="#0000ff" size="2"&gt;&lt;font color="#0000ff" size="2"&gt;delete&lt;/font&gt;&lt;/font&gt;&lt;/font&gt;&lt;/font&gt;&lt;font color="#0000ff" size="2"&gt;&lt;font color="#0000ff" size="2"&gt; 
&lt;p&gt;as&lt;/p&gt;
&lt;p&gt;declare&lt;/font&gt;&lt;/font&gt;&lt;font size="2"&gt; @sql &lt;/font&gt;&lt;font color="#0000ff" size="2"&gt;&lt;font color="#0000ff" size="2"&gt;varchar&lt;/font&gt;&lt;/font&gt;&lt;font color="#808080" size="2"&gt;&lt;font color="#808080" size="2"&gt;(&lt;/font&gt;&lt;/font&gt;&lt;font size="2"&gt;100&lt;/font&gt;&lt;font color="#808080" size="2"&gt;&lt;font color="#808080" size="2"&gt;)&lt;/p&gt;&lt;/font&gt;&lt;/font&gt;&lt;font color="#0000ff" size="2"&gt;&lt;font color="#0000ff" size="2"&gt;set&lt;/font&gt;&lt;/font&gt;&lt;font size="2"&gt; &lt;/font&gt;&lt;font color="#0000ff" size="2"&gt;&lt;font color="#0000ff" size="2"&gt;nocount&lt;/font&gt;&lt;/font&gt;&lt;font size="2"&gt; &lt;/font&gt;&lt;font color="#0000ff" size="2"&gt;&lt;font color="#0000ff" size="2"&gt;on&lt;/font&gt;&lt;/font&gt;&lt;/font&gt;&lt;/font&gt;&lt;font color="#0000ff" size="2"&gt;&lt;font color="#0000ff" size="2"&gt; 
&lt;p&gt;select&lt;/font&gt;&lt;/font&gt;&lt;font size="2"&gt; @sql &lt;/font&gt;&lt;font color="#808080" size="2"&gt;&lt;font color="#808080" size="2"&gt;=&lt;/font&gt;&lt;/font&gt;&lt;font size="2"&gt; &lt;/font&gt;&lt;font color="#ff0000" size="2"&gt;&lt;font color="#ff0000" size="2"&gt;&amp;#39;dbcc inputbuffer(&amp;#39;&lt;/font&gt;&lt;/font&gt;&lt;font size="2"&gt; &lt;/font&gt;&lt;font color="#808080" size="2"&gt;&lt;font color="#808080" size="2"&gt;+&lt;/font&gt;&lt;/font&gt;&lt;font size="2"&gt; &lt;/font&gt;&lt;font color="#ff00ff" size="2"&gt;&lt;font color="#ff00ff" size="2"&gt;convert&lt;/font&gt;&lt;/font&gt;&lt;font color="#808080" size="2"&gt;&lt;font color="#808080" size="2"&gt;(&lt;/font&gt;&lt;/font&gt;&lt;font color="#0000ff" size="2"&gt;&lt;font color="#0000ff" size="2"&gt;varchar&lt;/font&gt;&lt;/font&gt;&lt;font color="#808080" size="2"&gt;&lt;font color="#808080" size="2"&gt;,&lt;/font&gt;&lt;/font&gt;&lt;font size="2"&gt; &lt;/font&gt;&lt;font color="#ff00ff" size="2"&gt;&lt;font color="#ff00ff" size="2"&gt;@@spid&lt;/font&gt;&lt;/font&gt;&lt;font color="#808080" size="2"&gt;&lt;font color="#808080" size="2"&gt;)&lt;/font&gt;&lt;/font&gt;&lt;font size="2"&gt; &lt;/font&gt;&lt;font color="#808080" size="2"&gt;&lt;font color="#808080" size="2"&gt;+&lt;/font&gt;&lt;/font&gt;&lt;font size="2"&gt; &lt;/font&gt;&lt;font color="#ff0000" size="2"&gt;&lt;font color="#ff0000" size="2"&gt;&amp;#39;)&amp;#39;&lt;/p&gt;&lt;/font&gt;&lt;/font&gt;&lt;font color="#0000ff" size="2"&gt;&lt;font color="#0000ff" size="2"&gt;
&lt;p&gt;insert&lt;/font&gt;&lt;/font&gt;&lt;font size="2"&gt; &lt;/font&gt;&lt;font color="#0000ff" size="2"&gt;&lt;font color="#0000ff" size="2"&gt;into&lt;/font&gt;&lt;/font&gt;&lt;font size="2"&gt; dbcc_monitor &lt;/font&gt;&lt;font color="#0000ff" size="2"&gt;&lt;font color="#0000ff" size="2"&gt;exec&lt;/font&gt;&lt;/font&gt;&lt;font color="#808080" size="2"&gt;&lt;font color="#808080" size="2"&gt;(&lt;/font&gt;&lt;/font&gt;&lt;font size="2"&gt;@sql&lt;/font&gt;&lt;font color="#808080" size="2"&gt;&lt;font color="#808080" size="2"&gt;)&lt;/font&gt;&lt;/font&gt;&lt;font size="2"&gt; &lt;/font&gt;&lt;/p&gt;
&lt;p&gt;&lt;font size="2"&gt;&lt;/font&gt;&amp;nbsp;&lt;/p&gt;
&lt;p&gt;&lt;font size="2"&gt;Then whenever an insert, update or delete happens on the table, the results of dbcc inputbuffer are logged to the dbcc_monitor table. This should contain the name of the stored procedure that caused the data modification. You could also capture the data from the inserted and deleted tables in the trigger to find out what the modifications were.&lt;/font&gt;&lt;/p&gt;
&lt;p&gt;&lt;font size="2"&gt;A word of warning though. There will be a performance hit with this as it logs all data modifications, so dont do it on a heavily modified table&lt;/p&gt;&lt;/font&gt;&lt;img src="http://sqlblogcasts.com/aggbug.aspx?PostID=12414" width="1" height="1"&gt;</content><author><name>antxxxx</name><uri>http://sqlblogcasts.com/members/antxxxx.aspx</uri></author></entry><entry><title>Upgrading database projects to GDR release</title><link rel="alternate" type="text/html" href="http://sqlblogcasts.com/blogs/antxxxx/archive/2009/07/15/upgrading-database-projects-to-gdr-release.aspx" /><link rel="enclosure" type="application/x-zip-compressed" length="4225" href="http://sqlblogcasts.com/blogs/antxxxx/attachment/11987.ashx" /><id>http://sqlblogcasts.com/blogs/antxxxx/archive/2009/07/15/upgrading-database-projects-to-gdr-release.aspx</id><published>2009-07-15T09:42:00Z</published><updated>2009-07-15T09:42:00Z</updated><content type="html">&lt;p&gt;
Database projects are available in visual studio database edition (which is covered under the same licence as visual studio developer edition). They allow you to store all the objects that make up a database in a project and easily deploy them to a server. The objects are stored as sql scripts that create the object. When you deploy it compares the object definitions to the target database and creates a difference sql script that makes the target server the same as the project.
&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;
With th GDR release for visual studio 2008 version, there are many improvements, including support for sql 2008, and the seperation of build and deploy steps. Gert Drapers has an excellent article at &lt;a href="http://blogs.msdn.com/gertd/archive/2009/06/05/declarative-database-development.aspx"&gt; http://blogs.msdn.com/gertd/archive/2009/06/05/declarative-database-development.aspx &lt;/a&gt; explaining how database projects work in the GDR release
&lt;/p&gt;&lt;p&gt;
If you have an existing database project and you install the GDR release, you need to upgrade your projects to the new version.
&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;
There are 3 methods I will discuss here on how to do this.
&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;
The first method is to first deploy your old database project to a blank database, and then import it into the GDR version. This is probably the cleanest method. However, it does mean that the location of your scripts (ie object definitions) will change, which if you have your project under source control may cause problems. It is also very time consuming, so it may not be an option if you have many projects.
&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;
The second method is to just open the database projects in the GDR version and go through the upgrade wizard. This just changes the dbproj file, and adds some extra files, but leaves all the scripts in the same location. If you have your project under source control, this is a better method for that reason. However, it is time consuming and if you have many projects, it can take a long time.
&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;
There is a bug in the upgrade wizard. The database.sqlpermissions file gets added to the dbproj file like this
&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;
&amp;lt;PropertiesFile Include=&amp;quot;Properties\Database.sqlpermissions&amp;quot; /&amp;gt;
&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;
when it should get added as 
&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;
&amp;lt;Build Include=&amp;quot;Properties\Database.sqlpermissions&amp;quot;&amp;gt;
&lt;/p&gt;&lt;p&gt;
     &amp;lt;ModelBuilderType&amp;gt;Permissions&amp;lt;/ModelBuilderType&amp;gt;
&lt;/p&gt;&lt;p&gt;
   &amp;lt;/Build&amp;gt;
&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;
So you will manually need to edit the dbproj file after the upgrade.
&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;
It also does not move the contents of the permissions.sql file into the database.sqlpermissions file, so this is something you need to do manually.
&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;
The third method is to automate the 2nd method using powershell. I have recently used this to upgrade hundreds of projects in a few hours. The main script is called upgrade-projects.ps1
&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;
The script finds all dbproj file, and then callls 
&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;
C:\Program Files\Microsoft Visual Studio 9.0\Common7\IDE\devenv.exe $dbprojname /upgrade
&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;
on them which does the upgrade without the need for intervention.
&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;
It also fixes the database.sqlpermissions file in the dbproj file automatically,  and changes the model collation to be uk case-insensitive (as all my database projects have this collation)
&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;
It also calls another script - upgrade_permissions.ps1 which tries to upgrade the permissions.sql file into database.sqlpermissions format. This script works for basic grant statements on tables and stored procedures (eg grant select, grant delete, grant execute etc) and for most grants on xml schema collections. There may be problems with it if you try to do it with other objects.
&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;
It uses the get-tfs cmdlet to try and check out and add files to tfs. This is available from here - &lt;a href="http://blogs.msdn.com/jmanning/archive/2006/09/28/776141.aspx"&gt; http://blogs.msdn.com/jmanning/archive/2006/09/28/776141.aspx&lt;/a&gt;. If you use another source control provider you will need to change these parts.
&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;
Finally the script calls another script called build-all.ps1 which tries to build all the projects to check for any errors. 
&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;
All 3 scripts are in the file &lt;a href="http://sqlblogcasts.com/blogs/antxxxx/upgrade_database_projects.zip"&gt;here&lt;/a&gt;. I hope this helps anybody that is upgrading database projects
&lt;/p&gt;&lt;img src="http://sqlblogcasts.com/aggbug.aspx?PostID=11987" width="1" height="1"&gt;</content><author><name>antxxxx</name><uri>http://sqlblogcasts.com/members/antxxxx.aspx</uri></author><category term="GDR" scheme="http://sqlblogcasts.com/blogs/antxxxx/archive/tags/GDR/default.aspx" /><category term="database projects" scheme="http://sqlblogcasts.com/blogs/antxxxx/archive/tags/database+projects/default.aspx" /><category term="visual studio" scheme="http://sqlblogcasts.com/blogs/antxxxx/archive/tags/visual+studio/default.aspx" /></entry><entry><title>script to find out what a spid is doing</title><link rel="alternate" type="text/html" href="http://sqlblogcasts.com/blogs/antxxxx/archive/2006/11/30/script-to-find-out-what-a-spid-is-doing.aspx" /><link rel="enclosure" type="application/zip" length="952" href="http://sqlblogcasts.com/blogs/antxxxx/attachment/1449.ashx" /><id>http://sqlblogcasts.com/blogs/antxxxx/archive/2006/11/30/script-to-find-out-what-a-spid-is-doing.aspx</id><published>2006-11-30T13:43:00Z</published><updated>2006-11-30T13:43:00Z</updated><content type="html">&lt;p&gt;If a server is behaving badly, or there is a long running process and you want to find out what it is actually doing, you might find these scripts useful. They can be used to show the query or stored procedure that is executing and the text of the statement that is executing within that procedure.&lt;/p&gt;&lt;p&gt;This gives a more complete picture of what is happening than by just using dbcc inputbuffer which&amp;nbsp; just displays the last statement sent by the client to sql server.&lt;/p&gt;&lt;p&gt;For example say have a stored procedure, uspProcedure1, which calls another procedure, uspProcedure2, inside it, and uspProcedure2 takes a long time to complete. If a client executes uspProcedure1 and you run dbcc inputbuffer on that spid, it will just show uspProcedure1 executing, even though the statement currently executing is in uspProcedure2&lt;br /&gt;&lt;/p&gt;&lt;p&gt;Both scripts create a procedure which does the same thing - sp_dba_showline is for sql 2000 with sp3 or greater installed and sp_dba_showline2005 is for sql 2005. The reason for the difference is the sql 2000 version uses fn_get_sql (a function introduced in sp3) which is being depreciated in favor of sys.dm_exec_sql_text (available in sql 2005). The sql 2005 version also uses a cross apply join to get the data.&lt;br /&gt;&lt;/p&gt;&lt;p&gt;&amp;nbsp;&lt;/p&gt;&lt;p&gt;The procedure takes 1 parameter, @spid, and the results returned are:&lt;/p&gt;&lt;p&gt;the results of dbcc inputbuffer to see what query or procedure was called from the client&lt;br /&gt;&lt;/p&gt;&lt;p&gt;the results of sp_who2 to show general process information&lt;br /&gt;&lt;/p&gt;&lt;p&gt;the first 100 lines of the procedure or query being executed (this can be useful to find the procedure name being executed)&lt;br /&gt;&lt;/p&gt;&lt;p&gt;the text of the statement actually being executed.&amp;nbsp;&lt;/p&gt;&lt;p&gt;If you create these on the master database as dbo, then they should be accessible from all user database &lt;br /&gt;&lt;/p&gt;&lt;p&gt;&lt;br /&gt;&lt;/p&gt;&lt;img src="http://sqlblogcasts.com/aggbug.aspx?PostID=1449" width="1" height="1"&gt;</content><author><name>antxxxx</name><uri>http://sqlblogcasts.com/members/antxxxx.aspx</uri></author><category term="Diagnostics" scheme="http://sqlblogcasts.com/blogs/antxxxx/archive/tags/Diagnostics/default.aspx" /></entry><entry><title>Running a report against several servers in RS2005</title><link rel="alternate" type="text/html" href="http://sqlblogcasts.com/blogs/antxxxx/archive/2006/11/24/running-a-report-against-several-servers-in-rs2005.aspx" /><link rel="enclosure" type="application/x-zip-compressed" length="3874" href="http://sqlblogcasts.com/blogs/antxxxx/attachment/1412.ashx" /><id>http://sqlblogcasts.com/blogs/antxxxx/archive/2006/11/24/running-a-report-against-several-servers-in-rs2005.aspx</id><published>2006-11-24T14:47:00Z</published><updated>2006-11-24T14:47:00Z</updated><content type="html">

&lt;p class="MsoNormal"&gt;Whilst
I was looking at building custom reports in management studio, I finally got
round to looking at reporting services in sql 2005.&lt;/p&gt;&lt;p class="MsoNormal"&gt;&amp;nbsp;&lt;/p&gt;



&lt;p class="MsoNormal"&gt;One
really neat feature I found is the ability to use an expression to build a
connection string. Using this, you can dynamically set which server the report connects to when it runs. You
can then embed this report as a subreport on another report and so get it to
run against several servers all from one report. If you look after several
servers, this can give you a nice easy way to check all your servers are OK.&lt;/p&gt;&lt;p class="MsoNormal"&gt;&amp;nbsp;&lt;/p&gt;

&lt;p class="MsoNormal"&gt;To
do this, first create the report you want to run against each server. Don't
worry about the data source while you are designing it - just connect to any
machine and make sure it is designed how want.&lt;/p&gt;&lt;p class="MsoNormal"&gt;&amp;nbsp;&lt;/p&gt;

&lt;p class="MsoNormal"&gt;When
you are happy with it, add a parameter to the report called ServerName. This
should be a string datatype and the ‘allow blank value’ checkbox should be
unchecked.&lt;/p&gt;&lt;p class="MsoNormal"&gt;&amp;nbsp;&lt;/p&gt;

&lt;p class="MsoNormal"&gt;Next
you need to change the datasource to use an expression.(one thing to note is
you can’t use an expression on a shared datasource, so you may need to create a
new datasource for the report). Edit the datasource and click the fx button
next to the connection string and change the expression to&lt;/p&gt;&lt;p class="MsoNormal"&gt;&amp;nbsp;&lt;/p&gt;

&lt;p class="MsoNormal"&gt;&lt;span style="font-size:10pt;font-family:'Courier New';"&gt;=&lt;span style="color:maroon;"&gt;"Data
Source="&lt;/span&gt; &amp;amp; Parameters!ServerName.Value&lt;/span&gt;&lt;/p&gt;&lt;p class="MsoNormal"&gt;&amp;nbsp;&lt;/p&gt;

&lt;p class="MsoNormal"&gt;If
you now try and preview the report, you need to enter the servername parameter
and it runs against whichever server you specify.&lt;/p&gt;&lt;p class="MsoNormal"&gt;&amp;nbsp;&lt;/p&gt;

&lt;u1:p&gt;&lt;/u1:p&gt;

&lt;p class="MsoNormal"&gt;Now
for the second report. First create a dataset that will return all the names of
the servers you want to run the report against.&lt;/p&gt;&lt;p class="MsoNormal"&gt;&amp;nbsp;&lt;/p&gt;

&lt;u1:p&gt;&lt;/u1:p&gt;

&lt;p class="MsoNormal"&gt;On
the layout tab, add a table and bind it to that dataset. Then drag a subreport
into the detail part of the table. Right click on the subreport and select
properties and in the subreport drop down box, select the first report you
created. Finally go to the parameters tab and in the parameter name column
select ServerName and in the parameter value column select the column from the
dataset that contains the servername.&lt;/p&gt;&lt;p class="MsoNormal"&gt;&amp;nbsp;&lt;/p&gt;

&lt;u1:p&gt;&lt;/u1:p&gt;

&lt;p class="MsoNormal"&gt;In
the download on this entry are couple of reports to show how this all works.&lt;/p&gt;&lt;p class="MsoNormal"&gt;&amp;nbsp;&lt;/p&gt;

&lt;u1:p&gt;&lt;/u1:p&gt;

&lt;p class="MsoNormal"&gt;The
first report is SingleServerInfo that just shows some information that it
connects to. You can change which server it connects to using the ServerName
parameter.&lt;/p&gt;&lt;p class="MsoNormal"&gt;&amp;nbsp;&lt;/p&gt;

&lt;u1:p&gt;&lt;/u1:p&gt;

&lt;p class="MsoNormal"&gt;The
second report is MultipleServerInfo and has a table with SingleServerInfo as
subreport in one of the cells. This means it is called for each server returned
by the dataset on this report (which needs a table called ServerNames which can
be created using the script in the zip file)&lt;/p&gt;&lt;p class="MsoNormal"&gt;&amp;nbsp;&lt;/p&gt;&lt;p class="MsoNormal"&gt;These reports will only run against sql 2005 servers as they use some of the dynamic management views available on there. However, there is no reason why you cant use this technique to run a report against several sql 2000 servers (or a mixture of versions)&lt;br&gt; &lt;/p&gt;&lt;p class="MsoNormal"&gt;&amp;nbsp;&lt;/p&gt;&lt;p class="MsoNormal"&gt;Please make sure you look at the queries these reports run and are happy with them before running the reports against any of your servers.&amp;nbsp;&lt;/p&gt;



&lt;p class="MsoNormal"&gt;&lt;o:p&gt;&amp;nbsp;&lt;/o:p&gt;&lt;/p&gt;&lt;img src="http://sqlblogcasts.com/aggbug.aspx?PostID=1412" width="1" height="1"&gt;</content><author><name>antxxxx</name><uri>http://sqlblogcasts.com/members/antxxxx.aspx</uri></author></entry></feed>
