<?xml version="1.0" encoding="UTF-8" ?>
<?xml-stylesheet type="text/xsl" href="http://blogs.msdn.com/utility/FeedStylesheets/atom.xsl" media="screen"?><feed xmlns="http://www.w3.org/2005/Atom" xml:lang="en-US"><title type="html">Ramoji Ryali's Fundas</title><subtitle type="html">The interesting things I experimented with SQl Server.</subtitle><id>http://blogs.msdn.com/b/ramoji/atom.aspx</id><link rel="alternate" type="text/html" href="http://blogs.msdn.com/b/ramoji/" /><link rel="self" type="application/atom+xml" href="http://blogs.msdn.com/b/ramoji/atom.aspx" /><generator uri="http://telligent.com" version="5.6.583.17018">Telligent Community 5.6.583.17018 (Build: 5.6.583.17018)</generator><updated>2008-09-17T10:56:00Z</updated><entry><title>Could not load package because of error 0xC0011002. Failed to open package file due to error 0x80070005 "Access is denied."</title><link rel="alternate" type="text/html" href="http://blogs.msdn.com/b/ramoji/archive/2011/01/06/could-not-load-package-because-of-error-0xc0011002-failed-to-open-package-file-due-to-error-0x80070005-quot-access-is-denied-quot.aspx" /><id>http://blogs.msdn.com/b/ramoji/archive/2011/01/06/could-not-load-package-because-of-error-0xc0011002-failed-to-open-package-file-due-to-error-0x80070005-quot-access-is-denied-quot.aspx</id><published>2011-01-06T13:23:00Z</published><updated>2011-01-06T13:23:00Z</updated><content type="html">&lt;p&gt;Came across this error while executing a SSIS package through a SQL Agent Job on a SQL Server 2008 server.The job is running under a windows security account and the SSIS package is stored on file system of the server.&lt;/p&gt;
&lt;p&gt;The exact error message received was as shown below.&lt;/p&gt;
&lt;p&gt;Executed as user: Domain\User. Microsoft (R) SQL Server Execute Package Utility&amp;nbsp; Version 10.50.1600.1 for 64-bit&amp;nbsp; Copyright (C) Microsoft Corporation 2010. All rights reserved.&amp;nbsp;&amp;nbsp;&amp;nbsp; Started:&amp;nbsp; 11:11:37 PM&amp;nbsp; Error: 2011-01-03 23:11:37.14&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; Code: 0xC0011007&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; Source: {1BDBB290-5831-476E-97F5-78DA45F876F4}&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; Description: Unable to load the package as XML because of package does not have a valid XML format. A specific XML parser error will be posted.&amp;nbsp; End Error&amp;nbsp; Error: 2011-01-03 23:11:37.14&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; Code: 0xC0011002&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; Source: {1BDBB290-5831-476E-97F5-78DA45F876F4}&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; Description: Failed to open package file "C:\SSIS\MyPackage.dtsx" due to error 0x80070005 "Access is denied.".&amp;nbsp; This happens when loading a package and the file cannot be opened or loaded correctly into the XML document. This can be the result of either providing an incorrect file name was specified when calling LoadPackage or the XML file was specified and has an incorrect format.&amp;nbsp; End Error&amp;nbsp; &lt;i&gt;&lt;b&gt;Could not load package "D:\SSIS\MyPackage.dtsx" because of error 0xC0011002.&amp;nbsp; Description: Failed to open package file "D:\SSIS\MyPackage.dtsx" due to error 0x80070005 "Access is denied."&lt;/b&gt;&lt;/i&gt;.&amp;nbsp; This happens when loading a package and the file cannot be opened or loaded correctly into the XML document. This can be the result of either providing an incorrect file name was specified when calling LoadPackage or the XML file was specified and has an incorrect format.&amp;nbsp; Source: {1BDBB290-5831-476E-97F5-78DA45F876F4}&amp;nbsp; Started:&amp;nbsp; 11:11:37 PM&amp;nbsp; Finished: 11:11:37 PM&amp;nbsp; Elapsed:&amp;nbsp; 0.031 seconds.&amp;nbsp; Process Exit Code 4.&amp;nbsp; .&amp;nbsp; NOTE: The step was retried the requested number of times (5) without succeeding.&amp;nbsp; The step failed.&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;p&gt;Since the error message is talking about access, verified whether the security account with which SQL Agent Service is running has access to the server folder in which SSIS package is stored. Noticed that the security account doesn't have the access and the job started working after giving the read &amp;amp; write permission on the folder.&lt;/p&gt;
&lt;p&gt;Let me know if this has helped you.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=10112441" width="1" height="1"&gt;</content><author><name>Ramoji</name><uri>http://blogs.msdn.com/Ramoji/ProfileUrlRedirect.ashx</uri></author></entry><entry><title>Comparing data between two tables in SQL Server</title><link rel="alternate" type="text/html" href="http://blogs.msdn.com/b/ramoji/archive/2010/07/01/how-to-compare-data-between-two-tables-in-sql-server.aspx" /><id>http://blogs.msdn.com/b/ramoji/archive/2010/07/01/how-to-compare-data-between-two-tables-in-sql-server.aspx</id><published>2010-07-01T13:58:00Z</published><updated>2010-07-01T13:58:00Z</updated><content type="html">&lt;p&gt;As a database developer sometime or the other you might have come across this requirement and it can be achieved using many ways including built-in features like Checksum and TableDiff utility.&amp;nbsp;However, I would like to share an alternate&amp;nbsp;way to achieve the objective, which might be useful in some situations.&lt;/p&gt;
&lt;p&gt;Usually&amp;nbsp;the intention of&amp;nbsp;comparison is to find out the missing rows from either of the tables or both. This where the operator "EXCEPT" comes very handy. Let us see&amp;nbsp;it with an example.&lt;/p&gt;
&lt;p&gt;&lt;span style="color: #008000; font-size: x-small;"&gt;&lt;span style="color: #008000; font-size: x-small;"&gt;&lt;span style="color: #008000; font-size: x-small;"&gt;&lt;span style="color: #008000; font-size: x-small;"&gt;&lt;/span&gt;&lt;/span&gt;
&lt;p&gt;&amp;nbsp;--Create two Tables--&lt;/p&gt;
&lt;p&gt;&lt;span style="color: #0000ff;"&gt;CREATE TABLE TableA(ID Int, Name Varchar(256))&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span style="color: #0000ff;"&gt;GO&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span style="color: #0000ff;"&gt;CREATE TABLE TableB(ID Int, Name Varchar(256))&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span style="color: #0000ff;"&gt;GO&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span style="color: #0000ff;"&gt;INSERT INTO TableA VALUES(1,'A'),(2,'B'),(3,'D')&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span style="color: #0000ff;"&gt;INSERT INTO TableB VALUES(1,'A'),(2,NULL),(3,'C')&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;--Get rows from TableA that are not found in TableB--&lt;/p&gt;
&lt;p&gt;&lt;span style="color: #0000ff;"&gt;SELECT * FROM TableA&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span style="color: #0000ff;"&gt;EXCEPT&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span style="color: #0000ff;"&gt;SELECT * FROM TableB&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;--Get rows from TableB that are not found in TableA--&lt;/p&gt;
&lt;p&gt;&lt;span style="color: #0000ff;"&gt;SELECT * FROM TableB&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span style="color: #0000ff;"&gt;EXCEPT&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span style="color: #0000ff;"&gt;SELECT * FROM TableA&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;/p&gt;
&lt;/span&gt;&lt;/span&gt;I have used the above concept for comparing data between heavy tables and the performance is satisfactory. I could get the result in 3 Min 55 sec when I compared a table having 1.18 million rows. The comparison can't be performed for some of the data types of the columns like XML, Text and Image etc. So, I have written a generic stored procedure that does the comparison between two tables by excluding the columns that can't be compared. It also allows to compare tables across databases and schemas. Validations and error handling are not added as the intention is to just present the idea.&lt;/p&gt;
&lt;p&gt;
&lt;p&gt;----------------------------------------------------------------------------------------------------------------------&lt;/p&gt;
&lt;p&gt;&lt;span style="color: #0000ff;"&gt;CREATE PROCEDURE CompareTableData&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span style="color: #0000ff;"&gt;(&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span style="color: #0000ff;"&gt;@SourceDB sysname&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span style="color: #0000ff;"&gt;,@SourceSchema sysname&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span style="color: #0000ff;"&gt;,@SourceTable sysname&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span style="color: #0000ff;"&gt;,@TargetDB sysname&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span style="color: #0000ff;"&gt;,@TargetSchema sysname&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span style="color: #0000ff;"&gt;,@TargetTable sysname&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span style="color: #0000ff;"&gt;)&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span style="color: #0000ff;"&gt;AS&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span style="color: #0000ff;"&gt;BEGIN&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span style="color: #0000ff;"&gt;SET NOCOUNT ON&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span style="color: #0000ff;"&gt;DECLARE @SQL NVarchar(Max)&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span style="color: #0000ff;"&gt;DECLARE @ColList Varchar(Max)&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span style="color: #008000;"&gt;--Concatenate the column list by excluding the data types that can't be used in comparision--&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span style="color: #0000ff;"&gt;SET @SQL = 'SELECT @ColList = CASE WHEN @ColList IS NULL THEN '''' ELSE @ColList + '','' END + SC.Name FROM ' + @SourceDB + '.sys.columns SC '&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span style="color: #0000ff;"&gt;SET @SQL = @SQL + ' INNER JOIN ' + @SourceDB + '.sys.Types ST ON SC.system_type_id = ST.system_type_id WHERE object_id = object_id(@SourceTable) '&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span style="color: #0000ff;"&gt;SET @SQL = @SQL + ' AND ST.Name NOT IN (''xml'',''Text'',''Image'',''Geometry'',''Geography'')'&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span style="color: #0000ff;"&gt;EXEC sp_executesql @SQL,N'@ColList varchar(Max) OUTPUT,@SourceTable sysname',@ColList OUTPUT,@Sourcetable&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span style="color: #008000;"&gt;--Get the rows that are missing from Target table--&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span style="color: #0000ff;"&gt;SET @SQL = 'SELECT ''' + @TargetTable + ''' as RowMissingFrom,' + @ColList + ' FROM ' + @SourceDB + '.' + @SourceSchema + '.' + @SourceTable&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span style="color: #0000ff;"&gt;SET @SQL = @SQL + ' EXCEPT '&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span style="color: #0000ff;"&gt;SET @SQL = @SQL + ' SELECT ''' + @TargetTable + ''' as RowMissingFrom,' + @ColList + ' FROM ' + @TargetDB + '.' + @TargetSchema + '.' + @TargetTable&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span style="color: #0000ff;"&gt;EXEC sp_executesql @SQL,N'@ColList varchar(Max)',@ColList&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span style="color: #008000;"&gt;--Get the rows that are missing from Source table--&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span style="color: #0000ff;"&gt;SET @SQL = ' SELECT ''' + @SourceTable + ''' as RowMissingFrom,' + @ColList + ' FROM ' + @TargetDB + '.' + @TargetSchema + '.' + @TargetTable&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span style="color: #0000ff;"&gt;SET @SQL = @SQL + ' EXCEPT '&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span style="color: #0000ff;"&gt;SET @SQL = @SQL + 'SELECT ''' + @SourceTable + ''' as RowMissingFrom,' + @ColList + ' FROM ' + @SourceDB + '.' + @SourceSchema + '.' + @SourceTable&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span style="color: #0000ff;"&gt;EXEC sp_executesql @SQL,N'@ColList varchar(Max)',@ColList &lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span style="color: #0000ff;"&gt;END&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;-----------------------------------------------------------------------------------------------------------&lt;/p&gt;
&lt;p&gt;Sample usgae of&amp;nbsp;the procedure&amp;nbsp;is:&amp;nbsp;&amp;nbsp;&lt;span style="color: #0000ff; font-size: x-small;"&gt;&lt;span style="color: #0000ff; font-size: x-small;"&gt;EXEC&amp;nbsp;&lt;/span&gt;&lt;/span&gt;&lt;span style="font-size: x-small;"&gt; CompareTableData&lt;/span&gt;&lt;span style="color: #0000ff; font-size: x-small;"&gt;&lt;span style="color: #0000ff; font-size: x-small;"&gt; &lt;/span&gt;&lt;/span&gt;&lt;span style="color: #ff0000; font-size: x-small;"&gt;&lt;span style="color: #ff0000; font-size: x-small;"&gt;'DB1'&lt;/span&gt;&lt;/span&gt;&lt;span style="color: #808080; font-size: x-small;"&gt;&lt;span style="color: #808080; font-size: x-small;"&gt;,&lt;/span&gt;&lt;/span&gt;&lt;span style="color: #ff0000; font-size: x-small;"&gt;&lt;span style="color: #ff0000; font-size: x-small;"&gt;'dbo'&lt;/span&gt;&lt;/span&gt;&lt;span style="color: #808080; font-size: x-small;"&gt;&lt;span style="color: #808080; font-size: x-small;"&gt;,&lt;/span&gt;&lt;/span&gt;&lt;span style="color: #ff0000; font-size: x-small;"&gt;&lt;span style="color: #ff0000; font-size: x-small;"&gt;'TableA'&lt;/span&gt;&lt;/span&gt;&lt;span style="color: #808080; font-size: x-small;"&gt;&lt;span style="color: #808080; font-size: x-small;"&gt;,&lt;/span&gt;&lt;/span&gt;&lt;span style="color: #ff0000; font-size: x-small;"&gt;&lt;span style="color: #ff0000; font-size: x-small;"&gt;'DB2'&lt;/span&gt;&lt;/span&gt;&lt;span style="color: #808080; font-size: x-small;"&gt;&lt;span style="color: #808080; font-size: x-small;"&gt;,&lt;/span&gt;&lt;/span&gt;&lt;span style="color: #ff0000; font-size: x-small;"&gt;&lt;span style="color: #ff0000; font-size: x-small;"&gt;'HR'&lt;/span&gt;&lt;/span&gt;&lt;span style="color: #808080; font-size: x-small;"&gt;&lt;span style="color: #808080; font-size: x-small;"&gt;,&lt;/span&gt;&lt;/span&gt;&lt;span style="color: #ff0000; font-size: x-small;"&gt;&lt;span style="color: #ff0000; font-size: x-small;"&gt;'TableB'&lt;span style="color: #ff0000; font-size: x-small;"&gt;&lt;span style="color: #ff0000; font-size: x-small;"&gt;&amp;nbsp;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span style="color: #ff0000; font-size: x-small;"&gt;&lt;span style="color: #ff0000; font-size: x-small;"&gt;&lt;span style="color: #ff0000; font-size: x-small;"&gt;&lt;span style="color: #ff0000; font-size: x-small;"&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&amp;nbsp;Please share your feedback if you find this interesting.&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=10033421" width="1" height="1"&gt;</content><author><name>Ramoji</name><uri>http://blogs.msdn.com/Ramoji/ProfileUrlRedirect.ashx</uri></author></entry><entry><title>Message "TFS10139: The following check-in policies have not been satisfied" comes in VSTS2010</title><link rel="alternate" type="text/html" href="http://blogs.msdn.com/b/ramoji/archive/2010/06/14/message-quot-tfs10139-the-following-check-in-policies-have-not-been-satisfied-quot-comes-in-vsts2010.aspx" /><id>http://blogs.msdn.com/b/ramoji/archive/2010/06/14/message-quot-tfs10139-the-following-check-in-policies-have-not-been-satisfied-quot-comes-in-vsts2010.aspx</id><published>2010-06-14T07:12:49Z</published><updated>2010-06-14T07:12:49Z</updated><content type="html">&lt;p&gt;Got this message after the upgrade from VSTS 2008 to VSTS 2010 while checking in a file. The message disappeared after installing "Team Foundation Server Power Tools April 2010" from the below location.&lt;/p&gt;
&lt;p&gt;&lt;a href="http://visualstudiogallery.msdn.microsoft.com/en-us/3e8c9b68-6e39-4577-b9b7-78489b5cb1da"&gt;http://visualstudiogallery.msdn.microsoft.com/en-us/3e8c9b68-6e39-4577-b9b7-78489b5cb1da&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;Hope this helps :-)&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=10024263" width="1" height="1"&gt;</content><author><name>Ramoji</name><uri>http://blogs.msdn.com/Ramoji/ProfileUrlRedirect.ashx</uri></author></entry><entry><title>Error while enabling CDC on a table. The server principal "xyz" is not able to access the database "msdb" under the current security context. </title><link rel="alternate" type="text/html" href="http://blogs.msdn.com/b/ramoji/archive/2010/05/13/error-while-enabling-cdc-on-a-table-the-server-principal-xyz-is-not-able-to-access-the-database-msdb-under-the-current-security-context.aspx" /><id>http://blogs.msdn.com/b/ramoji/archive/2010/05/13/error-while-enabling-cdc-on-a-table-the-server-principal-xyz-is-not-able-to-access-the-database-msdb-under-the-current-security-context.aspx</id><published>2010-05-13T06:01:00Z</published><updated>2010-05-13T06:01:00Z</updated><content type="html">&lt;P&gt;We came across the following error&amp;nbsp;after&amp;nbsp;successfully enabling CDC on&amp;nbsp;a Database and then trying to enable CDC on a table in SQL Server 2008 SP1 (Version 10.0.2531.0)&lt;/P&gt;
&lt;P&gt;&lt;SPAN style="FONT-FAMILY: 'Calibri','sans-serif'; COLOR: red; FONT-SIZE: 11pt"&gt;Msg 22832, Level 16, State 1, Procedure sp_cdc_enable_table_internal, Line 607&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN style="FONT-FAMILY: 'Calibri','sans-serif'; COLOR: red; FONT-SIZE: 11pt"&gt;&lt;/SPAN&gt;&lt;SPAN style="FONT-FAMILY: 'Calibri','sans-serif'; COLOR: red; FONT-SIZE: 11pt"&gt;Could not update the metadata that indicates table [dbo].[MyTable] is enabled for Change Data Capture. The failure occurred when executing the command '[sys].[sp_cdc_add_job] @job_type = N'capture''. The error returned was 916: &lt;B&gt;'The server principal "S-1-9-3-3045654011-13150378417-261222020-2009464159."&lt;/B&gt; &lt;B&gt;is not able to access the database "msdb" under the current security context.'&lt;/B&gt;. Use the action and error to determine the cause of the failure and resubmit the request.&lt;/SPAN&gt;&lt;SPAN style="COLOR: black"&gt;&lt;?xml:namespace prefix = o ns = "urn:schemas-microsoft-com:office:office" /&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;Since the failure message is saying the error occured while creating the Capture job, we tried explicitly creating the same using the system procedure "sp_cdc_add_job" as shown below and it solved the issue for us.&lt;/P&gt;&lt;FONT color=#0000ff size=2&gt;&lt;FONT color=#0000ff size=2&gt;
&lt;P&gt;---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------&amp;nbsp;&lt;/P&gt;
&lt;P&gt;USE&lt;/FONT&gt;&lt;/FONT&gt;&lt;FONT size=2&gt; MyDatabase&lt;/P&gt;&lt;/FONT&gt;&lt;FONT color=#0000ff size=2&gt;&lt;FONT color=#0000ff size=2&gt;
&lt;P&gt;GO&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;--Enable CDC on the database&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;EXECUTE&lt;/FONT&gt;&lt;/FONT&gt;&lt;FONT size=2&gt; &lt;/FONT&gt;&lt;FONT color=#008000 size=2&gt;&lt;FONT color=#008000 size=2&gt;sys&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=#800000 size=2&gt;&lt;FONT color=#800000 size=2&gt;sp_cdc_enable_db&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;go&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;--Manually create Capture job to avoid the job creation error&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;EXEC&lt;/FONT&gt;&lt;/FONT&gt;&lt;FONT size=2&gt; [sys]&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;[sp_cdc_add_job]&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 size=2&gt;@job_type &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;N'capture'&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;go&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;--Enable CDC on the tables&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;EXECUTE&lt;/FONT&gt;&lt;/FONT&gt;&lt;FONT size=2&gt; &lt;/FONT&gt;&lt;FONT color=#008000 size=2&gt;&lt;FONT color=#008000 size=2&gt;sys&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=#800000 size=2&gt;&lt;FONT color=#800000 size=2&gt;sp_cdc_enable_table&lt;/FONT&gt;&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 size=2&gt;@source_schema &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;N'dbo'&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; @source_name &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;'AdjustmentReason'&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; @role_name &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;N'cdc_admin'&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; @supports_net_changes &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; 1&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; @index_name &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;null,&lt;/FONT&gt;&lt;/FONT&gt;&lt;FONT size=2&gt; @captured_column_list &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;null,&lt;/FONT&gt;&lt;/FONT&gt;&lt;FONT size=2&gt; @filegroup_name &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;N'PRIMARY'&lt;/P&gt;&lt;/FONT&gt;&lt;/FONT&gt;
&lt;P mce_keep="true"&gt;---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------&lt;/P&gt;
&lt;P mce_keep="true"&gt;If you want more details on the above error, you can refer to the&amp;nbsp;link &lt;A href="http://msdn.microsoft.com/en-us/library/ee342155.aspx"&gt;http://msdn.microsoft.com/en-us/library/ee342155.aspx&lt;/A&gt;.&lt;/P&gt;
&lt;P mce_keep="true"&gt;Please drop me an encouraging note if this work around has helped in solving your error. Thanks in advance.&amp;nbsp;&lt;/P&gt;
&lt;P mce_keep="true"&gt;&amp;nbsp;&lt;/P&gt;
&lt;P mce_keep="true"&gt;&amp;nbsp;&lt;/P&gt;
&lt;P mce_keep="true"&gt;&amp;nbsp;&lt;/P&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=10012326" width="1" height="1"&gt;</content><author><name>Ramoji</name><uri>http://blogs.msdn.com/Ramoji/ProfileUrlRedirect.ashx</uri></author></entry><entry><title>SSIS Data Flow Task fails with Unspecified Error</title><link rel="alternate" type="text/html" href="http://blogs.msdn.com/b/ramoji/archive/2010/01/05/ssis-data-flow-task-fails-with-unspecified-error.aspx" /><id>http://blogs.msdn.com/b/ramoji/archive/2010/01/05/ssis-data-flow-task-fails-with-unspecified-error.aspx</id><published>2010-01-05T14:01:00Z</published><updated>2010-01-05T14:01:00Z</updated><content type="html">&lt;P&gt;We have few SQL Agent jobs on&amp;nbsp;SQL Server 2008 (10.0.2531) and these jobs&amp;nbsp;are executing SSIS packages, which are&amp;nbsp;created using BIDS 2008. The jobs are scheduled to run daily at a low frequency. The intention is to run these jobs like a demon service. &lt;/P&gt;
&lt;P&gt;We started getting the "Unspecified Error" at random intervals of time and the jobs always failed at the Data Flow Task only.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;The job's error log has the following message. However, when the error is captured using&amp;nbsp;an event handler&amp;nbsp;in the package, an error code of "-2147467259" is reported.&amp;nbsp;&amp;nbsp;&lt;/P&gt;&lt;FONT color=#0000ff size=2&gt;&lt;FONT color=#0000ff size=2&gt;
&lt;P&gt;&lt;EM&gt;Code:&lt;/EM&gt;&lt;/FONT&gt;&lt;/FONT&gt;&lt;FONT size=2&gt;&lt;EM&gt; 0x80004005 &lt;/EM&gt;&lt;/P&gt;&lt;/FONT&gt;&lt;FONT color=#0000ff size=2&gt;&lt;FONT color=#0000ff size=2&gt;
&lt;P&gt;&lt;EM&gt;Source:&lt;/EM&gt;&lt;/FONT&gt;&lt;/FONT&gt;&lt;EM&gt;&lt;FONT size=2&gt; &lt;/FONT&gt;&lt;FONT color=#808080 size=2&gt;&lt;FONT color=#808080 size=2&gt;&amp;lt;&lt;/FONT&gt;&lt;/FONT&gt;&lt;FONT size=2&gt;Data Flow Task Name&lt;/FONT&gt;&lt;FONT color=#808080 size=2&gt;&lt;FONT color=#808080 size=2&gt;&amp;gt;&lt;/FONT&gt;&lt;/FONT&gt;&lt;FONT size=2&gt; SSIS&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;Pipeline &lt;/P&gt;&lt;/FONT&gt;&lt;/EM&gt;&lt;FONT color=#0000ff size=2&gt;&lt;FONT color=#0000ff size=2&gt;
&lt;P&gt;&lt;EM&gt;Description:&lt;/EM&gt;&lt;/FONT&gt;&lt;/FONT&gt;&lt;EM&gt;&lt;FONT size=2&gt; Unspecified error &lt;/FONT&gt;&lt;FONT color=#0000ff size=2&gt;&lt;FONT color=#0000ff size=2&gt;End&lt;/FONT&gt;&lt;/FONT&gt;&lt;FONT size=2&gt; Error&lt;/P&gt;&lt;/FONT&gt;&lt;/EM&gt;&lt;FONT color=#0000ff size=2&gt;&lt;FONT color=#0000ff size=2&gt;
&lt;P&gt;&lt;EM&gt;DTExec:&lt;/EM&gt;&lt;/FONT&gt;&lt;/FONT&gt;&lt;EM&gt;&lt;FONT size=2&gt; The package execution returned DTSER_FAILURE&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;/FONT&gt;&lt;/FONT&gt;&lt;FONT size=2&gt;1&lt;/FONT&gt;&lt;FONT color=#808080 size=2&gt;&lt;FONT color=#808080 size=2&gt;)&lt;/FONT&gt;&lt;/FONT&gt;&lt;/EM&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT color=#808080 size=2&gt;&lt;FONT color=#808080 size=2&gt;&lt;FONT color=#000000&gt;After struggling for two weeks with the error, we finally fixed it by limiting the SQL Server Memory usage. We&amp;nbsp;restricted SQL Server&amp;nbsp;to consume&amp;nbsp;50% at the max. The reason for doing this is to leave enough&amp;nbsp;memory&amp;nbsp;to&amp;nbsp;other services like Integration Services. Otherwise, over a period of time, SQL Server consumes almost all the&amp;nbsp;available memory&amp;nbsp;and releases it only when demanded by OS.&lt;/FONT&gt;&lt;/FONT&gt;&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT color=#808080 size=2&gt;&lt;FONT color=#808080 size=2&gt;&lt;FONT color=#000000&gt;Here is the exact script we used, which you can tweak based on the percentage you want to allocate depending on your project requirement. Let me know if this blog has helped you.&lt;/FONT&gt;&lt;/FONT&gt;&lt;/FONT&gt;&lt;/P&gt;&lt;FONT color=#808080 size=2&gt;&lt;FONT color=#808080 size=2&gt;&lt;FONT color=#0000ff size=2&gt;&lt;FONT color=#0000ff size=2&gt;
&lt;P&gt;DECLARE &lt;/FONT&gt;&lt;/FONT&gt;&lt;FONT color=#000000 size=2&gt;@TotalMemInGB &lt;/FONT&gt;&lt;FONT color=#0000ff size=2&gt;&lt;FONT color=#0000ff size=2&gt;int&lt;/P&gt;
&lt;P&gt;DECLARE &lt;/FONT&gt;&lt;/FONT&gt;&lt;FONT color=#000000 size=2&gt;@MinMemInMB &lt;/FONT&gt;&lt;FONT color=#0000ff size=2&gt;&lt;FONT color=#0000ff size=2&gt;int&lt;/P&gt;
&lt;P&gt;DECLARE &lt;/FONT&gt;&lt;/FONT&gt;&lt;FONT color=#000000 size=2&gt;@MaxMemInMB &lt;/FONT&gt;&lt;FONT color=#0000ff size=2&gt;&lt;FONT color=#0000ff size=2&gt;int&lt;/P&gt;
&lt;P&gt;select &lt;/FONT&gt;&lt;/FONT&gt;&lt;FONT color=#000000 size=2&gt;@TotalMemInGB =(physical_memory_in_bytes/(1024*1024)/1000) &lt;/FONT&gt;&lt;FONT color=#0000ff size=2&gt;&lt;FONT color=#0000ff size=2&gt;from &lt;/FONT&gt;&lt;/FONT&gt;&lt;FONT size=2&gt;&lt;FONT color=#000000&gt;sys.dm_os_sys_info&lt;/FONT&gt;&lt;/P&gt;&lt;/FONT&gt;&lt;FONT color=#0000ff size=2&gt;&lt;FONT color=#0000ff size=2&gt;
&lt;P&gt;SET &lt;/FONT&gt;&lt;/FONT&gt;&lt;FONT color=#000000 size=2&gt;@MinMemInMB= (@TotalMemInGB * 0.5) * 1024 &lt;/FONT&gt;&lt;FONT color=#008000 size=2&gt;&lt;FONT color=#008000 size=2&gt;-- taking 50% of available memory.&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;SET &lt;/FONT&gt;&lt;/FONT&gt;&lt;FONT color=#000000 size=2&gt;@MaxMemInMB= (@TotalMemInGB * 0.5) * 1024 &lt;/FONT&gt;&lt;FONT color=#008000 size=2&gt;&lt;FONT color=#008000 size=2&gt;-- taking 50% of available memory.&lt;/P&gt;
&lt;P mce_keep="true"&gt;&amp;nbsp;&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;EXEC &lt;/FONT&gt;&lt;/FONT&gt;&lt;FONT color=#000000 size=2&gt;sp_configure &lt;/FONT&gt;&lt;FONT color=#a31515 size=2&gt;&lt;FONT color=#a31515 size=2&gt;'show advanced options'&lt;/FONT&gt;&lt;/FONT&gt;&lt;FONT size=2&gt;&lt;FONT color=#000000&gt;,1&lt;/FONT&gt;&lt;/P&gt;&lt;/FONT&gt;&lt;FONT color=#0000ff size=2&gt;&lt;FONT color=#0000ff size=2&gt;
&lt;P&gt;RECONFIGURE&lt;/P&gt;
&lt;P&gt;EXEC &lt;/FONT&gt;&lt;/FONT&gt;&lt;FONT color=#000000 size=2&gt;sp_configure &lt;/FONT&gt;&lt;FONT color=#a31515 size=2&gt;&lt;FONT color=#a31515 size=2&gt;'max server memory'&lt;/FONT&gt;&lt;/FONT&gt;&lt;FONT size=2&gt;&lt;FONT color=#000000&gt;, @MaxMemInMB&lt;/FONT&gt;&lt;/P&gt;&lt;/FONT&gt;&lt;FONT color=#0000ff size=2&gt;&lt;FONT color=#0000ff size=2&gt;
&lt;P&gt;RECONFIGURE&lt;/P&gt;
&lt;P&gt;EXEC &lt;/FONT&gt;&lt;/FONT&gt;&lt;FONT color=#000000 size=2&gt;sp_configure &lt;/FONT&gt;&lt;FONT color=#a31515 size=2&gt;&lt;FONT color=#a31515 size=2&gt;'min server memory'&lt;/FONT&gt;&lt;/FONT&gt;&lt;FONT size=2&gt;&lt;FONT color=#000000&gt;,@MinMemInMB&lt;/FONT&gt;&lt;/P&gt;&lt;/FONT&gt;&lt;FONT color=#0000ff size=2&gt;&lt;FONT color=#0000ff size=2&gt;
&lt;P&gt;RECONFIGURE &lt;/P&gt;
&lt;P mce_keep="true"&gt;&amp;nbsp;&lt;/P&gt;
&lt;P mce_keep="true"&gt;&amp;nbsp;&lt;/P&gt;&lt;/FONT&gt;&lt;/FONT&gt;&lt;/FONT&gt;&lt;/FONT&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=9943922" width="1" height="1"&gt;</content><author><name>Ramoji</name><uri>http://blogs.msdn.com/Ramoji/ProfileUrlRedirect.ashx</uri></author></entry><entry><title>SSIS package fails with Protocol error in TDS stream</title><link rel="alternate" type="text/html" href="http://blogs.msdn.com/b/ramoji/archive/2009/12/30/protocol-error-in-tds-stream.aspx" /><id>http://blogs.msdn.com/b/ramoji/archive/2009/12/30/protocol-error-in-tds-stream.aspx</id><published>2009-12-30T13:02:00Z</published><updated>2009-12-30T13:02:00Z</updated><content type="html">&lt;P&gt;Encountered this error while running a SSIS package through a SQL Agent Job on SQL Server 2008. The processing in the package is a pretty simple and&amp;nbsp;the purpose is to export data&amp;nbsp;from few tables from one SQL Server to another. Both the source and target servers are on SQL Server 2008 (10.0.2531) and&amp;nbsp;Data Flow Task&amp;nbsp;(with OLEDB source and destination tasks) is used for data export. The package is created using Visual Studio 2008 and the job is running on the destination server. &lt;/P&gt;
&lt;P&gt;The job continuously failed with the following error and in each run the failure occured at a different table.&lt;/P&gt;
&lt;P mce_keep="true"&gt;&lt;FONT color=#0000ff&gt;&lt;/FONT&gt;&lt;/P&gt;
&lt;P style="TEXT-ALIGN: justify; LINE-HEIGHT: normal; MARGIN: 0in 0in 0pt; mso-layout-grid-align: none" class=MsoNormal&gt;&lt;SPAN style="FONT-FAMILY: 'Arial','sans-serif'; COLOR: black; FONT-SIZE: 8pt; mso-themecolor: text1; mso-bidi-language: HI; mso-no-proof: yes"&gt;&lt;EM&gt;Source: DFT_MyTable Source - MyTable &lt;?xml:namespace prefix = o ns = "urn:schemas-microsoft-com:office:office" /&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/EM&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P style="TEXT-ALIGN: justify; LINE-HEIGHT: normal; MARGIN: 0in 0in 0pt; mso-layout-grid-align: none" class=MsoNormal&gt;&lt;SPAN style="FONT-FAMILY: 'Arial','sans-serif'; COLOR: black; FONT-SIZE: 8pt; mso-themecolor: text1; mso-bidi-language: HI; mso-no-proof: yes"&gt;&lt;EM&gt;Description: SSIS Error Code DTS_E_OLEDBERROR. An OLE DB error has occurred. Error code: 0x80004005. &lt;o:p&gt;&lt;/o:p&gt;&lt;/EM&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P style="TEXT-ALIGN: justify; LINE-HEIGHT: normal; MARGIN: 0in 0in 0pt; mso-layout-grid-align: none" class=MsoNormal&gt;&lt;SPAN style="FONT-FAMILY: 'Arial','sans-serif'; COLOR: black; FONT-SIZE: 8pt; mso-themecolor: text1; mso-bidi-language: HI; mso-no-proof: yes"&gt;&lt;EM&gt;An OLE DB record is available. Source: "Microsoft SQL Server Native Client 10.0" Hresult: 0x80004005 &lt;/EM&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P style="TEXT-ALIGN: justify; LINE-HEIGHT: normal; MARGIN: 0in 0in 0pt; mso-layout-grid-align: none" class=MsoNormal&gt;&lt;SPAN style="FONT-FAMILY: 'Arial','sans-serif'; COLOR: black; FONT-SIZE: 8pt; mso-themecolor: text1; mso-bidi-language: HI; mso-no-proof: yes"&gt;&lt;/SPAN&gt;&lt;EM&gt;&lt;SPAN style="LINE-HEIGHT: 115%; FONT-FAMILY: 'Arial','sans-serif'; COLOR: black; FONT-SIZE: 8pt; mso-themecolor: text1; mso-bidi-language: HI; mso-no-proof: yes; mso-fareast-font-family: Calibri; mso-fareast-theme-font: minor-latin; mso-ansi-language: EN-US; mso-fareast-language: EN-US"&gt;Description: "&lt;/SPAN&gt;&lt;SPAN style="LINE-HEIGHT: 115%; FONT-FAMILY: 'Arial','sans-serif'; COLOR: red; FONT-SIZE: 8pt; mso-bidi-language: HI; mso-no-proof: yes; mso-fareast-font-family: Calibri; mso-fareast-theme-font: minor-latin; mso-ansi-language: EN-US; mso-fareast-language: EN-US"&gt;Protocol error in TDS stream&lt;/SPAN&gt;&lt;SPAN style="LINE-HEIGHT: 115%; FONT-FAMILY: 'Arial','sans-serif'; COLOR: black; FONT-SIZE: 8pt; mso-themecolor: text1; mso-bidi-language: HI; mso-no-proof: yes; mso-fareast-font-family: Calibri; mso-fareast-theme-font: minor-latin; mso-ansi-language: EN-US; mso-fareast-language: EN-US"&gt;". An OLE DB record is available&lt;/SPAN&gt;&lt;/EM&gt;&lt;/P&gt;
&lt;P&gt;The issue is solved when the Network Protocol used to connect to the source SQL Server is changed from&amp;nbsp;TCP/IP to NamedPipes. Basically, an alias&amp;nbsp;for the source is created on the destination server using the below steps.&lt;/P&gt;
&lt;P&gt;1. Go to Start--&amp;gt; All Programs--&amp;gt; Microsoft SQL Server 2008--&amp;gt; Configuration Tools --&amp;gt; SQL Server Configuration Manager&lt;/P&gt;
&lt;P&gt;2. Expand the node SQL Native Client 10.0 Configuration&lt;/P&gt;
&lt;P&gt;3. Right click on "Aliases" and then select "New Alias..."&lt;/P&gt;
&lt;P&gt;4. Provide the IP address of the Source SQL server against the "Server" field and specify the Source server name against the "Alias Name" field.&lt;/P&gt;
&lt;P&gt;5. Choose the protocol as "NamedPipes" and click OK&lt;/P&gt;&lt;FONT color=#0000ff&gt;&lt;FONT color=#0000ff&gt;
&lt;P style="TEXT-ALIGN: justify; LINE-HEIGHT: normal; MARGIN: 0in 0in 0pt; mso-layout-grid-align: none" class=MsoNormal&gt;&lt;SPAN style="LINE-HEIGHT: 115%; FONT-FAMILY: 'Arial','sans-serif'; COLOR: black; FONT-SIZE: 8pt; mso-themecolor: text1; mso-bidi-language: HI; mso-no-proof: yes; mso-fareast-font-family: Calibri; mso-fareast-theme-font: minor-latin; mso-ansi-language: EN-US; mso-fareast-language: EN-US"&gt;&lt;FONT size=2&gt;Please drop me a note if you have come across this error and this blog has helped you in resolving the issue.&lt;/FONT&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;EM&gt;&lt;/EM&gt;&lt;/FONT&gt;&lt;/FONT&gt;&amp;nbsp;&lt;/P&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=9942266" width="1" height="1"&gt;</content><author><name>Ramoji</name><uri>http://blogs.msdn.com/Ramoji/ProfileUrlRedirect.ashx</uri></author></entry><entry><title>Could not update the metadata that indicates database is enabled for Change Data Capture. The failure occurred when executing the command SetCDCTracked(Value = 1)</title><link rel="alternate" type="text/html" href="http://blogs.msdn.com/b/ramoji/archive/2009/11/20/could-not-update-the-metadata-that-indicates-database-is-enabled-for-change-data-capture-the-failure-occurred-when-executing-the-command-setcdctracked-value-1.aspx" /><id>http://blogs.msdn.com/b/ramoji/archive/2009/11/20/could-not-update-the-metadata-that-indicates-database-is-enabled-for-change-data-capture-the-failure-occurred-when-executing-the-command-setcdctracked-value-1.aspx</id><published>2009-11-20T06:59:00Z</published><updated>2009-11-20T06:59:00Z</updated><content type="html">&lt;P&gt;This error message comes when you are trying to enable CDC on a SQL Server 2008 database for which the owner is not "sa". The exact error message will be as shown below.&lt;/P&gt;&lt;FONT size=1&gt;
&lt;P&gt;Msg 22830, Level 16, State 1, Procedure sp_cdc_enable_db_internal, Line 186&lt;/P&gt;
&lt;P&gt;Could not update the metadata that indicates database&amp;nbsp;[XXXXX] is enabled for Change Data Capture. The failure occurred when executing the command 'SetCDCTracked(Value = 1)'. The error returned was 15404: 'Could not obtain information about Windows NT group/user 'Domain\user', error code 0x5.'. Use the action and error to determine the cause of the failure and resubmit the request.&lt;/P&gt;
&lt;P&gt;Msg 266, Level 16, State 2, Procedure sp_cdc_enable_db_internal, Line 0&lt;/P&gt;
&lt;P&gt;Transaction count after EXECUTE indicates a mismatching number of BEGIN and COMMIT statements. Previous count = 1, current count = 2.&lt;/P&gt;
&lt;P&gt;Msg 266, Level 16, State 2, Procedure sp_cdc_enable_db, Line 0&lt;/P&gt;
&lt;P&gt;Transaction count after EXECUTE indicates a mismatching number of BEGIN and COMMIT statements. Previous count = 1, current count = 2.&lt;/P&gt;
&lt;P&gt;&lt;/FONT&gt;The fix for this is to change the databse owner to "sa"&amp;nbsp;by executing the below script.&lt;/P&gt;&lt;FONT color=#0000ff size=2&gt;&lt;FONT color=#0000ff size=2&gt;
&lt;P&gt;USE&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;&amp;lt;&lt;/FONT&gt;&lt;/FONT&gt;&lt;FONT color=#0000ff size=2&gt;&lt;FONT color=#0000ff size=2&gt;Database&lt;/FONT&gt;&lt;/FONT&gt;&lt;FONT color=#808080 size=2&gt;&lt;FONT color=#808080 size=2&gt;&amp;gt;&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;GO&lt;/P&gt;
&lt;P&gt;EXEC&lt;/FONT&gt;&lt;/FONT&gt;&lt;FONT size=2&gt; &lt;/FONT&gt;&lt;FONT color=#800000 size=2&gt;&lt;FONT color=#800000 size=2&gt;sp_changedbowner&lt;/FONT&gt;&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=#ff0000 size=2&gt;&lt;FONT color=#ff0000 size=2&gt;'sa'&lt;/P&gt;&lt;/FONT&gt;&lt;/FONT&gt;
&lt;P mce_keep="true"&gt;Read the below KB article for more details.&lt;/P&gt;
&lt;P mce_keep="true"&gt;&lt;A href="http://support.microsoft.com/kb/913423" mce_href="http://support.microsoft.com/kb/913423"&gt;http://support.microsoft.com/kb/913423&lt;/A&gt;&lt;/P&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=9926032" width="1" height="1"&gt;</content><author><name>Ramoji</name><uri>http://blogs.msdn.com/Ramoji/ProfileUrlRedirect.ashx</uri></author></entry><entry><title>Explicit value must be specified for identity column in table [XXXXXX] either when IDENTITY_INSERT is set to ON or when a replication user is inserting into a NOT FOR REPLICATION identity column</title><link rel="alternate" type="text/html" href="http://blogs.msdn.com/b/ramoji/archive/2009/11/13/explicit-value-must-be-specified-for-identity-column-in-table-xxxxxx-either-when-identity-insert-is-set-to-on-or-when-a-replication-user-is-inserting-into-a-not-for-replication-identity-column.aspx" /><id>http://blogs.msdn.com/b/ramoji/archive/2009/11/13/explicit-value-must-be-specified-for-identity-column-in-table-xxxxxx-either-when-identity-insert-is-set-to-on-or-when-a-replication-user-is-inserting-into-a-not-for-replication-identity-column.aspx</id><published>2009-11-13T09:37:00Z</published><updated>2009-11-13T09:37:00Z</updated><content type="html">&lt;P&gt;I encountered this error when explicitly inserting values in an Identity column of a Table that is created in a&amp;nbsp;SQL Server 2008 Database and the DB is not part of any kind of Replication. I have made sure that&amp;nbsp;"Identity_Insert" is turned on for that table before performing the insert. Also I have checked that "NOT FOR REPLICATION" is disabled for that&amp;nbsp;Identity column (Obviously, it is in disabled state in my case&amp;nbsp;as there is no Replication). &lt;/P&gt;
&lt;P&gt;After struggling for some time, I noticed that&amp;nbsp;an "Instead of Insert"&amp;nbsp;Trigger exist on the Table. The interesting thing is, no change is happening to the Idenity column in the Trigger definition. However,&amp;nbsp;disabling that Trigger&amp;nbsp;fixed the issue miraculously :-) &lt;/P&gt;
&lt;P&gt;Let me know if this&amp;nbsp;fix has helped you too.&amp;nbsp;&lt;/P&gt;
&lt;P mce_keep="true"&gt;&amp;nbsp;&lt;/P&gt;
&lt;P mce_keep="true"&gt;&amp;nbsp;&lt;/P&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=9921872" width="1" height="1"&gt;</content><author><name>Ramoji</name><uri>http://blogs.msdn.com/Ramoji/ProfileUrlRedirect.ashx</uri></author></entry><entry><title>Failed to open package file due to error 0x80070020. The process cannot access the file because it is being used by another process. This happens when loading a package and the file cannot be opened or loaded correctly into the XML document.</title><link rel="alternate" type="text/html" href="http://blogs.msdn.com/b/ramoji/archive/2009/08/28/failed-to-open-package-file-due-to-error-0x80070020-the-process-cannot-access-the-file-because-it-is-being-used-by-another-process-this-happens-when-loading-a-package-and-the-file-cannot-be-opened-or-loaded-correctly-into-the.aspx" /><id>http://blogs.msdn.com/b/ramoji/archive/2009/08/28/failed-to-open-package-file-due-to-error-0x80070020-the-process-cannot-access-the-file-because-it-is-being-used-by-another-process-this-happens-when-loading-a-package-and-the-file-cannot-be-opened-or-loaded-correctly-into-the.aspx</id><published>2009-08-28T18:00:00Z</published><updated>2009-08-28T18:00:00Z</updated><content type="html">&lt;P&gt;This error message comes while performing one (Or both) of the following actions.&lt;/P&gt;
&lt;P&gt;1.&amp;nbsp;Run SSIS Package using dtexec.exe (Either from a command file or&amp;nbsp;through a Job running on SQL Server 2008)&lt;/P&gt;
&lt;P&gt;2. Open SSIS package using&amp;nbsp;VS2008 or BIDS&lt;/P&gt;
&lt;P&gt;If you have a log file for the job, the exact error essage&lt;EM&gt;&amp;nbsp;&lt;/EM&gt;you see would be as follows&lt;EM&gt;:&lt;/EM&gt;&lt;/P&gt;
&lt;P&gt;&lt;EM&gt;-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------&lt;/EM&gt;&lt;/P&gt;
&lt;P&gt;&lt;EM&gt;Microsoft (R) SQL Server Execute Package Utility&lt;BR&gt;Version 10.0.1600.22 for 32-bit&lt;BR&gt;Copyright (C) Microsoft Corp 1984-2005. All rights reserved.&lt;/EM&gt;&lt;/P&gt;
&lt;P&gt;&lt;EM&gt;Error:&amp;nbsp;&lt;BR&gt;&amp;nbsp;&amp;nbsp; Code: 0xC0011007&lt;BR&gt;&amp;nbsp;&amp;nbsp; Source: {95765D16-E9AA-4DDA-9932-9DF1281E1208} &lt;BR&gt;&amp;nbsp;&amp;nbsp; Description: Unable to load the package as XML because of package does not have a valid XML format. A specific XML parser error will be posted.&lt;BR&gt;End Error&lt;BR&gt;Error:&amp;nbsp;&lt;BR&gt;&amp;nbsp;&amp;nbsp; Code: 0xC0011002&lt;BR&gt;&amp;nbsp;&amp;nbsp; Source: {95765D16-E9AA-4DDA-9932-9DF1281E1208} &lt;BR&gt;&amp;nbsp;&amp;nbsp; Description: Failed to open package file "E:\MyPackage.dtsx" due to error 0x80070020 "The process cannot access the file because it is being used by another process.".&amp;nbsp; This happens when loading a package and the file cannot be opened or loaded correctly into the XML document. This can be the result of either providing an incorrect file name was specified when calling LoadPackage or the XML file was specified and has an incorrect format.&lt;BR&gt;End Error&lt;BR&gt;Could not load package "E:\MyPackage.dtsx" because of error 0xC0011002.&lt;BR&gt;Description: Failed to open package file "E:\MyPackage.dtsx" due to error 0x80070020 "The process cannot access the file because it is being used by another process.".&amp;nbsp; This happens when loading a package and the file cannot be opened or loaded correctly into the XML document. This can be the result of either providing an incorrect file name was specified when calling LoadPackage or the XML file was specified and has an incorrect format.&lt;BR&gt;&lt;/EM&gt;Source: {95765D16-E9AA-4DDA-9932-9DF1281E1208}&lt;/P&gt;
&lt;P&gt;&lt;BR&gt;&lt;EM&gt;-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------&lt;/EM&gt;&lt;/P&gt;
&lt;P&gt;&lt;STRONG&gt;Fix:&lt;/STRONG&gt;&amp;nbsp;The fix is&amp;nbsp;same as the one I explained in my other &lt;A title="Package migration from version 3 to version 2 failed with error 0xC001700A. The version number in the package is not valid. The version number cannot be greater than current version number" href="http://blogs.msdn.com/ramoji/archive/2008/12/24/package-migration-from-version-3-to-version-2-failed-with-error-0xc001700a-the-version-number-in-the-package-is-not-valid-the-version-number-cannot-be-greater-than-current-version-number.aspx" mce_href="http://blogs.msdn.com/ramoji/archive/2008/12/24/package-migration-from-version-3-to-version-2-failed-with-error-0xc001700a-the-version-number-in-the-package-is-not-valid-the-version-number-cannot-be-greater-than-current-version-number.aspx"&gt;&lt;STRONG&gt;blog&lt;/STRONG&gt;&lt;/A&gt;. The physical path&amp;nbsp;of SQL Server 2008's DTEXEC.exe should appear first in the PATH environment variable.&lt;/P&gt;
&lt;P&gt;&lt;STRONG&gt;&lt;/STRONG&gt;&amp;nbsp;&lt;/P&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=9888533" width="1" height="1"&gt;</content><author><name>Ramoji</name><uri>http://blogs.msdn.com/Ramoji/ProfileUrlRedirect.ashx</uri></author></entry><entry><title>Checkin cannot proceed because the policy requirements have not been satisfied.</title><link rel="alternate" type="text/html" href="http://blogs.msdn.com/b/ramoji/archive/2009/08/26/checkin-cannot-proceed-because-the-policy-requirements-have-not-been-satisfied.aspx" /><id>http://blogs.msdn.com/b/ramoji/archive/2009/08/26/checkin-cannot-proceed-because-the-policy-requirements-have-not-been-satisfied.aspx</id><published>2009-08-26T16:45:00Z</published><updated>2009-08-26T16:45:00Z</updated><content type="html">&lt;P&gt;I got this message while checking-in a file&amp;nbsp;after the fresh installation of&amp;nbsp;Visual Studio 2008 Professional and&amp;nbsp;TFS client.&lt;/P&gt;
&lt;P&gt;This message disappeared&amp;nbsp;after installing VSTS 2008 Power Tools. The download link is provided for your quick reference here.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;A href="http://www.microsoft.com/downloads/details.aspx?FamilyId=FBD14EEA-781F-45A1-8C46-9F6BA2F68BF0&amp;amp;displaylang=en" mce_href="http://www.microsoft.com/downloads/details.aspx?FamilyId=FBD14EEA-781F-45A1-8C46-9F6BA2F68BF0&amp;amp;displaylang=en"&gt;http://www.microsoft.com/downloads/details.aspx?FamilyId=FBD14EEA-781F-45A1-8C46-9F6BA2F68BF0&amp;amp;displaylang=en&lt;/A&gt;&lt;/P&gt;
&lt;P&gt;Please share your feedback if the same fix has helped you.&lt;/P&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=9885331" width="1" height="1"&gt;</content><author><name>Ramoji</name><uri>http://blogs.msdn.com/Ramoji/ProfileUrlRedirect.ashx</uri></author></entry><entry><title>Transfer permissions between objects in SQL Server 2008</title><link rel="alternate" type="text/html" href="http://blogs.msdn.com/b/ramoji/archive/2009/07/02/transfer-permissions-between-objects-in-sql-server-2008.aspx" /><id>http://blogs.msdn.com/b/ramoji/archive/2009/07/02/transfer-permissions-between-objects-in-sql-server-2008.aspx</id><published>2009-07-02T16:39:00Z</published><updated>2009-07-02T16:39:00Z</updated><content type="html">&lt;P&gt;Sometimes we have to transfer the permissions from one object to another. Here the object could be a table or view. We can write&amp;nbsp; a straight forward script using GRANT and REVOKE statements if this requirement is for one or two objects. But what if more number of objects are involved and the permissions that exist at the time of development might change by the time you deploy the code in production. What I mean is, if you get a list of permissions that already exist on these tables from production and create scripts based on that, there is no guarantee that the same permissions exist when this script goes to production. Obviously, this results in the failure of the script. So, we need an intelligent script rather than a static script in this scenario.&amp;nbsp; &lt;/P&gt;
&lt;P&gt;Let us consider a scenario in which a bunch of tables are there and access to these tables by down stream systems is controlled by some database roles. Now, these tables have to be renamed due to some business reason without breaking the downstream systems. What we typically do in this case is, rename the tables using sp_rename and create views with the old table names on top of the renamed tables. The backward compatibility is maintained as we are creating the views with old table names. The permissions given to the database roles on the old table names will be automatically carried over to the newly renamed tables as a part of the renaming itself. But downstream systems still cannot access the views because the permissions exist on the newly renamed tables have to be explicitly transferred to the views. This is where the need comes for a dynamic script that does the permissions transfer from one object to another.&amp;nbsp; &lt;/P&gt;
&lt;P&gt;So, here is a generic script that would come handy in this type of scenarios. This SP transfers the permissions from an object (@FromObjectName parameter) to another object (@ToObjectName parameter). Appreciate your feedback if you feel this is useful.&lt;/P&gt;
&lt;P&gt;CREATE PROC [dbo].[ResetPermsOnObject] (&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;BR&gt;&amp;nbsp;@DBName sysname,&amp;nbsp;&amp;nbsp; &lt;BR&gt;&amp;nbsp;@SchemaName sysname = 'dbo',&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;BR&gt;&amp;nbsp;@ToObjectName sysname,&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;BR&gt;&amp;nbsp;@FromObjectName sysname &lt;BR&gt;)&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;BR&gt;WITH RECOMPILE&amp;nbsp;&amp;nbsp; &lt;BR&gt;AS&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;BR&gt;&amp;nbsp; &lt;BR&gt;BEGIN&amp;nbsp; &lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;BR&gt;SET NOCOUNT ON&amp;nbsp; &lt;BR&gt;&amp;nbsp; &lt;BR&gt;DECLARE @ObjectName sysname&amp;nbsp; &lt;BR&gt;DECLARE @ErrorMessage NVARCHAR(4000)&amp;nbsp; &lt;BR&gt;DECLARE @SQL nvarchar(4000)&amp;nbsp; &lt;BR&gt;DECLARE @RetVal Int&amp;nbsp; &lt;BR&gt;DECLARE @CurCount Int &lt;BR&gt;DECLARE @MaxCount Int&lt;BR&gt;DECLARE @Grantee sysname&lt;BR&gt;DECLARE @Action NVarchar(20)&lt;BR&gt;DECLARE @PermList Table&lt;BR&gt;(&lt;BR&gt;&amp;nbsp;Id Int IDENTITY(1,1),&lt;BR&gt;&amp;nbsp;[Owner] sysname,&lt;BR&gt;&amp;nbsp;[Object] sysname,&lt;BR&gt;&amp;nbsp;Grantee sysname,&lt;BR&gt;&amp;nbsp;Gantor sysname,&lt;BR&gt;&amp;nbsp;ProtectType NVarchar(10),&lt;BR&gt;&amp;nbsp;[Action] NVarchar(20), &lt;BR&gt;&amp;nbsp;Grantor sysname&lt;BR&gt;) &lt;/P&gt;
&lt;P mce_keep="true"&gt;-------------Validate arguments----------------------&amp;nbsp;&amp;nbsp; &lt;BR&gt;&amp;nbsp; &lt;BR&gt;IF(@DBName IS NULL)&amp;nbsp; &lt;BR&gt;BEGIN&amp;nbsp; &lt;BR&gt;&amp;nbsp;SELECT @ErrorMessage = 'Database Name must be supplied.'&amp;nbsp;&amp;nbsp; &lt;BR&gt;&amp;nbsp;GOTO ABEND&amp;nbsp; &lt;BR&gt;END&amp;nbsp; &lt;BR&gt;&amp;nbsp; &lt;BR&gt;IF(@ToObjectName IS NULL)&amp;nbsp; &lt;BR&gt;BEGIN&amp;nbsp; &lt;BR&gt;&amp;nbsp;SELECT @ErrorMessage = 'Old Object Name must be supplied.'&amp;nbsp;&amp;nbsp; &lt;BR&gt;&amp;nbsp;GOTO ABEND&amp;nbsp; &lt;BR&gt;END&amp;nbsp; &lt;BR&gt;&amp;nbsp; &lt;BR&gt;IF(@FromObjectName IS NULL)&amp;nbsp; &lt;BR&gt;BEGIN&amp;nbsp; &lt;BR&gt;&amp;nbsp;SELECT @ErrorMessage = 'New Object Name must be supplied.'&amp;nbsp;&amp;nbsp; &lt;BR&gt;&amp;nbsp;GOTO ABEND&amp;nbsp; &lt;BR&gt;END &lt;BR&gt;&amp;nbsp; &lt;BR&gt;--Check for the existence of the Database&amp;nbsp; &lt;BR&gt;IF NOT EXISTS(SELECT Name FROM sys.databases where Name &lt;A href="mailto:=@DBName"&gt;=@DBName&lt;/A&gt;) &lt;BR&gt;BEGIN &lt;BR&gt;&amp;nbsp;SET @ErrorMessage = 'The specified Database does not exist'&amp;nbsp;&lt;BR&gt;&amp;nbsp;GOTO ABEND&lt;BR&gt;END&lt;BR&gt;&amp;nbsp; &lt;BR&gt;--Check for the existence of the Schema&amp;nbsp; &lt;BR&gt;IF(upper(@SchemaName) &amp;lt;&amp;gt; 'DBO')&amp;nbsp; &lt;BR&gt;BEGIN&amp;nbsp; &lt;BR&gt;&amp;nbsp;SET @SQL = 'SELECT @RetVal = COUNT(*) FROM ' + QUOTENAME(@DBName) + '.sys.schemas WHERE name = ''' + @SchemaName + ''''&amp;nbsp; &lt;BR&gt;&amp;nbsp;BEGIN TRY&amp;nbsp; &lt;BR&gt;&amp;nbsp; EXEC sp_executesql @SQL,N'@RetVal Bit OUTPUT',@RetVal OUTPUT&amp;nbsp; &lt;BR&gt;&amp;nbsp;END TRY&amp;nbsp; &lt;BR&gt;&amp;nbsp;BEGIN CATCH&amp;nbsp; &lt;BR&gt;&amp;nbsp; SELECT @ErrorMessage = ERROR_MESSAGE()&amp;nbsp;&amp;nbsp; &lt;BR&gt;&amp;nbsp; GOTO ABEND&amp;nbsp; &lt;BR&gt;&amp;nbsp;END CATCH&amp;nbsp; &lt;BR&gt;&amp;nbsp;IF(@RetVal = 0)&amp;nbsp; &lt;BR&gt;&amp;nbsp;BEGIN&amp;nbsp; &lt;BR&gt;&amp;nbsp; SELECT @ErrorMessage = 'No Schema with the name ' + @SchemaName + ' exists in the Database ' + @DBName&amp;nbsp;&amp;nbsp; &lt;BR&gt;&amp;nbsp; GOTO ABEND&amp;nbsp; &lt;BR&gt;&amp;nbsp;END&amp;nbsp;&amp;nbsp; &lt;BR&gt;END&amp;nbsp; &lt;BR&gt;&amp;nbsp; &lt;BR&gt;-------------Check for the validity of all the Objects----------------------&amp;nbsp; &lt;BR&gt;&amp;nbsp; &lt;BR&gt;&amp;nbsp;--Check for existence of the Old object&amp;nbsp; &lt;BR&gt;&amp;nbsp;SET @SQL = 'SELECT @RetVal=COUNT(*) FROM ' + QUOTENAME(@DBName) + '.sys.Objects WHERE name = ''' + @ToObjectName + ''''&amp;nbsp; &lt;BR&gt;&amp;nbsp;BEGIN TRY&amp;nbsp; &lt;BR&gt;&amp;nbsp; EXEC sp_executesql @SQL,N'@RetVal Int OUTPUT',@RetVal OUTPUT&amp;nbsp; &lt;BR&gt;&amp;nbsp;END TRY&amp;nbsp; &lt;BR&gt;&amp;nbsp;BEGIN CATCH&amp;nbsp; &lt;BR&gt;&amp;nbsp; SELECT @ErrorMessage = ERROR_MESSAGE()&amp;nbsp;&amp;nbsp; &lt;BR&gt;&amp;nbsp; GOTO ABEND&amp;nbsp; &lt;BR&gt;&amp;nbsp;END CATCH&amp;nbsp; &lt;BR&gt;&amp;nbsp; &lt;BR&gt;&amp;nbsp;IF(@RetVal = 0)&amp;nbsp; &lt;BR&gt;&amp;nbsp;BEGIN&amp;nbsp; &lt;BR&gt;&amp;nbsp; SELECT @ErrorMessage = 'No object with the name ' + @ToObjectName + ' exists in the Database ' + @DBName&amp;nbsp;&amp;nbsp; &lt;BR&gt;&amp;nbsp; GOTO ABEND&amp;nbsp; &lt;BR&gt;&amp;nbsp;END&amp;nbsp;&amp;nbsp; &lt;/P&gt;
&lt;P mce_keep="true"&gt;&amp;nbsp;--Check for existence of the New object&amp;nbsp; &lt;BR&gt;&amp;nbsp;SET @SQL = 'SELECT @RetVal=COUNT(*) FROM ' + QUOTENAME(@DBName) + '.sys.Objects WHERE name = ''' + @FromObjectName + ''''&amp;nbsp; &lt;BR&gt;&amp;nbsp;BEGIN TRY&amp;nbsp; &lt;BR&gt;&amp;nbsp; EXEC sp_executesql @SQL,N'@RetVal Int OUTPUT',@RetVal OUTPUT&amp;nbsp; &lt;BR&gt;&amp;nbsp;END TRY&amp;nbsp; &lt;BR&gt;&amp;nbsp;BEGIN CATCH&amp;nbsp; &lt;BR&gt;&amp;nbsp; SELECT @ErrorMessage = ERROR_MESSAGE()&amp;nbsp;&amp;nbsp; &lt;BR&gt;&amp;nbsp; GOTO ABEND&amp;nbsp; &lt;BR&gt;&amp;nbsp;END CATCH&amp;nbsp; &lt;BR&gt;&amp;nbsp; &lt;BR&gt;&amp;nbsp;IF(@RetVal = 0)&amp;nbsp; &lt;BR&gt;&amp;nbsp;BEGIN&amp;nbsp; &lt;BR&gt;&amp;nbsp; SELECT @ErrorMessage = 'No object with the name ' + @FromObjectName + ' exists in the Database ' + @DBName&amp;nbsp;&amp;nbsp; &lt;BR&gt;&amp;nbsp; GOTO ABEND&amp;nbsp; &lt;BR&gt;&amp;nbsp;END&amp;nbsp;&amp;nbsp; &lt;BR&gt;&amp;nbsp;&amp;nbsp; &lt;BR&gt;-------Check whether any DBRoles are given permissions or not --------------------------------------------&lt;/P&gt;
&lt;P mce_keep="true"&gt;&amp;nbsp;SET @SQL = 'SELECT @RetVal = COUNT(sdp.name) FROM ' + QUOTENAME(@DBName) + '.sys.sysprotects sp '&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;+ ' INNER JOIN ' + QUOTENAME(@DBName) + '.sys.sysobjects so ON sp.id = so.id '&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;+ ' INNER JOIN ' + QUOTENAME(@DBName) + '.sys.database_principals sdp ON sdp.Principal_Id = sp.uid'&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;+ ' WHERE so.Name = ''' + @FromObjectName + ''''&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;BR&gt;&amp;nbsp;EXEC sp_executesql @SQL,N'@RetVal Bit OUTPUT',@RetVal OUTPUT&lt;BR&gt;&amp;nbsp;IF(@RetVal &amp;lt;= 0)&lt;BR&gt;&amp;nbsp;BEGIN&lt;BR&gt;&amp;nbsp;&amp;nbsp;PRINT 'No roles are granted permissions on the object ' + @FromObjectName&lt;BR&gt;&amp;nbsp;&amp;nbsp;GOTO FINAL&lt;BR&gt;&amp;nbsp;END&amp;nbsp;&amp;nbsp; &lt;BR&gt;&amp;nbsp;&amp;nbsp; &lt;BR&gt;----------Get the permissions defined on the old object------------------------------------------------------&lt;BR&gt;&amp;nbsp;SET @SQL = 'Use ' + QUOTENAME(@DBName) + '; EXEC sp_helprotect ' + QUOTENAME(@SchemaName + '.' + @FromObjectName)&lt;BR&gt;&amp;nbsp;&lt;BR&gt;&amp;nbsp;INSERT INTO @PermList&lt;BR&gt;&amp;nbsp;EXEC sp_executesql @SQL&lt;BR&gt;&amp;nbsp;&lt;BR&gt;----Now loop through all the roles and assign the permissions to the old Object ------------------------------&lt;BR&gt;&amp;nbsp;&lt;BR&gt;&amp;nbsp;SELECT @CurCount = Min(Id),@MaxCount = Max(Id) FROM @PermList&lt;BR&gt;&amp;nbsp;&lt;BR&gt;&amp;nbsp;WHILE(@CurCount &amp;lt;= @MaxCount)&lt;BR&gt;&amp;nbsp;BEGIN&lt;BR&gt;&amp;nbsp;&amp;nbsp;SELECT @Action = [Action], @Grantee = Grantee FROM @PermList WHERE Id = @CurCount&lt;BR&gt;&amp;nbsp;&amp;nbsp;&lt;BR&gt;&amp;nbsp;&amp;nbsp;SET @SQL = 'USE ' + QUOTENAME(@DBName) + ';GRANT ' + @Action + ' ON OBJECT::' + QUOTENAME(@SchemaName) + '.' + QUOTENAME(@ToObjectName) + ' TO ' + QUOTENAME(@Grantee)&lt;BR&gt;&amp;nbsp;&amp;nbsp;EXEC(@SQL)&lt;BR&gt;&amp;nbsp;&amp;nbsp;IF(@@ERROR &amp;lt;&amp;gt; 0) &lt;BR&gt;&amp;nbsp;&amp;nbsp;BEGIN&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;SET @ErrorMessage = 'Unbale to grant permissions on ' + QUOTENAME(@ToObjectName) + ' to the role ' + QUOTENAME(@Grantee)&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;GOTO ABEND&lt;BR&gt;&amp;nbsp;&amp;nbsp;END&amp;nbsp;&amp;nbsp;&lt;BR&gt;&amp;nbsp;&amp;nbsp;&lt;BR&gt;&amp;nbsp;&amp;nbsp;SET @SQL = 'USE ' + QUOTENAME(@DBName) + ';REVOKE ' + @Action + ' ON OBJECT::' + QUOTENAME(@SchemaName) + '.' + QUOTENAME(@FromObjectName) + ' FROM ' + QUOTENAME(@Grantee)&lt;BR&gt;&amp;nbsp;&amp;nbsp;EXEC (@SQL)&lt;BR&gt;&amp;nbsp;&amp;nbsp;IF(@@ERROR &amp;lt;&amp;gt; 0) &lt;BR&gt;&amp;nbsp;&amp;nbsp;BEGIN&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;SET @ErrorMessage = 'Unbale to revoke permissions on Object ' + QUOTENAME(@ToObjectName) + ' from the role ' + QUOTENAME(@Grantee)&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;GOTO ABEND&lt;BR&gt;&amp;nbsp;&amp;nbsp;END&lt;BR&gt;&amp;nbsp;&amp;nbsp;&lt;BR&gt;&amp;nbsp;&amp;nbsp;PRINT 'Permissions are successfully applied on ' + QUOTENAME(@ToObjectName) + ' TO the role ' + QUOTENAME(@Grantee)&lt;BR&gt;&amp;nbsp;&amp;nbsp;SET @CurCount = @CurCount + 1&amp;nbsp; &amp;nbsp;&lt;BR&gt;&amp;nbsp;END&lt;/P&gt;
&lt;P mce_keep="true"&gt;&amp;nbsp;RETURN&amp;nbsp; &lt;BR&gt;&amp;nbsp; &lt;BR&gt;ABEND:&amp;nbsp; &lt;BR&gt;&amp;nbsp;RAISERROR 500001 @ErrorMessage&amp;nbsp; &lt;BR&gt;FINAL:&amp;nbsp; &lt;BR&gt;&amp;nbsp;RETURN&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;BR&gt;END&amp;nbsp; &lt;/P&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=9814122" width="1" height="1"&gt;</content><author><name>Ramoji</name><uri>http://blogs.msdn.com/Ramoji/ProfileUrlRedirect.ashx</uri></author></entry><entry><title>The AcquireConnection method call to the connection manager failed with error code 0xC0202009</title><link rel="alternate" type="text/html" href="http://blogs.msdn.com/b/ramoji/archive/2009/03/10/the-acquireconnection-method-call-to-the-connection-manager-failed-with-error-code-0xc0202009.aspx" /><id>http://blogs.msdn.com/b/ramoji/archive/2009/03/10/the-acquireconnection-method-call-to-the-connection-manager-failed-with-error-code-0xc0202009.aspx</id><published>2009-03-10T08:15:00Z</published><updated>2009-03-10T08:15:00Z</updated><content type="html">&lt;p&gt;Sometimes the actual error lies somewhere and the error message directs us to look at something else. We end up wasting time in this process&amp;nbsp;as the error message diverted us.&amp;nbsp;Recently, we came across one such kind of scenario while&amp;nbsp;calling a SSIS package in one of the Job steps on SQL Server 2008. The details are as follows.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Error: &lt;/strong&gt;Login failed for user 'Domain\alias'. An OLE DB record is available. Source: "Microsoft SQL Server Native Client 10.0" Hresult: 0x80004005 Description: "Cannot open database "MyDatabase" requested by the login. The login failed.". End Error Error: 2009-02-26 03:08:23.93 Code: 0xC020801C Source: DFT-MyTask OLE DB Source [1] Description: SSIS Error Code DTS_E_CANNOTACQUIRECONNECTIONFROMCONNECTIONMANAGER. The AcquireConnection method call to the connection manager "MyServer.MyDatabase" failed with error code 0xC0202009. There may be error messages posted before this with more information on why the AcquireConnection method call failed. End Error Error: 2009-02-26 03:08:23.93 Code: 0xC0047017 Source: DFT-MyTask SSIS.Pipeline Description: component "OLE DB Source" (1) failed validation and returned error code 0xC020801C. End Error Progress: 2009-02-26 03:08:23.93 Source: DFT-MyTask Validating: 50% complete End Progress Error: 2009-02-26 03:08:23.93 Code: 0xC004700C Source: DFT-MyTask SSIS.Pipeline Description: One or more component failed validation. End Error Error&amp;nbsp;&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Job Logic:&lt;/strong&gt; We are using a script task to dynamically set the connection manager. We are pulling data from a source server using a select query and putting it into a table on a destination server. We&amp;nbsp;are surprised to see login failed error in the first part of the message. Because, the account "Domain\alias" is a sysadmin on the source as well as destination server and the job is also running under the same account. &lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Analysis: &lt;/strong&gt;Since the account is sysadmin,&amp;nbsp;the error message is misleading. Also, the second&amp;nbsp;message was of no use as it didn't detail why it couln't acquire connection inspite of having the right permissions. Interestingly, the crux lies in the last part of the message where it says validation failed.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Fix:&lt;/strong&gt;&amp;nbsp;After breaking our heads why the validation has failed, we couldn't find any reason but noticed that the DFT-MyTask has "DelayValidation" property set to false in the package. So, we changed the DelayValidation property of DFT-MyTask to true and re-ran the job and it succeeded.&amp;nbsp;&amp;nbsp;&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Root Cause: &lt;/strong&gt;As per our understanding&lt;strong&gt;, &lt;/strong&gt;if DelayValidation is not set to true,&lt;strong&gt; &lt;/strong&gt;SSIS engine uses the design time values of a task until it actually runs a task. Since we are dynamically setting the connection manager, instead of using the dynamically set value (Which it uses anayway while running the task), it tried to validate the task with the design time values set for the connection manager. Unfortunately, the service account with which the job is running doesn't have access to the server and database set during the design time for the connection manager. So, the validation of the task failed causing the job to fail.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=9468702" width="1" height="1"&gt;</content><author><name>Ramoji</name><uri>http://blogs.msdn.com/Ramoji/ProfileUrlRedirect.ashx</uri></author></entry><entry><title>General Network error. Check your network documentation.</title><link rel="alternate" type="text/html" href="http://blogs.msdn.com/b/ramoji/archive/2008/12/24/general-network-error-check-your-network-documentation.aspx" /><id>http://blogs.msdn.com/b/ramoji/archive/2008/12/24/general-network-error-check-your-network-documentation.aspx</id><published>2008-12-24T09:42:00Z</published><updated>2008-12-24T09:42:00Z</updated><content type="html">&lt;P&gt;This is a proper netwrok error and has nothing to do with the coding if any of your jobs/queries/packages fail with this message.&lt;/P&gt;
&lt;P&gt;Please refer the following article for the workaround.&lt;/P&gt;
&lt;P&gt;&lt;A href="http://support.microsoft.com/kb/942861/en-us" mce_href="http://support.microsoft.com/kb/942861/en-us"&gt;http://support.microsoft.com/kb/942861/en-us&lt;/A&gt;&lt;/P&gt;
&lt;P&gt;Another work around we tried and succeeded in our project was as follows:&lt;/P&gt;
&lt;P&gt;There is something called Network Speed setting which is usually set to&amp;nbsp;AUTO or a fixed value. You can check this from Start-&amp;gt;Control Panel-&amp;gt;Network Connections-&amp;gt;Local Area Connection-&amp;gt;Properties-&amp;gt;Configure-&amp;gt;Advanced-&amp;gt;Speed &amp;amp;Duplex property. Change it to 100 MBPS full or whatever value that matches the configuration of the n/w port on the switch side. It solved the issue for us.&lt;/P&gt;
&lt;P mce_keep="true"&gt;&amp;nbsp;&lt;/P&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=9251529" width="1" height="1"&gt;</content><author><name>Ramoji</name><uri>http://blogs.msdn.com/Ramoji/ProfileUrlRedirect.ashx</uri></author></entry><entry><title>Package migration from version 3 to version 2 failed with error 0xC001700A. The version number in the package is not valid. The version number cannot be greater than current version number.</title><link rel="alternate" type="text/html" href="http://blogs.msdn.com/b/ramoji/archive/2008/12/24/package-migration-from-version-3-to-version-2-failed-with-error-0xc001700a-the-version-number-in-the-package-is-not-valid-the-version-number-cannot-be-greater-than-current-version-number.aspx" /><id>http://blogs.msdn.com/b/ramoji/archive/2008/12/24/package-migration-from-version-3-to-version-2-failed-with-error-0xc001700a-the-version-number-in-the-package-is-not-valid-the-version-number-cannot-be-greater-than-current-version-number.aspx</id><published>2008-12-24T09:05:00Z</published><updated>2008-12-24T09:05:00Z</updated><content type="html">&lt;P&gt;I guess at least once every SQL developer might have come across this error on SQL Server 2008 while running a SQL job that calls a package. &lt;/P&gt;
&lt;P&gt;&lt;STRONG&gt;Reason for the error: &lt;/STRONG&gt;Old version of the DTEXEC is picked up by SQL Server instead of the new one. That means, the exe shipped with 2005 is picked up when it is expected to use&amp;nbsp;the one shipped with 2008.&amp;nbsp;So, obviously this happens when SQL Server 2008 is running along with SQL Server 2005 on the same machine. As a result of this, we end up with two versions of DTEXEC executables.&amp;nbsp;One residing in SQL Server 2005 path ("C:\Program Files\Microsoft SQL Server\90\DTS\Binn") and the other in SQL Server 2008 path ("C:\Program Files\Microsoft SQL Server\100\DTS\Binn"). &lt;/P&gt;
&lt;P&gt;&lt;STRONG&gt;Fix for the error: &lt;/STRONG&gt;There are three&amp;nbsp;workarounds to correct this.&lt;/P&gt;
&lt;P&gt;1. Hard code the path of SQL Server 2008's DTEXEC&amp;nbsp;while calling the SSIS package as shown below.&lt;/P&gt;
&lt;P&gt;C:\Program Files\Microsoft SQL Server\100\DTS\Binn\DTEXEC.exe /F "D:\MyFolder\MyPackage.dtsx" &lt;/P&gt;
&lt;P&gt;2. Rename the old exe in the 2005 path to a different name (Example:- C:\Program Files\Microsoft SQL Server\90\DTS\Binn\DTEXEC_Old.exe)&lt;/P&gt;
&lt;P&gt;3. Go to PATH environmental variable and&amp;nbsp;edit it in such a way&amp;nbsp;that "C:\Program Files\Microsoft SQL Server\100\DTS\Binn" path appears well before the "C:\Program Files\Microsoft SQL Server\90\DTS\Binn" path. &lt;/P&gt;
&lt;P mce_keep="true"&gt;Please drop me a note if this has helped you. &lt;/P&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=9251479" width="1" height="1"&gt;</content><author><name>Ramoji</name><uri>http://blogs.msdn.com/Ramoji/ProfileUrlRedirect.ashx</uri></author></entry><entry><title>How to open DTS packages in SQL Server 2008?</title><link rel="alternate" type="text/html" href="http://blogs.msdn.com/b/ramoji/archive/2008/10/16/how-to-open-dts-packages-in-sql-server-2008.aspx" /><id>http://blogs.msdn.com/b/ramoji/archive/2008/10/16/how-to-open-dts-packages-in-sql-server-2008.aspx</id><published>2008-10-16T08:11:00Z</published><updated>2008-10-16T08:11:00Z</updated><content type="html">&lt;P class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;&lt;SPAN style="COLOR: #1f497d"&gt;&lt;?xml:namespace prefix = o ns = "urn:schemas-microsoft-com:office:office" /&gt;&lt;o:p&gt;&lt;FONT face=Calibri size=3&gt;An error occurs if you try to open&amp;nbsp;a DTS package&amp;nbsp;from Leagcy --&amp;gt; Data Transformation Services in SSMS of 2008. The message says, &lt;STRONG&gt;SQL Server 2000 DTS Designer Components are required to edit&amp;nbsp;DTS packages. Install the special web download, "SQL Server 2000 DTS Designer Components" to use this feature. (Microsoft.SqlServer.DtsObjectExploreUI).&lt;/STRONG&gt;&lt;/FONT&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;&lt;SPAN style="COLOR: #1f497d"&gt;&lt;o:p&gt;&lt;STRONG&gt;&lt;FONT face=Calibri size=3&gt;&lt;/FONT&gt;&lt;/STRONG&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&amp;nbsp;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;&lt;SPAN style="COLOR: #1f497d"&gt;&lt;o:p&gt;&lt;FONT face=Calibri size=3&gt;Downloading the following software from Microsoft's download center and Installing&amp;nbsp;fixes this issue in most of the cases.&lt;/FONT&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;&lt;SPAN style="COLOR: #1f497d"&gt;&lt;o:p&gt;&lt;FONT face=Calibri size=3&gt;&lt;/FONT&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&amp;nbsp;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;&lt;SPAN style="COLOR: #1f497d"&gt;&lt;o:p&gt;&lt;FONT face=Calibri size=3&gt;1. Microsoft SQL Server 2005 Backward compatibility&lt;/FONT&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;&lt;SPAN style="COLOR: #1f497d"&gt;&lt;o:p&gt;&lt;FONT face=Calibri size=3&gt;2. SQL Server 2000 DTS Designer Components&lt;/FONT&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;&lt;SPAN style="COLOR: #1f497d"&gt;&lt;o:p&gt;&lt;FONT face=Calibri size=3&gt;&lt;/FONT&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&amp;nbsp;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;&lt;SPAN style="COLOR: #1f497d"&gt;&lt;o:p&gt;&lt;FONT face=Calibri size=3&gt;However, in some cases it doesn't solve the problem and the error re-appears even after installing the above software. &lt;/FONT&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;&lt;SPAN style="COLOR: #1f497d"&gt;&lt;o:p&gt;&lt;FONT face=Calibri size=3&gt;&lt;/FONT&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&amp;nbsp;&lt;/P&gt;&lt;SPAN style="COLOR: #1f497d"&gt;&lt;o:p&gt;&lt;FONT face=Calibri size=3&gt;
&lt;P class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;&lt;B&gt;&lt;SPAN style="COLOR: #1f497d"&gt;&lt;FONT size=3&gt;&lt;FONT face=Calibri&gt;Reason for this:&lt;o:p&gt;&lt;/o:p&gt;&lt;/FONT&gt;&lt;/FONT&gt;&lt;/SPAN&gt;&lt;/B&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;&lt;FONT size=3&gt;&lt;SPAN style="COLOR: #1f497d"&gt;&lt;FONT face=Calibri&gt;SQL Server uses the library (&lt;B&gt;sqlgui.dll&lt;/B&gt;) to open DTS package in GUI mode. This DLL comes with katmai (Located in &amp;lt;SQL Path&amp;gt;\100\Toos\Binn) also but this shouldn’t be used. The DLL that comes with SQL server 2000 (Located in in &amp;lt;SQL Path&amp;gt;\80\Toos\Binn) should be used. SQL server looks for the path of this DLL in the order in which the paths are defined in PATH environment variable. So, we need to make sure 80 comes before 100.&lt;/FONT&gt;&lt;/SPAN&gt;&lt;/FONT&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;&amp;nbsp;&lt;/FONT&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;SPAN style="COLOR: #1f497d"&gt;&lt;o:p&gt;&lt;FONT face=Calibri size=3&gt;&amp;nbsp;&lt;/FONT&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;&lt;SPAN style="COLOR: #1f497d"&gt;&lt;o:p&gt;&lt;FONT face=Calibri size=3&gt;Perform the following steps to fix the issue in such situation.&amp;nbsp;&lt;/FONT&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&amp;nbsp;Please note that this workaround should be used in Development environments only. Playing with the environment variable on Production systems might hamper some or the other application and hence avoid this in such cases.&lt;/P&gt;
&lt;OL&gt;
&lt;LI&gt;
&lt;DIV class=MsoListParagraph style="MARGIN: 0in 0in 0pt 0.5in; TEXT-INDENT: -0.25in; mso-list: l0 level1 lfo1"&gt;&lt;SPAN style="COLOR: #1f497d"&gt;&lt;FONT size=3&gt;&lt;FONT face=Calibri&gt;Make sure all the SQL Server Management Studio (SSMS) sessions are closed&lt;/FONT&gt;&lt;/FONT&gt;&lt;/SPAN&gt;&lt;/DIV&gt;&lt;/LI&gt;
&lt;LI&gt;
&lt;DIV class=MsoListParagraph style="MARGIN: 0in 0in 0pt 0.5in; TEXT-INDENT: -0.25in; mso-list: l0 level1 lfo1"&gt;&lt;SPAN style="COLOR: #1f497d"&gt;&lt;FONT size=3&gt;&lt;FONT face=Calibri&gt;Go to &amp;nbsp;ControlPanel --&amp;gt; System --&amp;gt; Advanced --&amp;gt; Environment variables&lt;/FONT&gt;&lt;/FONT&gt;&lt;/SPAN&gt;&lt;/DIV&gt;&lt;/LI&gt;
&lt;LI&gt;
&lt;DIV class=MsoListParagraph style="MARGIN: 0in 0in 0pt 0.5in; TEXT-INDENT: -0.25in; mso-list: l0 level1 lfo1"&gt;&lt;SPAN style="COLOR: #1f497d"&gt;&lt;FONT size=3&gt;&lt;FONT face=Calibri&gt;Update the PATH environment variable in such a way that the path “&lt;B&gt;C:\Program Files\Microsoft SQL Server\80\Tools\Binn\&lt;/B&gt;” appears before the “C:\Program Files\Microsoft SQL Server\100\...” paths. On the server, the folder might be Program Files X(86) instead of Program Files. Use the path accordingly.&lt;/FONT&gt;&lt;/FONT&gt;&lt;/SPAN&gt;&lt;/DIV&gt;&lt;/LI&gt;
&lt;LI&gt;
&lt;DIV class=MsoListParagraph style="MARGIN: 0in 0in 0pt 0.5in; TEXT-INDENT: -0.25in; mso-list: l0 level1 lfo1"&gt;&lt;FONT size=3&gt;&lt;SPAN style="COLOR: #1f497d"&gt;&lt;FONT face=Calibri&gt;Launch SSMS and open a DTS package from Legacy &lt;/FONT&gt;&lt;/SPAN&gt;&lt;SPAN style="COLOR: #1f497d; FONT-FAMILY: Wingdings"&gt;à&lt;/SPAN&gt;&lt;SPAN style="COLOR: #1f497d"&gt;&lt;FONT face=Calibri&gt; Data Transformation Services&lt;o:p&gt;&lt;/o:p&gt;&lt;/FONT&gt;&lt;/SPAN&gt;&lt;/FONT&gt;&lt;/DIV&gt;&lt;/LI&gt;
&lt;LI&gt;
&lt;DIV class=MsoListParagraph style="MARGIN: 0in 0in 0pt 0.5in; TEXT-INDENT: -0.25in; mso-list: l0 level1 lfo1"&gt;&lt;SPAN style="COLOR: #1f497d"&gt;&lt;FONT size=3&gt;&lt;FONT face=Calibri&gt;You will get some errors. Click OK. The package opens but the icons can’t be seen.&lt;o:p&gt;&lt;/o:p&gt;&lt;/FONT&gt;&lt;/FONT&gt;&lt;/SPAN&gt;&lt;/DIV&gt;&lt;/LI&gt;
&lt;LI&gt;
&lt;DIV class=MsoListParagraph style="MARGIN: 0in 0in 0pt 0.5in; TEXT-INDENT: -0.25in; mso-list: l0 level1 lfo1"&gt;&lt;SPAN style="COLOR: #1f497d; mso-fareast-font-family: Calibri; mso-bidi-font-family: Calibri"&gt;&lt;SPAN style="mso-list: Ignore"&gt;&lt;SPAN style="FONT: 7pt 'Times New Roman'"&gt;&amp;nbsp;&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;SPAN style="COLOR: #1f497d"&gt;&lt;FONT size=3&gt;&lt;FONT face=Calibri&gt;Just hover the mouse over the icons till you notice icons as white boxes&lt;o:p&gt;&lt;/o:p&gt;&lt;/FONT&gt;&lt;/FONT&gt;&lt;/SPAN&gt;&lt;/DIV&gt;&lt;/LI&gt;
&lt;LI&gt;
&lt;DIV class=MsoListParagraph style="MARGIN: 0in 0in 0pt 0.5in; TEXT-INDENT: -0.25in; mso-list: l0 level1 lfo1"&gt;&lt;SPAN style="COLOR: #1f497d"&gt;&lt;FONT size=3&gt;&lt;FONT face=Calibri&gt;Exit SSMS&lt;o:p&gt;&lt;/o:p&gt;&lt;/FONT&gt;&lt;/FONT&gt;&lt;/SPAN&gt;&lt;/DIV&gt;&lt;/LI&gt;
&lt;LI&gt;
&lt;DIV class=MsoListParagraph style="MARGIN: 0in 0in 0pt 0.5in; TEXT-INDENT: -0.25in; mso-list: l0 level1 lfo1"&gt;&lt;FONT size=3&gt;&lt;SPAN style="COLOR: #1f497d"&gt;&lt;FONT face=Calibri&gt;Again launch SSMS and open&amp;nbsp;the same&amp;nbsp;DTS package from Legacy &lt;/FONT&gt;&lt;/SPAN&gt;&lt;SPAN style="COLOR: #1f497d; FONT-FAMILY: Wingdings"&gt;à&lt;/SPAN&gt;&lt;SPAN style="COLOR: #1f497d"&gt;&lt;FONT face=Calibri&gt; Data Transformation Services. &lt;o:p&gt;&lt;/o:p&gt;&lt;/FONT&gt;&lt;/SPAN&gt;&lt;/FONT&gt;&lt;/DIV&gt;&lt;/LI&gt;
&lt;LI&gt;
&lt;DIV class=MsoListParagraph style="MARGIN: 0in 0in 0pt 0.5in; TEXT-INDENT: -0.25in; mso-list: l0 level1 lfo1"&gt;&lt;SPAN style="COLOR: #1f497d"&gt;&lt;FONT size=3&gt;&lt;FONT face=Calibri&gt;Package gets opened properly&lt;o:p&gt;&lt;/o:p&gt;&lt;/FONT&gt;&lt;/FONT&gt;&lt;/SPAN&gt;&lt;/DIV&gt;&lt;/LI&gt;&lt;/OL&gt;
&lt;P class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;&lt;SPAN style="COLOR: #1f497d"&gt;&lt;o:p&gt;&lt;FONT face=Calibri size=3&gt;&lt;/FONT&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;&lt;SPAN style="COLOR: #1f497d"&gt;&lt;FONT size=3&gt;&lt;FONT face=Calibri&gt;Sometimes steps from&amp;nbsp;4 to&amp;nbsp;8 have to be performed more than once if the error persists.&amp;nbsp;&lt;/FONT&gt;&lt;/FONT&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;&lt;FONT face=Calibri size=3&gt;&lt;SPAN style="COLOR: #1f497d"&gt;&lt;/SPAN&gt;&lt;/FONT&gt;&amp;nbsp;&lt;/P&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=9001465" width="1" height="1"&gt;</content><author><name>Ramoji</name><uri>http://blogs.msdn.com/Ramoji/ProfileUrlRedirect.ashx</uri></author></entry><entry><title>Reading DTS and SSIS packages programmatically</title><link rel="alternate" type="text/html" href="http://blogs.msdn.com/b/ramoji/archive/2008/09/29/how-to-read-a-dts-package-programmatically.aspx" /><id>http://blogs.msdn.com/b/ramoji/archive/2008/09/29/how-to-read-a-dts-package-programmatically.aspx</id><published>2008-09-29T15:33:00Z</published><updated>2008-09-29T15:33:00Z</updated><content type="html">&lt;P&gt;Reading a DTS/SSIS programmatically helps a lot in doing impact analysis.&amp;nbsp;Consider a scenario in which all the packages containing a particular table&amp;nbsp;or&amp;nbsp;stored procedure&amp;nbsp;need to identified.&amp;nbsp;Let me give&amp;nbsp;another usage scenario for this. The sql native clinet provider SQLNCLI.1 is no longer supported in SQL server 2008 and it has to be changed to SQLNCLI10.1. If you are migrating to SQL Server 2008 and the provider name has to be changed across all packages,&amp;nbsp;dynamically accessing the DTS/SSIS package using .NET&amp;nbsp;assemblies is the best way&amp;nbsp;to achieve this. Otherwise all the packages have to be opened manually for verifying and modifying the&amp;nbsp;tasks.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Let us see how we can do this using C#. Add the following references for accessing DTS/SSIS object model.&lt;/P&gt;
&lt;P&gt;1. Microsoft.sqlserver.Pipelinewrap (Physical location--&amp;gt; C:\Program Files\Microsoft SQL Server\90\SDK\Assemblies\Microsoft.SqlServer.DTSPipelineWrap.dll)&lt;/P&gt;
&lt;P&gt;2. Microsoft.sqlserver.ManagedDTS (Physical location--&amp;gt; C:\Program Files\Microsoft SQL Server\90\SDK\Assemblies\Microsoft.SQLServer.ManagedDTS.dll)&lt;/P&gt;
&lt;P&gt;3. Microsoft.sqlserver.ScriptTask (Physical location--&amp;gt; C:\Program Files\Microsoft SQL Server\90\DTS\Tasks\Microsoft.SqlServer.ScriptTask.dll)&lt;/P&gt;
&lt;P&gt;4. Microsoft.sqlserver.VSAHosting (Physical location--&amp;gt; C:\Program Files\Microsoft SQL Server\90\DTS\Binn\Microsoft.SqlServer.VSAHosting.dll)&lt;/P&gt;
&lt;P&gt;5. Select "Microsoft DTSPackage Object Library" from the COM tab in the references (Physical Location --&amp;gt; C:\Program Files\Microsoft SQL Server\80\Tools\Binn\DtsPkg.dll)&lt;/P&gt;
&lt;P&gt;6. Microsoft.sqlserver.Exec80PackageTask (Physical location--&amp;gt; C:\Program Files\Microsoft SQL Server\90\DTS\Tasks\Microsoft.SqlServer.Exec80PackageTask.dll)&lt;/P&gt;
&lt;P mce_keep="true"&gt;Use the following namespaces:&lt;/P&gt;&lt;FONT color=#0000ff size=2&gt;
&lt;P&gt;using&lt;/FONT&gt;&lt;FONT size=2&gt; Microsoft.SqlServer.Dts.Runtime;&lt;/P&gt;&lt;/FONT&gt;&lt;FONT color=#0000ff size=2&gt;
&lt;P&gt;using&lt;/FONT&gt;&lt;FONT size=2&gt; Microsoft.SqlServer.Dts.Pipeline.Wrapper;&lt;/P&gt;&lt;/FONT&gt;&lt;FONT color=#0000ff size=2&gt;
&lt;P&gt;using&lt;/FONT&gt;&lt;FONT size=2&gt; Microsoft.SqlServer.Dts.Tasks.Exec80PackageTask;&lt;/P&gt;&lt;/FONT&gt;&lt;FONT color=#0000ff size=2&gt;
&lt;P&gt;using&lt;/FONT&gt;&lt;FONT size=2&gt; Microsoft.SqlServer.Dts.Tasks.ScriptTask;&lt;/P&gt;&lt;/FONT&gt;
&lt;P mce_keep="true"&gt;&lt;U&gt;Now Load and access the DTS package that is physically stored on the file system:&lt;/U&gt;&lt;/P&gt;&lt;FONT color=#0000ff size=2&gt;
&lt;P&gt;string&lt;/FONT&gt;&lt;FONT size=2&gt; PkgLocation = &lt;/FONT&gt;&lt;FONT color=#a31515 size=2&gt;"E\\Test\\abcd.dts"&lt;/FONT&gt;&lt;FONT size=2&gt;;&lt;/FONT&gt;&lt;/P&gt;&lt;FONT size=2&gt;&lt;FONT size=2&gt;&lt;FONT color=#0000ff size=2&gt;
&lt;P&gt;string&lt;/FONT&gt;&lt;FONT size=2&gt; PkgPwd = &lt;/FONT&gt;&lt;FONT color=#a31515 size=2&gt;"abc123"&lt;/FONT&gt;&lt;FONT size=2&gt;;&lt;/P&gt;&lt;/FONT&gt;&lt;/FONT&gt;&lt;/FONT&gt;&lt;FONT size=2&gt;
&lt;P&gt;DTS.&lt;/FONT&gt;&lt;FONT color=#2b91af size=2&gt;PackageClass&lt;/FONT&gt;&lt;FONT size=2&gt; dtsPkg = &lt;/FONT&gt;&lt;FONT color=#0000ff size=2&gt;new&lt;/FONT&gt;&lt;FONT size=2&gt; DTS.&lt;/FONT&gt;&lt;FONT color=#2b91af size=2&gt;PackageClass&lt;/FONT&gt;&lt;FONT size=2&gt;();&lt;/P&gt;
&lt;P&gt;&lt;/FONT&gt;&lt;FONT color=#0000ff size=2&gt;object&lt;/FONT&gt;&lt;FONT size=2&gt; pVarPersistStgOfHost = &lt;/FONT&gt;&lt;FONT color=#0000ff size=2&gt;null&lt;/FONT&gt;&lt;FONT size=2&gt;;&lt;/P&gt;&lt;/FONT&gt;&lt;FONT size=2&gt;
&lt;P&gt;dtsPkg.LoadFromStorageFile(PkgLocation, PkgPwd, &lt;/FONT&gt;&lt;FONT color=#0000ff size=2&gt;null&lt;/FONT&gt;&lt;FONT size=2&gt;, &lt;/FONT&gt;&lt;FONT color=#0000ff size=2&gt;null&lt;/FONT&gt;&lt;FONT size=2&gt;, &lt;/FONT&gt;&lt;FONT color=#0000ff size=2&gt;null&lt;/FONT&gt;&lt;FONT size=2&gt;, &lt;/FONT&gt;&lt;FONT color=#0000ff size=2&gt;ref&lt;/FONT&gt;&lt;FONT size=2&gt; pVarPersistStgOfHost);&lt;/FONT&gt;&lt;/P&gt;&lt;FONT size=2&gt;
&lt;P&gt;&lt;/FONT&gt;&lt;FONT color=#2b91af size=2&gt;MessageBox&lt;/FONT&gt;&lt;FONT size=2&gt;.Show(dtsPkg.Name); //Get Package Name&lt;/P&gt;
&lt;P&gt;&lt;/FONT&gt;&lt;FONT color=#2b91af size=2&gt;MessageBox&lt;/FONT&gt;&lt;FONT size=2&gt;.Show(dtsPkg.Tasks.Count.ToString()); //Get number of tasks present in the package&lt;/P&gt;
&lt;P&gt;&lt;/FONT&gt;&lt;FONT color=#0000ff size=2&gt;for&lt;/FONT&gt;&lt;FONT size=2&gt; (&lt;/FONT&gt;&lt;FONT color=#0000ff size=2&gt;int&lt;/FONT&gt;&lt;FONT size=2&gt; i = 1; i &amp;lt;= dtsPkg.Tasks.Count; i++)&lt;/P&gt;
&lt;P&gt;{&lt;/P&gt;
&lt;P&gt;&lt;/FONT&gt;&lt;FONT color=#2b91af size=2&gt;MessageBox&lt;/FONT&gt;&lt;FONT size=2&gt;.Show(dtsPkg.Tasks.Item(i).Name); //Get Task Name&lt;/P&gt;
&lt;P&gt;&lt;/FONT&gt;&lt;FONT color=#2b91af size=2&gt;MessageBox&lt;/FONT&gt;&lt;FONT size=2&gt;.Show(dtsPkg.Tasks.Item(i).Description); //Get Task Description&lt;/P&gt;
&lt;P&gt;&lt;/FONT&gt;&lt;FONT color=#0000ff size=2&gt;for&lt;/FONT&gt;&lt;FONT size=2&gt; (&lt;/FONT&gt;&lt;FONT color=#0000ff size=2&gt;int&lt;/FONT&gt;&lt;FONT size=2&gt; j = 1; j &amp;lt;= dtsPkg.Tasks.Item(i).Properties.Count; j++)&lt;/P&gt;
&lt;P&gt;{&lt;/P&gt;
&lt;P&gt;&lt;/FONT&gt;&lt;FONT color=#2b91af size=2&gt;MessageBox&lt;/FONT&gt;&lt;FONT size=2&gt;.Show(dtsPkg.Tasks.Item(i).Properties.Item(j).Name); //Get property name&lt;/P&gt;
&lt;P&gt;&lt;/FONT&gt;&lt;FONT color=#0000ff size=2&gt;if&lt;/FONT&gt;&lt;FONT size=2&gt; (dtsPkg.Tasks.Item(i).Properties.Item(j).Value != &lt;/FONT&gt;&lt;FONT color=#0000ff size=2&gt;null&lt;/FONT&gt;&lt;FONT size=2&gt;)&lt;/P&gt;
&lt;P&gt;{&lt;/P&gt;
&lt;P&gt;&lt;/FONT&gt;&lt;FONT color=#2b91af size=2&gt;MessageBox&lt;/FONT&gt;&lt;FONT size=2&gt;.Show(dtsPkg.Tasks.Item(i).Properties.Item(j).Value.ToString()); //Get Property Value&lt;/P&gt;
&lt;P&gt;}&lt;/P&gt;
&lt;P&gt;}&lt;/P&gt;
&lt;P&gt;}&lt;/P&gt;
&lt;P mce_keep="true"&gt;&lt;U&gt;Now Load and access the SSIS package that is physically stored on the file system:&lt;/U&gt;&amp;nbsp;&lt;/P&gt;&lt;FONT size=2&gt;
&lt;P&gt;&lt;/FONT&gt;&lt;FONT color=#2b91af size=2&gt;&lt;FONT color=#0000ff&gt;&amp;nbsp;&lt;/FONT&gt;string&lt;FONT color=#000000 size=2&gt; PkgLocation = &lt;/FONT&gt;&lt;FONT color=#a31515 size=2&gt;"E\\Test\\abcd.dtsx"&lt;/FONT&gt;&lt;FONT color=#000000 size=2&gt;;&lt;/FONT&gt;&lt;/P&gt;&lt;FONT size=2&gt;&lt;FONT size=2&gt;&lt;FONT color=#0000ff size=2&gt;
&lt;P&gt;string&lt;/FONT&gt;&lt;FONT color=#000000 size=2&gt; PkgPwd = &lt;/FONT&gt;&lt;FONT color=#a31515 size=2&gt;"abc123"&lt;/FONT&gt;&lt;FONT color=#000000 size=2&gt;;&lt;/FONT&gt;&lt;/FONT&gt;&lt;/FONT&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;string strNewPackage = "Newabcd";&lt;/P&gt;&lt;FONT size=2&gt;
&lt;P&gt;Microsoft.SqlServer.Dts.Runtime.&lt;/FONT&gt;&lt;FONT color=#2b91af size=2&gt;Application&lt;/FONT&gt;&lt;FONT size=2&gt; ssisApplication;&lt;/P&gt;
&lt;P&gt;ssisApplication = &lt;/FONT&gt;&lt;FONT color=#0000ff size=2&gt;new&lt;/FONT&gt;&lt;FONT size=2&gt; Microsoft.SqlServer.Dts.Runtime.&lt;/FONT&gt;&lt;FONT color=#2b91af size=2&gt;Application&lt;/FONT&gt;&lt;FONT size=2&gt;();&lt;/P&gt;&lt;/FONT&gt;&lt;/FONT&gt;
&lt;P&gt;&lt;FONT color=#2b91af size=2&gt;Package&lt;/FONT&gt;&lt;FONT size=2&gt; dtsPkg;&lt;/FONT&gt;&lt;/P&gt;&lt;FONT size=2&gt;&lt;FONT size=2&gt;
&lt;P&gt;&lt;/FONT&gt;&lt;FONT color=#0000ff size=2&gt;if&lt;/FONT&gt;&lt;FONT size=2&gt; (PkgPwd != &lt;/FONT&gt;&lt;FONT color=#0000ff size=2&gt;null&lt;/FONT&gt;&lt;FONT size=2&gt;)&lt;/P&gt;
&lt;P&gt;{&lt;/P&gt;
&lt;P&gt;dtsApp.PackagePassword = PkgPwd;&lt;/P&gt;
&lt;P&gt;}&lt;/P&gt;&lt;FONT size=2&gt;
&lt;P&gt;PkgLocation = &lt;/FONT&gt;&lt;FONT color=#a31515 size=2&gt;@""&lt;/FONT&gt;&lt;FONT size=2&gt; + PkgLocation;&lt;/P&gt;
&lt;P&gt;&lt;/FONT&gt;&lt;FONT size=2&gt;dtsPkg = dtsApp.LoadPackage(PkgLocation, &lt;/FONT&gt;&lt;FONT color=#0000ff size=2&gt;null&lt;/FONT&gt;&lt;FONT size=2&gt;);&lt;/P&gt;&lt;FONT size=2&gt;
&lt;P&gt;&lt;/FONT&gt;&lt;FONT color=#0000ff size=2&gt;foreach&lt;/FONT&gt;&lt;FONT size=2&gt; (&lt;/FONT&gt;&lt;FONT color=#2b91af size=2&gt;Executable&lt;/FONT&gt;&lt;FONT size=2&gt; e1 &lt;/FONT&gt;&lt;FONT color=#0000ff size=2&gt;in&lt;/FONT&gt;&lt;FONT size=2&gt; exes)&lt;/P&gt;
&lt;P&gt;{&lt;/P&gt;
&lt;P&gt;&lt;/FONT&gt;&lt;FONT color=#2b91af size=2&gt;TaskHost&lt;/FONT&gt;&lt;FONT size=2&gt; T1 = (&lt;/FONT&gt;&lt;FONT color=#2b91af size=2&gt;TaskHost&lt;/FONT&gt;&lt;FONT size=2&gt;)e1;&lt;/P&gt;
&lt;P&gt;&lt;/FONT&gt;&lt;FONT color=#2b91af size=2&gt;DtsProperties&lt;/FONT&gt;&lt;FONT size=2&gt; dp = T1.Properties;&lt;/P&gt;
&lt;P&gt;&lt;/FONT&gt;&lt;FONT color=#0000ff size=2&gt;foreach&lt;/FONT&gt;&lt;FONT size=2&gt; (&lt;/FONT&gt;&lt;FONT color=#2b91af size=2&gt;DtsProperty&lt;/FONT&gt;&lt;FONT size=2&gt; p &lt;/FONT&gt;&lt;FONT color=#0000ff size=2&gt;in&lt;/FONT&gt;&lt;FONT size=2&gt; dp)&lt;/P&gt;
&lt;P&gt;{&lt;/P&gt;
&lt;P&gt;&lt;/FONT&gt;&lt;FONT color=#2b91af size=2&gt;MessageBox&lt;/FONT&gt;&lt;FONT size=2&gt;.Show(T1.Name.ToString()); //Get Task Name&lt;/P&gt;
&lt;P&gt;&lt;/FONT&gt;&lt;FONT color=#2b91af size=2&gt;MessageBox&lt;/FONT&gt;&lt;FONT size=2&gt;.Show(p.Name.ToString()); //Get Task's property Name&lt;/P&gt;
&lt;P&gt;&lt;/FONT&gt;&lt;FONT color=#0000ff size=2&gt;if&lt;/FONT&gt;&lt;FONT size=2&gt; (p.Get == &lt;/FONT&gt;&lt;FONT color=#0000ff size=2&gt;true&lt;/FONT&gt;&lt;FONT size=2&gt;)&lt;/P&gt;
&lt;P&gt;{&lt;/P&gt;
&lt;P&gt;&lt;/FONT&gt;&lt;FONT color=#2b91af size=2&gt;MessageBox&lt;/FONT&gt;&lt;FONT size=2&gt;.Show(p.GetValue(T1).ToString()); //get Task's property value&lt;/P&gt;
&lt;P&gt;}&lt;/P&gt;
&lt;P&gt;}&lt;/P&gt;
&lt;P&gt;&lt;/FONT&gt;&lt;FONT color=#0000ff size=2&gt;if&lt;/FONT&gt;&lt;FONT size=2&gt; (T1.InnerObject.ToString() == &lt;/FONT&gt;&lt;FONT color=#a31515 size=2&gt;"Microsoft.SqlServer.Dts.Tasks.ScriptTask.ScriptTask"&lt;/FONT&gt;&lt;FONT size=2&gt;) //This block is specific to Script Task&lt;/P&gt;
&lt;P&gt;{&lt;/P&gt;
&lt;P&gt;&lt;/FONT&gt;&lt;FONT color=#2b91af size=2&gt;ScriptTask&lt;/FONT&gt;&lt;FONT size=2&gt; ST = (&lt;/FONT&gt;&lt;FONT color=#2b91af size=2&gt;ScriptTask&lt;/FONT&gt;&lt;FONT size=2&gt;)T1.InnerObject;&lt;/P&gt;
&lt;P&gt;&lt;/FONT&gt;&lt;FONT color=#2b91af size=2&gt;ScriptTaskCodeProvider&lt;/FONT&gt;&lt;FONT size=2&gt; scp = ST.CodeProvider;&lt;/P&gt;
&lt;P&gt;&lt;/FONT&gt;&lt;FONT color=#0000ff size=2&gt;string&lt;/FONT&gt;&lt;FONT size=2&gt; strMoniker = &lt;/FONT&gt;&lt;FONT color=#a31515 size=2&gt;"dts://Scripts/"&lt;/FONT&gt;&lt;FONT size=2&gt; + ST.VsaProjectName + &lt;/FONT&gt;&lt;FONT color=#a31515 size=2&gt;"/ScriptMain.vsaitem"&lt;/FONT&gt;&lt;FONT size=2&gt;;&lt;/P&gt;&lt;/FONT&gt;&lt;FONT size=2&gt;
&lt;P&gt;scp.GetSourceCode(strMoniker);&lt;/P&gt;
&lt;P&gt;//Let us change the provider name&lt;/P&gt;
&lt;P&gt;scp.PutSourceCode(strMoniker, scp.GetSourceCode(strMoniker).Replace(&lt;FONT color=#a31515 size=2&gt;"SQLNCLI.1"&lt;/FONT&gt;&lt;FONT size=2&gt;, &lt;/FONT&gt;&lt;FONT color=#a31515 size=2&gt;"SQLNCLI10.1"&lt;/FONT&gt;&lt;FONT size=2&gt;));&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT size=2&gt;//Save the package in the default folder (C:\Program Files\Microsoft SQL Server\90\DTS\Packages) with a&amp;nbsp;new name. strNewPackage variable holds the new name&lt;/P&gt;&lt;/FONT&gt;
&lt;P&gt;dtsApp.SaveToDtsServer(dtsPkg, &lt;/FONT&gt;&lt;FONT color=#0000ff size=2&gt;null&lt;/FONT&gt;&lt;FONT size=2&gt;, &lt;/FONT&gt;&lt;FONT color=#a31515 size=2&gt;@"File System\"&lt;/FONT&gt;&lt;FONT size=2&gt; + strNewPackage, &lt;/FONT&gt;&lt;FONT color=#a31515 size=2&gt;"."&lt;/FONT&gt;&lt;FONT size=2&gt;);&lt;/P&gt;
&lt;P&gt;}&lt;/P&gt;
&lt;P&gt;&lt;/FONT&gt;&lt;FONT color=#0000ff size=2&gt;if&lt;/FONT&gt;&lt;FONT size=2&gt; (T1.InnerObject.ToString() == &lt;/FONT&gt;&lt;FONT color=#a31515 size=2&gt;"System.__ComObject"&lt;/FONT&gt;&lt;FONT size=2&gt;) //This block is specific to the inner task (Ex:- DataFlow Task will have inner tasks for source and destination)&lt;/P&gt;
&lt;P&gt;{&lt;/P&gt;
&lt;P&gt;&lt;/FONT&gt;&lt;FONT color=#2b91af size=2&gt;MainPipe&lt;/FONT&gt;&lt;FONT size=2&gt; m = (&lt;/FONT&gt;&lt;FONT color=#2b91af size=2&gt;MainPipe&lt;/FONT&gt;&lt;FONT size=2&gt;)T1.InnerObject;&lt;/P&gt;
&lt;P&gt;&lt;/FONT&gt;&lt;FONT color=#2b91af size=2&gt;IDTSComponentMetaDataCollection90&lt;/FONT&gt;&lt;FONT size=2&gt; mdc = m.ComponentMetaDataCollection;&lt;/P&gt;
&lt;P&gt;&lt;/FONT&gt;&lt;FONT color=#0000ff size=2&gt;foreach&lt;/FONT&gt;&lt;FONT size=2&gt; (&lt;/FONT&gt;&lt;FONT color=#2b91af size=2&gt;IDTSComponentMetaData90&lt;/FONT&gt;&lt;FONT size=2&gt; md &lt;/FONT&gt;&lt;FONT color=#0000ff size=2&gt;in&lt;/FONT&gt;&lt;FONT size=2&gt; mdc)&lt;/P&gt;
&lt;P&gt;{&lt;/P&gt;
&lt;P&gt;&lt;/FONT&gt;&lt;FONT color=#0000ff size=2&gt;foreach&lt;/FONT&gt;&lt;FONT size=2&gt; (&lt;/FONT&gt;&lt;FONT color=#2b91af size=2&gt;IDTSCustomProperty90&lt;/FONT&gt;&lt;FONT size=2&gt; cprop &lt;/FONT&gt;&lt;FONT color=#0000ff size=2&gt;in&lt;/FONT&gt;&lt;FONT size=2&gt; md.CustomPropertyCollection)&lt;/P&gt;
&lt;P&gt;{&lt;/P&gt;
&lt;P&gt;&lt;/FONT&gt;&lt;FONT color=#2b91af size=2&gt;MessageBox&lt;/FONT&gt;&lt;FONT size=2&gt;.Show(T1.Name.ToString());&lt;/P&gt;
&lt;P&gt;&lt;/FONT&gt;&lt;FONT color=#2b91af size=2&gt;MessageBox&lt;/FONT&gt;&lt;FONT size=2&gt;.Show(md.Name.ToString()); //Get Inner Task Name&lt;/P&gt;
&lt;P&gt;&lt;/FONT&gt;&lt;FONT color=#2b91af size=2&gt;MessageBox&lt;/FONT&gt;&lt;FONT size=2&gt;.Show(cprop.Name.ToString()); //Get Inner Task's property Name&lt;/P&gt;
&lt;P&gt;&lt;/FONT&gt;&lt;FONT color=#2b91af size=2&gt;MessageBox&lt;/FONT&gt;&lt;FONT size=2&gt;.Show(cprop.Value.ToString()); //Get Inner Task's property Value&lt;/P&gt;
&lt;P&gt;}&lt;/P&gt;
&lt;P&gt;}&lt;/P&gt;
&lt;P&gt;}&lt;/P&gt;
&lt;P&gt;}&lt;/P&gt;
&lt;P&gt;Hope you find it interesting.&amp;nbsp;&lt;/P&gt;
&lt;P mce_keep="true"&gt;&amp;nbsp;&lt;/P&gt;&lt;/FONT&gt;&lt;/FONT&gt;&lt;/FONT&gt;&lt;/FONT&gt;&lt;/FONT&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=8968801" width="1" height="1"&gt;</content><author><name>Ramoji</name><uri>http://blogs.msdn.com/Ramoji/ProfileUrlRedirect.ashx</uri></author></entry><entry><title>Moving indexes from one filegroup to another in SQL Server</title><link rel="alternate" type="text/html" href="http://blogs.msdn.com/b/ramoji/archive/2008/09/26/how-to-move-existing-indexes-from-one-filegroup-to-another.aspx" /><id>http://blogs.msdn.com/b/ramoji/archive/2008/09/26/how-to-move-existing-indexes-from-one-filegroup-to-another.aspx</id><published>2008-09-26T14:53:00Z</published><updated>2008-09-26T14:53:00Z</updated><content type="html">&lt;P&gt;This is a pretty simple task but I would like to provide a generic method for doing this.&amp;nbsp;It will help if&amp;nbsp;the requirement&amp;nbsp;is one (or all) of the folowing. I&amp;nbsp;have only considered&amp;nbsp;non-clustered indexes&amp;nbsp;along with the Inclued columns and filtered indexes.&amp;nbsp;No point in moving clustered indexes as moving them would move the data as well. This is because the leaf level of a clustered index is nothing but a data page.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;1. Move all the Indexes of a Table/View&lt;/P&gt;
&lt;P&gt;2. Move specific Indexes of a Table/View&lt;/P&gt;
&lt;P&gt;2. Move all the indexes&amp;nbsp;present in&amp;nbsp;a Database&lt;/P&gt;
&lt;P&gt;Here is a SP to achieve this and I haven't added validations as the idea is to&amp;nbsp;present how to do this. Hope this is useful.&lt;/P&gt;
&lt;P&gt;I am assuming that you have already created a user-defined FileGroup&amp;nbsp;to which you would like to move the indexes. The required parameters for this SP are Database name, scehma name,&amp;nbsp;FileGroup name and minimum of one table/view name for the @ObjectNameList parameter. If you would like to move indexes from more than one object, specify a comma separated string (Ex:- @ObjectNameList = 'Table1,Table2'). Specify the Index name argument only when you want to move&amp;nbsp;a single index from that table/view.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;CREATE PROC [dbo].[MoveIndexToFileGroup] (&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;BR&gt;&amp;nbsp;@DBName sysname,&amp;nbsp;&amp;nbsp; &lt;BR&gt;&amp;nbsp;@SchemaName sysname = 'dbo',&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;BR&gt;&amp;nbsp;@ObjectNameList Varchar(Max),&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;BR&gt;&amp;nbsp;@IndexName sysname = null,&amp;nbsp; &lt;BR&gt;&amp;nbsp;@FileGroupName varchar(100)&amp;nbsp; &lt;BR&gt;)&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;BR&gt;WITH RECOMPILE&amp;nbsp;&amp;nbsp; &lt;BR&gt;AS&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;BR&gt;&amp;nbsp; &lt;BR&gt;BEGIN&amp;nbsp; &lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;BR&gt;SET NOCOUNT ON&amp;nbsp; &lt;BR&gt;&amp;nbsp; &lt;BR&gt;DECLARE @IndexSQL NVarchar(Max)&amp;nbsp; &lt;BR&gt;DECLARE @IndexKeySQL NVarchar(Max)&amp;nbsp; &lt;BR&gt;DECLARE @IncludeColSQL NVarchar(Max)&amp;nbsp; &lt;BR&gt;DECLARE @FinalSQL NVarchar(Max)&amp;nbsp; &lt;BR&gt;&amp;nbsp; &lt;BR&gt;DECLARE @CurLoopCount Int&amp;nbsp; &lt;BR&gt;DECLARE @MaxLoopCount Int&amp;nbsp; &lt;BR&gt;DECLARE @StartPos Int&amp;nbsp; &lt;BR&gt;DECLARE @EndPos Int&amp;nbsp; &lt;BR&gt;&amp;nbsp; &lt;BR&gt;DECLARE @ObjectName sysname&amp;nbsp; &lt;BR&gt;DECLARE @IndName sysname&amp;nbsp; &lt;BR&gt;DECLARE @IsUnique Varchar(10)&amp;nbsp; &lt;BR&gt;DECLARE @Type Varchar(25)&amp;nbsp; &lt;BR&gt;DECLARE @IsPadded Varchar(5)&amp;nbsp; &lt;BR&gt;DECLARE @IgnoreDupKey Varchar(5) &lt;BR&gt;DECLARE @AllowRowLocks Varchar(5)&amp;nbsp; &lt;BR&gt;DECLARE @AllowPageLocks Varchar(5) &lt;BR&gt;DECLARE @FillFactor Int&amp;nbsp; &lt;BR&gt;DECLARE @ExistingFGName Varchar(Max) &lt;BR&gt;DECLARE @FilterDef NVarchar(Max)&lt;BR&gt;&amp;nbsp; &lt;BR&gt;DECLARE @ErrorMessage NVARCHAR(4000)&amp;nbsp; &lt;BR&gt;DECLARE @SQL nvarchar(4000)&amp;nbsp; &lt;BR&gt;DECLARE @RetVal Bit&amp;nbsp; &lt;BR&gt;&amp;nbsp; &lt;BR&gt;DECLARE @ObjectList Table(Id Int Identity(1,1),ObjectName sysname)&amp;nbsp; &lt;BR&gt;&amp;nbsp; &lt;BR&gt;DECLARE @WholeIndexData Table&amp;nbsp; &lt;BR&gt;(&amp;nbsp; &lt;BR&gt;ObjectName sysname&amp;nbsp; &lt;BR&gt;,IndexName sysname&amp;nbsp; &lt;BR&gt;,Is_Unique Bit&amp;nbsp; &lt;BR&gt;,Type_Desc Varchar(25)&amp;nbsp; &lt;BR&gt;,Is_Padded Bit&amp;nbsp; &lt;BR&gt;,Ignore_Dup_Key Bit&amp;nbsp; &lt;BR&gt;,Allow_Row_Locks Bit&amp;nbsp; &lt;BR&gt;,Allow_Page_Locks Bit&amp;nbsp; &lt;BR&gt;,Fill_Factor Int&amp;nbsp; &lt;BR&gt;,Is_Descending_Key Bit&amp;nbsp; &lt;BR&gt;,ColumnName sysname&amp;nbsp; &lt;BR&gt;,Is_Included_Column Bit&amp;nbsp; &lt;BR&gt;,FileGroupName Varchar(Max)&lt;BR&gt;,Has_Filter Bit&lt;BR&gt;,Filter_Definition NVarchar(Max)&amp;nbsp; &lt;BR&gt;)&amp;nbsp; &lt;BR&gt;&amp;nbsp; &lt;BR&gt;DECLARE @DistinctIndexData Table&amp;nbsp; &lt;BR&gt;(&amp;nbsp; &lt;BR&gt;Id Int IDENTITY(1,1)&amp;nbsp; &lt;BR&gt;,ObjectName sysname&amp;nbsp; &lt;BR&gt;,IndexName sysname&amp;nbsp; &lt;BR&gt;,Is_Unique Bit&amp;nbsp; &lt;BR&gt;,Type_Desc Varchar(25)&amp;nbsp; &lt;BR&gt;,Is_Padded Bit&amp;nbsp; &lt;BR&gt;,Ignore_Dup_Key Bit&amp;nbsp; &lt;BR&gt;,Allow_Row_Locks Bit&amp;nbsp; &lt;BR&gt;,Allow_Page_Locks Bit&amp;nbsp; &lt;BR&gt;,Fill_Factor Int&amp;nbsp; &lt;BR&gt;,FileGroupName Varchar(Max) &lt;BR&gt;,Has_Filter Bit&lt;BR&gt;,Filter_Definition NVarchar(Max)&amp;nbsp; &lt;BR&gt;)&amp;nbsp; &lt;BR&gt;&amp;nbsp; &lt;BR&gt;-------------Validate arguments----------------------&amp;nbsp;&amp;nbsp; &lt;BR&gt;&amp;nbsp; &lt;BR&gt;IF(@DBName IS NULL)&amp;nbsp; &lt;BR&gt;BEGIN&amp;nbsp; &lt;BR&gt;&amp;nbsp;SELECT @ErrorMessage = 'Database Name must be supplied.'&amp;nbsp;&amp;nbsp; &lt;BR&gt;&amp;nbsp;GOTO ABEND&amp;nbsp; &lt;BR&gt;END&amp;nbsp; &lt;BR&gt;&amp;nbsp; &lt;BR&gt;IF(@ObjectNameList IS NULL)&amp;nbsp; &lt;BR&gt;BEGIN&amp;nbsp; &lt;BR&gt;&amp;nbsp;SELECT @ErrorMessage = 'Table or View Name(s) must be supplied.'&amp;nbsp;&amp;nbsp; &lt;BR&gt;&amp;nbsp;GOTO ABEND&amp;nbsp; &lt;BR&gt;END&amp;nbsp; &lt;BR&gt;&amp;nbsp; &lt;BR&gt;IF(@FileGroupName IS NULL)&amp;nbsp; &lt;BR&gt;BEGIN&amp;nbsp; &lt;BR&gt;&amp;nbsp;SELECT @ErrorMessage = 'FileGroup Name must be supplied.'&amp;nbsp;&amp;nbsp; &lt;BR&gt;&amp;nbsp;GOTO ABEND&amp;nbsp; &lt;BR&gt;END&amp;nbsp; &lt;BR&gt;&amp;nbsp; &lt;BR&gt;--Check for the existence of the Database&amp;nbsp; &lt;BR&gt;IF NOT EXISTS(SELECT Name FROM sys.databases where Name = @DBName) &lt;BR&gt;BEGIN &lt;BR&gt;&amp;nbsp;SET @ErrorMessage = 'The specified Database does not exist'&amp;nbsp;&lt;BR&gt;&amp;nbsp;GOTO ABEND&lt;BR&gt;END&lt;BR&gt;&amp;nbsp; &lt;BR&gt;--Check for the existence of the Schema&amp;nbsp; &lt;BR&gt;IF(upper(@SchemaName) &amp;lt;&amp;gt; 'DBO')&amp;nbsp; &lt;BR&gt;BEGIN&amp;nbsp; &lt;BR&gt;&amp;nbsp;SET @SQL = 'SELECT @RetVal = COUNT(*) FROM ' + QUOTENAME(@DBName) + '.sys.schemas WHERE name = ''' + @SchemaName + ''''&amp;nbsp; &lt;BR&gt;&amp;nbsp;BEGIN TRY&amp;nbsp; &lt;BR&gt;&amp;nbsp; EXEC sp_executesql @SQL,N'@RetVal Bit OUTPUT',@RetVal OUTPUT&amp;nbsp; &lt;BR&gt;&amp;nbsp;END TRY&amp;nbsp; &lt;BR&gt;&amp;nbsp;BEGIN CATCH&amp;nbsp; &lt;BR&gt;&amp;nbsp; SELECT @ErrorMessage = ERROR_MESSAGE()&amp;nbsp;&amp;nbsp; &lt;BR&gt;&amp;nbsp; GOTO ABEND&amp;nbsp; &lt;BR&gt;&amp;nbsp;END CATCH&amp;nbsp; &lt;BR&gt;&amp;nbsp;IF(@RetVal = 0)&amp;nbsp; &lt;BR&gt;&amp;nbsp;BEGIN&amp;nbsp; &lt;BR&gt;&amp;nbsp; SELECT @ErrorMessage = 'No Schema with the name ' + @SchemaName + ' exists in the Database ' + @DBName&amp;nbsp;&amp;nbsp; &lt;BR&gt;&amp;nbsp; GOTO ABEND&amp;nbsp; &lt;BR&gt;&amp;nbsp;END&amp;nbsp;&amp;nbsp; &lt;BR&gt;END&amp;nbsp; &lt;BR&gt;&amp;nbsp; &lt;BR&gt;--Check for the existence of the FileGroup&amp;nbsp; &lt;BR&gt;SET @SQL = 'SELECT @RetVal=COUNT(*) FROM ' + QUOTENAME(@DBName) + '.sys.filegroups WHERE name = ''' + @FileGroupName + ''''&amp;nbsp; &lt;BR&gt;BEGIN TRY&amp;nbsp; &lt;BR&gt;&amp;nbsp;EXEC sp_executesql @SQL,N'@RetVal Bit OUTPUT',@RetVal OUTPUT&amp;nbsp; &lt;BR&gt;END TRY&amp;nbsp; &lt;BR&gt;BEGIN CATCH&amp;nbsp; &lt;BR&gt;&amp;nbsp;SELECT @ErrorMessage = ERROR_MESSAGE()&amp;nbsp;&amp;nbsp; &lt;BR&gt;&amp;nbsp;GOTO ABEND&amp;nbsp; &lt;BR&gt;END CATCH&amp;nbsp; &lt;BR&gt;&amp;nbsp; &lt;BR&gt;IF(@RetVal = 0)&amp;nbsp; &lt;BR&gt;BEGIN&amp;nbsp; &lt;BR&gt;&amp;nbsp;SELECT @ErrorMessage = 'No FileGroup with the name ' + @FileGroupName + ' exists in the Database ' + @DBName&amp;nbsp;&amp;nbsp; &lt;BR&gt;&amp;nbsp;GOTO ABEND&amp;nbsp; &lt;BR&gt;END&amp;nbsp; &lt;BR&gt;&amp;nbsp; &lt;BR&gt;----------Get the objects from the concatenated list----------------------------------------------------&amp;nbsp; &lt;BR&gt;&amp;nbsp; &lt;BR&gt;SET @StartPos = 0&amp;nbsp; &lt;BR&gt;SET @EndPos = 0&amp;nbsp; &lt;BR&gt;&amp;nbsp; &lt;BR&gt;WHILE(@EndPos &amp;gt;= 0)&amp;nbsp; &lt;BR&gt;BEGIN&amp;nbsp; &lt;BR&gt;&amp;nbsp; &lt;BR&gt;&amp;nbsp;SELECT @EndPos = CHARINDEX(',',@ObjectNameList,@StartPos)&amp;nbsp; &lt;BR&gt;&amp;nbsp;IF(@EndPos = 0) --Means, separator is not found&amp;nbsp; &lt;BR&gt;&amp;nbsp;BEGIN&amp;nbsp; &lt;BR&gt;&amp;nbsp; INSERT INTO @ObjectList&amp;nbsp; &lt;BR&gt;&amp;nbsp; SELECT SUBSTRING(@ObjectNameList,@StartPos,(LEN(@ObjectNameList) - @StartPos)+1)&amp;nbsp;&amp;nbsp; &lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;BR&gt;&amp;nbsp; BREAK&amp;nbsp; &lt;BR&gt;&amp;nbsp;END&amp;nbsp; &lt;BR&gt;&amp;nbsp;&amp;nbsp; &lt;BR&gt;&amp;nbsp;INSERT INTO @ObjectList&amp;nbsp; &lt;BR&gt;&amp;nbsp;SELECT SUBSTRING(@ObjectNameList,@StartPos,(@EndPos - @StartPos))&amp;nbsp; &lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;BR&gt;&amp;nbsp;SET @StartPos = @EndPos + 1&amp;nbsp; &lt;BR&gt;&amp;nbsp;&amp;nbsp; &lt;BR&gt;END&amp;nbsp; &lt;BR&gt;&amp;nbsp; &lt;BR&gt;-------------Check for the validity of all the Objects----------------------&amp;nbsp; &lt;BR&gt;&amp;nbsp; &lt;BR&gt;SET @StartPos = 1&amp;nbsp; &lt;BR&gt;SELECT @EndPos = COUNT(*) FROM @ObjectList&amp;nbsp; &lt;BR&gt;&amp;nbsp; &lt;BR&gt;WHILE(@StartPos &amp;lt;= @EndPos)&amp;nbsp; &lt;BR&gt;BEGIN&amp;nbsp; &lt;BR&gt;&amp;nbsp; &lt;BR&gt;&amp;nbsp;SELECT @ObjectName = ObjectName FROM @ObjectList WHERE Id = @StartPos&amp;nbsp; &lt;BR&gt;&amp;nbsp; &lt;BR&gt;&amp;nbsp;--Check for existence of the object&amp;nbsp; &lt;BR&gt;&amp;nbsp;SET @SQL = 'SELECT @RetVal=COUNT(*) FROM ' + QUOTENAME(@DBName) + '.sys.Objects WHERE type IN (''U'',''V'') AND name = ''' + @ObjectName + ''''&amp;nbsp; &lt;BR&gt;&amp;nbsp;BEGIN TRY&amp;nbsp; &lt;BR&gt;&amp;nbsp; EXEC sp_executesql @SQL,N'@RetVal Int OUTPUT',@RetVal OUTPUT&amp;nbsp; &lt;BR&gt;&amp;nbsp;END TRY&amp;nbsp; &lt;BR&gt;&amp;nbsp;BEGIN CATCH&amp;nbsp; &lt;BR&gt;&amp;nbsp; SELECT @ErrorMessage = ERROR_MESSAGE()&amp;nbsp;&amp;nbsp; &lt;BR&gt;&amp;nbsp; GOTO ABEND&amp;nbsp; &lt;BR&gt;&amp;nbsp;END CATCH&amp;nbsp; &lt;BR&gt;&amp;nbsp; &lt;BR&gt;&amp;nbsp;IF(@RetVal = 0)&amp;nbsp; &lt;BR&gt;&amp;nbsp;BEGIN&amp;nbsp; &lt;BR&gt;&amp;nbsp; SELECT @ErrorMessage = 'No Table or View with the name ' + @ObjectName + ' exists in the Database ' + @DBName&amp;nbsp;&amp;nbsp; &lt;BR&gt;&amp;nbsp; GOTO ABEND&amp;nbsp; &lt;BR&gt;&amp;nbsp;END&amp;nbsp;&amp;nbsp; &lt;BR&gt;&amp;nbsp; &lt;BR&gt;&amp;nbsp;--Check for existence of Index&amp;nbsp; &lt;BR&gt;&amp;nbsp;IF(@IndexName IS NOT NULL)&amp;nbsp; &lt;BR&gt;&amp;nbsp;BEGIN&amp;nbsp; &lt;BR&gt;&amp;nbsp; SET @SQL = 'SELECT @RetVal=COUNT(*) FROM ' + QUOTENAME(@DBName) + '.sys.Indexes si INNER JOIN ' + QUOTENAME(@DBName) + '.sys.Objects so '&amp;nbsp; &lt;BR&gt;&amp;nbsp; SET @SQL = @SQL + ' ON si.Object_Id = so.Object_Id WHERE so.Schema_id = ' + CAST(Schema_Id(@Schemaname) as varchar(25))&amp;nbsp;&amp;nbsp; &lt;BR&gt;&amp;nbsp; SET @SQL = @SQL + ' AND so.name = ''' + @ObjectName + ''' AND si.name = ''' + @IndexName + ''''&amp;nbsp;&amp;nbsp; &lt;BR&gt;&amp;nbsp; &lt;BR&gt;&amp;nbsp; BEGIN TRY&amp;nbsp; &lt;BR&gt;&amp;nbsp;&amp;nbsp; EXEC sp_executesql @SQL,N'@RetVal Int OUTPUT',@RetVal OUTPUT&amp;nbsp; &lt;BR&gt;&amp;nbsp; END TRY&amp;nbsp; &lt;BR&gt;&amp;nbsp; BEGIN CATCH&amp;nbsp; &lt;BR&gt;&amp;nbsp;&amp;nbsp; SELECT @ErrorMessage = ERROR_MESSAGE()&amp;nbsp;&amp;nbsp; &lt;BR&gt;&amp;nbsp;&amp;nbsp; GOTO ABEND&amp;nbsp; &lt;BR&gt;&amp;nbsp; END CATCH&amp;nbsp; &lt;BR&gt;&amp;nbsp; &lt;BR&gt;&amp;nbsp; IF(@RetVal = 0)&amp;nbsp; &lt;BR&gt;&amp;nbsp; BEGIN&amp;nbsp; &lt;BR&gt;&amp;nbsp;&amp;nbsp; SELECT @ErrorMessage = 'No Index with the name ' + @IndexName + ' exists on the Object ' + @ObjectName&amp;nbsp;&amp;nbsp; &lt;BR&gt;&amp;nbsp;&amp;nbsp; GOTO ABEND&amp;nbsp; &lt;BR&gt;&amp;nbsp; END&amp;nbsp; &lt;BR&gt;&amp;nbsp;END&amp;nbsp; &lt;BR&gt;&amp;nbsp;&amp;nbsp; &lt;BR&gt;&amp;nbsp;SET @StartPos = @StartPos + 1&amp;nbsp; &lt;BR&gt;END&amp;nbsp; &lt;BR&gt;&amp;nbsp; &lt;BR&gt;-------------Loop till all the Objects are processed----------------------&amp;nbsp; &lt;BR&gt;&amp;nbsp; &lt;BR&gt;SET @StartPos = 1&amp;nbsp; &lt;BR&gt;SELECT @EndPos = COUNT(*) FROM @ObjectList&amp;nbsp; &lt;BR&gt;&amp;nbsp; &lt;BR&gt;WHILE(@StartPos &amp;lt;= @EndPos)&amp;nbsp; &lt;BR&gt;BEGIN&amp;nbsp; &lt;BR&gt;&amp;nbsp; &lt;BR&gt;&amp;nbsp;SELECT @ObjectName = ObjectName FROM @ObjectList WHERE Id = @StartPos&amp;nbsp; &lt;BR&gt;&amp;nbsp;&lt;BR&gt;&amp;nbsp;-------------Build the SQL to get the index data based on the inputs provided----------------------&amp;nbsp;&amp;nbsp; &lt;BR&gt;&amp;nbsp; &lt;BR&gt;&amp;nbsp;SET @IndexSQL =&amp;nbsp;&amp;nbsp; &lt;BR&gt;&amp;nbsp;'SELECT so.Name as ObjectName, si.Name as IndexName,si.Is_Unique,si.Type_Desc'&amp;nbsp; &lt;BR&gt;&amp;nbsp;+ ',si.Is_Padded,si.Ignore_Dup_Key,si.Allow_Row_Locks,si.Allow_Page_Locks,si.Fill_Factor,sic.Is_Descending_Key'&amp;nbsp; &lt;BR&gt;&amp;nbsp;+ ',sc.Name as ColumnName,sic.Is_Included_Column,sf.Name as FileGroupName,si.Has_Filter,si.Filter_Definition FROM '&lt;BR&gt;&amp;nbsp;+ QUOTENAME(@DBName) + '.sys.Objects so INNER JOIN ' + QUOTENAME(@DBName) + '.sys.Indexes si ON so.Object_Id = si.Object_id INNER JOIN '&amp;nbsp; &lt;BR&gt;&amp;nbsp;+ QUOTENAME(@DBName) + '.sys.FileGroups sf ON sf.Data_Space_Id = si.Data_Space_Id INNER JOIN '&amp;nbsp;&amp;nbsp; &lt;BR&gt;&amp;nbsp;+ QUOTENAME(@DBName) + '.sys.Index_columns sic ON si.Object_Id = sic.Object_Id AND si.Index_id = sic.Index_id INNER JOIN '&amp;nbsp; &lt;BR&gt;&amp;nbsp;+ QUOTENAME(@DBName) + '.sys.Columns sc ON sic.Column_Id = sc.Column_Id and sc.Object_Id = sic.Object_Id '&amp;nbsp; &lt;BR&gt;&amp;nbsp;+ ' WHERE so.Name = ''' + @ObjectName&amp;nbsp; + ''''&amp;nbsp; &lt;BR&gt;&amp;nbsp;+ ' AND so.Schema_id = ' + CAST(Schema_Id(@Schemaname) as varchar(25)) + ' AND si.Type_Desc = ''NONCLUSTERED'' '&amp;nbsp; &lt;BR&gt;&amp;nbsp; &lt;BR&gt;&amp;nbsp;IF(@IndexName IS NOT NULL)&amp;nbsp; &lt;BR&gt;&amp;nbsp;BEGIN&amp;nbsp; &lt;BR&gt;&amp;nbsp; SET @IndexSQL = @IndexSQL + ' AND si.Name = ''' + @IndexName + ''''&amp;nbsp; &lt;BR&gt;&amp;nbsp;END&amp;nbsp; &lt;BR&gt;&amp;nbsp; &lt;BR&gt;&amp;nbsp;SET @IndexSQL = @IndexSQL + ' ORDER BY ObjectName, IndexName'&amp;nbsp; &lt;BR&gt;&amp;nbsp; &lt;BR&gt;&amp;nbsp;--PRINT @IndexSQL&amp;nbsp; &lt;BR&gt;&amp;nbsp; &lt;BR&gt;&amp;nbsp;-------------Insert the Index Data in to a variable----------------------&amp;nbsp;&amp;nbsp; &lt;BR&gt;&amp;nbsp; &lt;BR&gt;&amp;nbsp;BEGIN TRY&amp;nbsp; &lt;BR&gt;&amp;nbsp; INSERT INTO @WholeIndexData&amp;nbsp; &lt;BR&gt;&amp;nbsp; EXEC sp_executesql @IndexSQL&amp;nbsp; &lt;BR&gt;&amp;nbsp;END TRY&amp;nbsp; &lt;BR&gt;&amp;nbsp;BEGIN CATCH&amp;nbsp; &lt;BR&gt;&amp;nbsp; SELECT @ErrorMessage = ERROR_MESSAGE()&amp;nbsp;&amp;nbsp; &lt;BR&gt;&amp;nbsp; GOTO ABEND&amp;nbsp; &lt;BR&gt;&amp;nbsp;END CATCH&amp;nbsp; &lt;BR&gt;&amp;nbsp; &lt;BR&gt;&amp;nbsp;--Check if any indexes are there on the object. Otherwise exit&amp;nbsp; &lt;BR&gt;&amp;nbsp;IF (SELECT COUNT(*) FROM @WholeIndexData) = 0&amp;nbsp; &lt;BR&gt;&amp;nbsp;BEGIN&amp;nbsp; &lt;BR&gt;&amp;nbsp; SELECT 'Object does not have any nonclustered indexes to move'&amp;nbsp;&amp;nbsp; &lt;BR&gt;&amp;nbsp; GOTO FINAL&amp;nbsp;&amp;nbsp; &lt;BR&gt;&amp;nbsp;END&amp;nbsp; &lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;BR&gt;&amp;nbsp;-------------Get the distinct index rows in to a variable----------------------&amp;nbsp;&amp;nbsp; &lt;BR&gt;&amp;nbsp; &lt;BR&gt;&amp;nbsp;INSERT INTO @DistinctIndexData&amp;nbsp; &lt;BR&gt;&amp;nbsp;SELECT DISTINCT&amp;nbsp;&amp;nbsp; &lt;BR&gt;&amp;nbsp;ObjectName,IndexName,Is_Unique,Type_Desc,Is_Padded,Ignore_Dup_Key,Allow_Row_Locks,Allow_Page_Locks,Fill_Factor,FileGroupName,Has_Filter,Filter_Definition&amp;nbsp; &lt;BR&gt;&amp;nbsp;FROM @WholeIndexData&lt;BR&gt;&amp;nbsp;WHERE ObjectName = @ObjectName&amp;nbsp; &lt;BR&gt;&amp;nbsp; &lt;BR&gt;&amp;nbsp;SELECT @CurLoopCount = Min(Id), @MaxLoopCount = Max(Id) FROM @DistinctIndexData WHERE ObjectName = @ObjectName&lt;BR&gt;&amp;nbsp; &lt;BR&gt;&amp;nbsp;--SELECT @CurLoopCount, @MaxLoopCount&amp;nbsp; &lt;BR&gt;&amp;nbsp; &lt;BR&gt;&amp;nbsp;-------------Loop till all the indexes are processed----------------------&amp;nbsp;&amp;nbsp; &lt;BR&gt;&amp;nbsp; &lt;BR&gt;&amp;nbsp;WHILE(@CurLoopCount &amp;lt;= @MaxLoopCount)&amp;nbsp; &lt;BR&gt;&amp;nbsp;BEGIN&amp;nbsp; &lt;BR&gt;&amp;nbsp; &lt;BR&gt;&amp;nbsp; SET @IndexKeySQL = ''&amp;nbsp; &lt;BR&gt;&amp;nbsp; SET @IncludeColSQL = ''&amp;nbsp; &lt;BR&gt;&amp;nbsp; &lt;BR&gt;&amp;nbsp; -------------Get the current index row to be processed----------------------&amp;nbsp; &lt;BR&gt;&amp;nbsp; SELECT&amp;nbsp;&amp;nbsp; &lt;BR&gt;&amp;nbsp;&amp;nbsp; @IndName&amp;nbsp;&amp;nbsp;&amp;nbsp;=&amp;nbsp;IndexName&amp;nbsp; &lt;BR&gt;&amp;nbsp;&amp;nbsp; ,@Type&amp;nbsp;&amp;nbsp;&amp;nbsp;=&amp;nbsp;Type_Desc&lt;BR&gt;&amp;nbsp;&amp;nbsp; ,@ExistingFGName =&amp;nbsp;FileGroupName&lt;BR&gt;&amp;nbsp;&amp;nbsp; ,@IsUnique&amp;nbsp;&amp;nbsp;=&amp;nbsp;CASE WHEN Is_Unique = 1 THEN 'UNIQUE ' ELSE '' END&amp;nbsp; &lt;BR&gt;&amp;nbsp;&amp;nbsp; ,@IsPadded&amp;nbsp;&amp;nbsp;=&amp;nbsp;CASE WHEN Is_Padded = 0 THEN 'OFF,' ELSE 'ON,'&amp;nbsp; END&amp;nbsp; &lt;BR&gt;&amp;nbsp;&amp;nbsp; ,@IgnoreDupKey&amp;nbsp;=&amp;nbsp;CASE WHEN Ignore_Dup_Key = 0 THEN 'OFF,' ELSE 'ON,' END&amp;nbsp; &lt;BR&gt;&amp;nbsp;&amp;nbsp; ,@AllowRowLocks&amp;nbsp;=&amp;nbsp;CASE WHEN Allow_Row_Locks = 0 THEN 'OFF,' ELSE 'ON,' END &lt;BR&gt;&amp;nbsp;&amp;nbsp; ,@AllowPageLocks&amp;nbsp;=&amp;nbsp;CASE WHEN Allow_Page_Locks = 0 THEN 'OFF,' ELSE 'ON,' END&amp;nbsp; &lt;BR&gt;&amp;nbsp;&amp;nbsp; ,@FillFactor&amp;nbsp;&amp;nbsp;=&amp;nbsp;CASE WHEN Fill_Factor = 0 THEN 100 ELSE Fill_Factor END&amp;nbsp; &lt;BR&gt;&amp;nbsp;&amp;nbsp; ,@FilterDef&amp;nbsp;&amp;nbsp;=&amp;nbsp;CASE WHEN Has_Filter = 1 THEN (' WHERE ' + Filter_Definition) ELSE '' END&amp;nbsp; &lt;BR&gt;&amp;nbsp; FROM @DistinctIndexData&amp;nbsp;&amp;nbsp; &lt;BR&gt;&amp;nbsp; WHERE Id = @CurLoopCount&amp;nbsp; &lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;BR&gt;&amp;nbsp; -------------Check if the index is already not part of that FileGroup----------------------&amp;nbsp; &lt;BR&gt;&amp;nbsp; &lt;BR&gt;&amp;nbsp; IF(@ExistingFGName = @FileGroupName)&amp;nbsp; &lt;BR&gt;&amp;nbsp; BEGIN&amp;nbsp; &lt;BR&gt;&amp;nbsp;&amp;nbsp; PRINT 'Index ' +&amp;nbsp; @IndName + ' is NOT moved as it is already part of the FileGroup ' + @FileGroupName + '.'&amp;nbsp; &lt;BR&gt;&amp;nbsp;&amp;nbsp; SET @CurLoopCount = @CurLoopCount + 1&amp;nbsp; &lt;BR&gt;&amp;nbsp;&amp;nbsp; CONTINUE&amp;nbsp; &lt;BR&gt;&amp;nbsp; END&amp;nbsp; &lt;BR&gt;&amp;nbsp; &lt;BR&gt;&amp;nbsp; ------- Construct the Index key string along with the direction--------------------&amp;nbsp; &lt;BR&gt;&amp;nbsp; SELECT&amp;nbsp;&amp;nbsp; &lt;BR&gt;&amp;nbsp;&amp;nbsp; @IndexKeySQL =&amp;nbsp;&amp;nbsp; &lt;BR&gt;&amp;nbsp;&amp;nbsp; CASE&amp;nbsp; &lt;BR&gt;&amp;nbsp;&amp;nbsp; WHEN @IndexKeySQL = '' THEN (@IndexKeySQL + QUOTENAME(ColumnName) + CASE WHEN Is_Descending_Key = 0 THEN ' ASC' ELSE ' DESC' END)&amp;nbsp;&amp;nbsp; &lt;BR&gt;&amp;nbsp;&amp;nbsp; ELSE (@IndexKeySQL + ',' + QUOTENAME(ColumnName) + CASE WHEN Is_Descending_Key = 0 THEN ' ASC' ELSE ' DESC' END)&amp;nbsp;&amp;nbsp; &lt;BR&gt;&amp;nbsp;&amp;nbsp; END&amp;nbsp; &lt;BR&gt;&amp;nbsp; FROM @WholeIndexData&amp;nbsp; &lt;BR&gt;&amp;nbsp; WHERE ObjectName = @ObjectName&amp;nbsp;&amp;nbsp; &lt;BR&gt;&amp;nbsp; AND IndexName = @IndName&amp;nbsp;&amp;nbsp; &lt;BR&gt;&amp;nbsp; AND Is_Included_Column = 0&amp;nbsp; &lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;BR&gt;&amp;nbsp; --PRINT @IndexKeySQL&amp;nbsp;&amp;nbsp; &lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;BR&gt;&amp;nbsp; ------ Construct the Included Column string --------------------------------------&amp;nbsp; &lt;BR&gt;&amp;nbsp; SELECT&amp;nbsp;&amp;nbsp; &lt;BR&gt;&amp;nbsp;&amp;nbsp; @IncludeColSQL =&amp;nbsp;&amp;nbsp; &lt;BR&gt;&amp;nbsp;&amp;nbsp; CASE&amp;nbsp; &lt;BR&gt;&amp;nbsp;&amp;nbsp; WHEN @IncludeColSQL = '' THEN (@IncludeColSQL + QUOTENAME(ColumnName))&amp;nbsp;&amp;nbsp; &lt;BR&gt;&amp;nbsp;&amp;nbsp; ELSE (@IncludeColSQL + ',' + QUOTENAME(ColumnName))&amp;nbsp;&amp;nbsp; &lt;BR&gt;&amp;nbsp;&amp;nbsp; END&amp;nbsp;&amp;nbsp; &lt;BR&gt;&amp;nbsp; FROM @WholeIndexData&amp;nbsp; &lt;BR&gt;&amp;nbsp; WHERE ObjectName = @ObjectName&amp;nbsp;&amp;nbsp; &lt;BR&gt;&amp;nbsp; AND IndexName = @IndName&amp;nbsp;&amp;nbsp; &lt;BR&gt;&amp;nbsp; AND Is_Included_Column = 1&amp;nbsp;&amp;nbsp; &lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;BR&gt;&amp;nbsp; --PRINT @IncludeColSQL&amp;nbsp; &lt;BR&gt;&amp;nbsp; &lt;BR&gt;&amp;nbsp; -------------Construct the final Create Index statement----------------------&amp;nbsp; &lt;BR&gt;&amp;nbsp; SELECT &lt;BR&gt;&amp;nbsp; @FinalSQL = 'CREATE ' + @IsUnique + @Type + ' INDEX ' + QUOTENAME(@IndName) &lt;BR&gt;&amp;nbsp; + ' ON ' + QUOTENAME(@DBName) + '.' + QUOTENAME(@SchemaName) + '.' + QUOTENAME(@ObjectName)&amp;nbsp; &lt;BR&gt;&amp;nbsp; + '(' + @IndexKeySQL + ') '&amp;nbsp;&amp;nbsp; &lt;BR&gt;&amp;nbsp; + CASE WHEN LEN(@IncludeColSQL) &amp;lt;&amp;gt; 0 THEN&amp;nbsp; 'INCLUDE(' + @IncludeColSQL + ') ' ELSE '' END&lt;BR&gt;&amp;nbsp; + @FilterDef&amp;nbsp; &lt;BR&gt;&amp;nbsp; + ' WITH ('&amp;nbsp;&amp;nbsp; &lt;BR&gt;&amp;nbsp; + 'PAD_INDEX = ' + @IsPadded&amp;nbsp;&amp;nbsp; &lt;BR&gt;&amp;nbsp; + 'IGNORE_DUP_KEY = ' + @IgnoreDupKey&amp;nbsp; &lt;BR&gt;&amp;nbsp; + 'ALLOW_ROW_LOCKS&amp;nbsp; = ' + @AllowRowLocks&amp;nbsp;&amp;nbsp; &lt;BR&gt;&amp;nbsp; + 'ALLOW_PAGE_LOCKS&amp;nbsp; = ' + @AllowPageLocks&amp;nbsp;&amp;nbsp; &lt;BR&gt;&amp;nbsp; + 'SORT_IN_TEMPDB = OFF,'&amp;nbsp;&amp;nbsp; &lt;BR&gt;&amp;nbsp; + 'DROP_EXISTING = ON,'&amp;nbsp;&amp;nbsp; &lt;BR&gt;&amp;nbsp; + 'ONLINE = OFF,'&amp;nbsp; &lt;BR&gt;&amp;nbsp; + 'FILLFACTOR = ' + CAST(@FillFactor AS Varchar(3))&amp;nbsp; &lt;BR&gt;&amp;nbsp; + ') ON ' + QUOTENAME(@FileGroupName)&amp;nbsp; &lt;BR&gt;&amp;nbsp; &lt;BR&gt;&amp;nbsp; --PRINT @FinalSQL&amp;nbsp; &lt;BR&gt;&amp;nbsp; &lt;BR&gt;&amp;nbsp; -------------Execute the Create Index statement to move to the specified filegroup----------------------&amp;nbsp; &lt;BR&gt;&amp;nbsp; BEGIN TRY&amp;nbsp; &lt;BR&gt;&amp;nbsp;&amp;nbsp; EXEC sp_executesql @FinalSQL&amp;nbsp; &lt;BR&gt;&amp;nbsp; END TRY&amp;nbsp; &lt;BR&gt;&amp;nbsp; BEGIN CATCH&amp;nbsp; &lt;BR&gt;&amp;nbsp;&amp;nbsp; SELECT @ErrorMessage = ERROR_MESSAGE()&amp;nbsp;&amp;nbsp; &lt;BR&gt;&amp;nbsp;&amp;nbsp; GOTO ABEND&amp;nbsp; &lt;BR&gt;&amp;nbsp; END CATCH&amp;nbsp;&amp;nbsp; &lt;BR&gt;&amp;nbsp; PRINT 'Index ' +&amp;nbsp; @IndName + ' on Object ' + @ObjectName + ' is moved successfully.'&amp;nbsp;&amp;nbsp; &lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;BR&gt;&amp;nbsp; SET @CurLoopCount = @CurLoopCount + 1&amp;nbsp; &lt;BR&gt;&amp;nbsp; &lt;BR&gt;&amp;nbsp;END&amp;nbsp; &lt;BR&gt;&amp;nbsp;&amp;nbsp; &lt;BR&gt;&amp;nbsp;SET @StartPos = @StartPos + 1&amp;nbsp; &lt;BR&gt;END&amp;nbsp; &lt;BR&gt;&amp;nbsp;SELECT 'The procedure completed successfully.'&amp;nbsp; &lt;BR&gt;&amp;nbsp;RETURN&amp;nbsp; &lt;BR&gt;&amp;nbsp; &lt;BR&gt;ABEND:&amp;nbsp; &lt;BR&gt;&amp;nbsp;RAISERROR 500001 @ErrorMessage&amp;nbsp; &lt;BR&gt;FINAL:&amp;nbsp; &lt;BR&gt;&amp;nbsp;RETURN&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;BR&gt;END&amp;nbsp; &lt;/P&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=8966385" width="1" height="1"&gt;</content><author><name>Ramoji</name><uri>http://blogs.msdn.com/Ramoji/ProfileUrlRedirect.ashx</uri></author></entry><entry><title>Creating new tables and loading data in SQL server by reading an Xml file</title><link rel="alternate" type="text/html" href="http://blogs.msdn.com/b/ramoji/archive/2008/09/18/how-to-create-new-tables-and-load-data-by-reading-an-xml-file.aspx" /><id>http://blogs.msdn.com/b/ramoji/archive/2008/09/18/how-to-create-new-tables-and-load-data-by-reading-an-xml-file.aspx</id><published>2008-09-18T12:25:00Z</published><updated>2008-09-18T12:25:00Z</updated><content type="html">&lt;P&gt;This kind of requirement may come if VSTS is used for&amp;nbsp;test automation and the&amp;nbsp;test results&amp;nbsp;have to be loaded to a Database. Since the output of test automation is an xml file, let us look at how we can create tables and load them with data by reading&amp;nbsp;an xml file.&lt;/P&gt;
&lt;P&gt;The logic at a high level is as follows.&lt;/P&gt;
&lt;P&gt;1. Load the Xml file into a DataSet&lt;/P&gt;
&lt;P&gt;2. Use SMO objects to access the target SQL Server and DB&lt;/P&gt;
&lt;P&gt;3. Read the DataTables one by one from DataSet and create corresponding tables in target Server&lt;/P&gt;
&lt;P&gt;4. Use SMO's BulkCopy to load the data from DataTable to the newly created table in target server&lt;/P&gt;
&lt;P&gt;Now, create a windows form with three textboxes&amp;nbsp;for capturing&amp;nbsp;target DB server name, DB name and Xml file name. Add a button to proceed with the execution.&lt;/P&gt;
&lt;P&gt;Use&amp;nbsp;the following SMO name spaces in the code. Make sure the assemblies "Microsoft.SqlServer.Smo" and "Microsoft.SqlServer.ConnectionInfo" are added to project references in Visual Studio 2005.&lt;/P&gt;&lt;FONT color=#0000ff size=2&gt;
&lt;P&gt;using&lt;/FONT&gt;&lt;FONT size=2&gt; Microsoft.SqlServer.Management;&lt;/P&gt;&lt;/FONT&gt;&lt;FONT color=#0000ff size=2&gt;
&lt;P&gt;using&lt;/FONT&gt;&lt;FONT size=2&gt; Microsoft.SqlServer.Management.Smo;&lt;/P&gt;&lt;/FONT&gt;&lt;FONT color=#0000ff size=2&gt;
&lt;P&gt;using&lt;/FONT&gt;&lt;FONT size=2&gt; Microsoft.SqlServer.Management.Common;&lt;/P&gt;&lt;/FONT&gt;&lt;FONT color=#0000ff size=2&gt;
&lt;P&gt;using&lt;/FONT&gt;&lt;FONT size=2&gt; Microsoft.SqlServer.Server;&lt;/P&gt;&lt;/FONT&gt;&lt;FONT color=#0000ff size=2&gt;
&lt;P&gt;using&lt;/FONT&gt;&lt;FONT size=2&gt; Microsoft.SqlServer;&lt;/P&gt;&lt;/FONT&gt;
&lt;P mce_keep="true"&gt;Add the following code to the button click event.&lt;/P&gt;&lt;FONT size=2&gt;
&lt;P&gt;&lt;/FONT&gt;&lt;FONT color=#0000ff size=2&gt;private&lt;/FONT&gt;&lt;FONT size=2&gt; &lt;/FONT&gt;&lt;FONT color=#0000ff size=2&gt;void&lt;/FONT&gt;&lt;FONT size=2&gt; button1_Click(&lt;/FONT&gt;&lt;FONT color=#0000ff size=2&gt;object&lt;/FONT&gt;&lt;FONT size=2&gt; sender, &lt;/FONT&gt;&lt;FONT color=#2b91af size=2&gt;EventArgs&lt;/FONT&gt;&lt;FONT size=2&gt; e)&lt;/P&gt;
&lt;P&gt;{&lt;/P&gt;
&lt;P&gt;&lt;/FONT&gt;&lt;FONT color=#2b91af size=2&gt;DataSet&lt;/FONT&gt;&lt;FONT size=2&gt; ds = &lt;/FONT&gt;&lt;FONT color=#0000ff size=2&gt;new&lt;/FONT&gt;&lt;FONT size=2&gt; &lt;/FONT&gt;&lt;FONT color=#2b91af size=2&gt;DataSet&lt;/FONT&gt;&lt;FONT size=2&gt;();&lt;/P&gt;
&lt;P&gt;&lt;/FONT&gt;&lt;FONT color=#008000 size=2&gt;//ds.ReadXmlSchema("E:\\Temp\\SampleWT1.xsd");&lt;/P&gt;&lt;/FONT&gt;&lt;FONT size=2&gt;
&lt;P&gt;ds.ReadXml(txtXmlLoc.Text);&lt;/P&gt;
&lt;P&gt;&lt;/FONT&gt;&lt;FONT color=#008000 size=2&gt;//ds.ReadXml("E:\\Temp\\Sample.xml");&lt;/P&gt;&lt;/FONT&gt;&lt;FONT size=2&gt;
&lt;P&gt;&lt;/FONT&gt;&lt;FONT color=#2b91af size=2&gt;Server&lt;/FONT&gt;&lt;FONT size=2&gt; objServer = &lt;/FONT&gt;&lt;FONT color=#0000ff size=2&gt;new&lt;/FONT&gt;&lt;FONT size=2&gt; &lt;/FONT&gt;&lt;FONT color=#2b91af size=2&gt;Server&lt;/FONT&gt;&lt;FONT size=2&gt;(txtServer.Text);&lt;/P&gt;
&lt;P&gt;&lt;/FONT&gt;&lt;FONT color=#2b91af size=2&gt;Database&lt;/FONT&gt;&lt;FONT size=2&gt; objDB = objServer.Databases[txtDatabase.Text];&lt;/P&gt;
&lt;P&gt;&lt;/FONT&gt;&lt;FONT color=#0000ff size=2&gt;string&lt;/FONT&gt;&lt;FONT size=2&gt; strCon = &lt;/FONT&gt;&lt;FONT color=#a31515 size=2&gt;"Data Source="&lt;/FONT&gt;&lt;FONT size=2&gt; + txtServer.Text + &lt;/FONT&gt;&lt;FONT color=#a31515 size=2&gt;";Initial Catalog=Rnd;Integrated Security=SSPI"&lt;/FONT&gt;&lt;FONT size=2&gt;;&lt;/P&gt;
&lt;P&gt;&lt;/FONT&gt;&lt;FONT color=#2b91af size=2&gt;SqlConnection&lt;/FONT&gt;&lt;FONT size=2&gt; objCon = &lt;/FONT&gt;&lt;FONT color=#0000ff size=2&gt;new&lt;/FONT&gt;&lt;FONT size=2&gt; &lt;/FONT&gt;&lt;FONT color=#2b91af size=2&gt;SqlConnection&lt;/FONT&gt;&lt;FONT size=2&gt;(strCon);&lt;/P&gt;
&lt;P&gt;objCon.Open();&lt;/P&gt;
&lt;P&gt;&lt;/FONT&gt;&lt;FONT color=#0000ff size=2&gt;int&lt;/FONT&gt;&lt;FONT size=2&gt; intTotalTables = ds.Tables.Count;&lt;/P&gt;
&lt;P&gt;&lt;/FONT&gt;&lt;FONT color=#2b91af size=2&gt;MessageBox&lt;/FONT&gt;&lt;FONT size=2&gt;.Show(&lt;/FONT&gt;&lt;FONT color=#a31515 size=2&gt;"Total Tables = "&lt;/FONT&gt;&lt;FONT size=2&gt; + intTotalTables.ToString());&lt;/P&gt;
&lt;P&gt;&lt;/FONT&gt;&lt;FONT color=#2b91af size=2&gt;Table&lt;/FONT&gt;&lt;FONT size=2&gt; T;&lt;/P&gt;
&lt;P&gt;&lt;/FONT&gt;&lt;FONT color=#0000ff size=2&gt;for&lt;/FONT&gt;&lt;FONT size=2&gt; (&lt;/FONT&gt;&lt;FONT color=#0000ff size=2&gt;int&lt;/FONT&gt;&lt;FONT size=2&gt; intTables = 0; intTables &amp;lt; intTotalTables; intTables++)&lt;/P&gt;
&lt;P&gt;{&lt;/P&gt;
&lt;P&gt;T = &lt;/FONT&gt;&lt;FONT color=#0000ff size=2&gt;new&lt;/FONT&gt;&lt;FONT size=2&gt; &lt;/FONT&gt;&lt;FONT color=#2b91af size=2&gt;Table&lt;/FONT&gt;&lt;FONT size=2&gt;(objDB, &lt;/FONT&gt;&lt;FONT color=#a31515 size=2&gt;"sqlCC_"&lt;/FONT&gt;&lt;FONT size=2&gt; + ds.Tables[intTables].TableName);&lt;/P&gt;
&lt;P&gt;&lt;/FONT&gt;&lt;FONT color=#2b91af size=2&gt;Column&lt;/FONT&gt;&lt;FONT size=2&gt; C = &lt;/FONT&gt;&lt;FONT color=#0000ff size=2&gt;new&lt;/FONT&gt;&lt;FONT size=2&gt; &lt;/FONT&gt;&lt;FONT color=#2b91af size=2&gt;Column&lt;/FONT&gt;&lt;FONT size=2&gt;();&lt;/P&gt;
&lt;P&gt;&lt;/FONT&gt;&lt;FONT color=#008000 size=2&gt;//MessageBox.Show(ds.Tables[intTables].Rows.Count.ToString());&lt;/P&gt;&lt;/FONT&gt;&lt;FONT size=2&gt;
&lt;P&gt;&lt;/FONT&gt;&lt;FONT color=#0000ff size=2&gt;foreach&lt;/FONT&gt;&lt;FONT size=2&gt; (&lt;/FONT&gt;&lt;FONT color=#2b91af size=2&gt;DataColumn&lt;/FONT&gt;&lt;FONT size=2&gt; dc &lt;/FONT&gt;&lt;FONT color=#0000ff size=2&gt;in&lt;/FONT&gt;&lt;FONT size=2&gt; ds.Tables[intTables].Columns)&lt;/P&gt;
&lt;P&gt;{&lt;/P&gt;
&lt;P&gt;C = &lt;/FONT&gt;&lt;FONT color=#0000ff size=2&gt;new&lt;/FONT&gt;&lt;FONT size=2&gt; &lt;/FONT&gt;&lt;FONT color=#2b91af size=2&gt;Column&lt;/FONT&gt;&lt;FONT size=2&gt;(T, dc.ColumnName);&lt;/P&gt;
&lt;P&gt;C.DataType = MapDataType(dc.DataType.ToString(), dc.MaxLength);&lt;/P&gt;
&lt;P&gt;T.Columns.Add(C);&lt;/P&gt;
&lt;P mce_keep="true"&gt;}&lt;/P&gt;
&lt;P&gt;T.Create();&lt;/P&gt;
&lt;P&gt;&lt;/FONT&gt;&lt;FONT color=#2b91af size=2&gt;SqlBulkCopy&lt;/FONT&gt;&lt;FONT size=2&gt; objBulkcopy = &lt;/FONT&gt;&lt;FONT color=#0000ff size=2&gt;new&lt;/FONT&gt;&lt;FONT size=2&gt; &lt;/FONT&gt;&lt;FONT color=#2b91af size=2&gt;SqlBulkCopy&lt;/FONT&gt;&lt;FONT size=2&gt;(objCon);&lt;/P&gt;
&lt;P mce_keep="true"&gt;objBulkcopy.DestinationTableName = &lt;/FONT&gt;&lt;FONT color=#a31515 size=2&gt;"sqlCC_"&lt;/FONT&gt;&lt;FONT size=2&gt; + ds.Tables[intTables].TableName;&lt;/P&gt;
&lt;P&gt;&lt;/FONT&gt;&lt;FONT size=2&gt;objBulkcopy.WriteToServer(ds.Tables[intTables]);&lt;/P&gt;
&lt;P&gt;&lt;/FONT&gt;&lt;FONT size=2&gt;objBulkcopy.Close();&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT size=2&gt;}&lt;/P&gt;
&lt;P mce_keep="true"&gt;objCon.Close();&lt;/P&gt;
&lt;P mce_keep="true"&gt;&lt;/FONT&gt;&lt;FONT color=#2b91af size=2&gt;MessageBox&lt;/FONT&gt;&lt;FONT size=2&gt;.Show(&lt;/FONT&gt;&lt;FONT color=#a31515 size=2&gt;"All tables are successfully loaded"&lt;/FONT&gt;&lt;FONT size=2&gt;);&lt;/P&gt;
&lt;P&gt;}&lt;/P&gt;&lt;/FONT&gt;
&lt;P mce_keep="true"&gt;Add a routine for mapping the data types.&lt;/P&gt;&lt;FONT size=2&gt;
&lt;P&gt;&lt;/FONT&gt;&lt;FONT color=#0000ff size=2&gt;public&lt;/FONT&gt;&lt;FONT size=2&gt; &lt;/FONT&gt;&lt;FONT color=#2b91af size=2&gt;DataType&lt;/FONT&gt;&lt;FONT size=2&gt; MapDataType(&lt;/FONT&gt;&lt;FONT color=#0000ff size=2&gt;string&lt;/FONT&gt;&lt;FONT size=2&gt; dataType, &lt;/FONT&gt;&lt;FONT color=#0000ff size=2&gt;int&lt;/FONT&gt;&lt;FONT size=2&gt; dataTypeLength)&lt;/P&gt;
&lt;P&gt;{&lt;/P&gt;
&lt;P&gt;&lt;/FONT&gt;&lt;FONT color=#2b91af size=2&gt;DataType&lt;/FONT&gt;&lt;FONT size=2&gt; DTTemp = &lt;/FONT&gt;&lt;FONT color=#0000ff size=2&gt;null&lt;/FONT&gt;&lt;FONT size=2&gt;;&lt;/P&gt;
&lt;P mce_keep="true"&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;/FONT&gt;&lt;FONT color=#0000ff size=2&gt;switch&lt;/FONT&gt;&lt;FONT size=2&gt; (dataType)&lt;/P&gt;
&lt;P&gt;{&lt;/P&gt;
&lt;P&gt;&lt;/FONT&gt;&lt;FONT color=#0000ff size=2&gt;case&lt;/FONT&gt;&lt;FONT size=2&gt; (&lt;/FONT&gt;&lt;FONT color=#a31515 size=2&gt;"System.Decimal"&lt;/FONT&gt;&lt;FONT size=2&gt;):&lt;/P&gt;
&lt;P&gt;DTTemp = &lt;/FONT&gt;&lt;FONT color=#0000ff size=2&gt;new&lt;/FONT&gt;&lt;FONT size=2&gt; &lt;/FONT&gt;&lt;FONT color=#2b91af size=2&gt;DataType&lt;/FONT&gt;&lt;FONT size=2&gt;(&lt;/FONT&gt;&lt;FONT color=#2b91af size=2&gt;SqlDataType&lt;/FONT&gt;&lt;FONT size=2&gt;.Decimal, 10, 2);&lt;/P&gt;
&lt;P&gt;&lt;/FONT&gt;&lt;FONT color=#0000ff size=2&gt;break&lt;/FONT&gt;&lt;FONT size=2&gt;;&lt;/P&gt;
&lt;P&gt;&lt;/FONT&gt;&lt;FONT color=#0000ff size=2&gt;case&lt;/FONT&gt;&lt;FONT size=2&gt; (&lt;/FONT&gt;&lt;FONT color=#a31515 size=2&gt;"System.String"&lt;/FONT&gt;&lt;FONT size=2&gt;):&lt;/P&gt;
&lt;P&gt;DTTemp = &lt;/FONT&gt;&lt;FONT color=#0000ff size=2&gt;new&lt;/FONT&gt;&lt;FONT size=2&gt; &lt;/FONT&gt;&lt;FONT color=#2b91af size=2&gt;DataType&lt;/FONT&gt;&lt;FONT size=2&gt;(&lt;/FONT&gt;&lt;FONT color=#2b91af size=2&gt;SqlDataType&lt;/FONT&gt;&lt;FONT size=2&gt;.VarChar, dataTypeLength);&lt;/P&gt;
&lt;P&gt;&lt;/FONT&gt;&lt;FONT color=#0000ff size=2&gt;break&lt;/FONT&gt;&lt;FONT size=2&gt;;&lt;/P&gt;
&lt;P&gt;&lt;/FONT&gt;&lt;FONT color=#0000ff size=2&gt;case&lt;/FONT&gt;&lt;FONT size=2&gt; (&lt;/FONT&gt;&lt;FONT color=#a31515 size=2&gt;"System.Int32"&lt;/FONT&gt;&lt;FONT size=2&gt;):&lt;/P&gt;
&lt;P&gt;DTTemp = &lt;/FONT&gt;&lt;FONT color=#0000ff size=2&gt;new&lt;/FONT&gt;&lt;FONT size=2&gt; &lt;/FONT&gt;&lt;FONT color=#2b91af size=2&gt;DataType&lt;/FONT&gt;&lt;FONT size=2&gt;(&lt;/FONT&gt;&lt;FONT color=#2b91af size=2&gt;SqlDataType&lt;/FONT&gt;&lt;FONT size=2&gt;.Int);&lt;/P&gt;
&lt;P&gt;&lt;/FONT&gt;&lt;FONT color=#0000ff size=2&gt;break&lt;/FONT&gt;&lt;FONT size=2&gt;;&lt;/P&gt;
&lt;P&gt;&lt;/FONT&gt;&lt;FONT color=#0000ff size=2&gt;case&lt;/FONT&gt;&lt;FONT size=2&gt; (&lt;/FONT&gt;&lt;FONT color=#a31515 size=2&gt;"System.Byte"&lt;/FONT&gt;&lt;FONT size=2&gt;):&lt;/P&gt;
&lt;P&gt;DTTemp = &lt;/FONT&gt;&lt;FONT color=#0000ff size=2&gt;new&lt;/FONT&gt;&lt;FONT size=2&gt; &lt;/FONT&gt;&lt;FONT color=#2b91af size=2&gt;DataType&lt;/FONT&gt;&lt;FONT size=2&gt;(&lt;/FONT&gt;&lt;FONT color=#2b91af size=2&gt;SqlDataType&lt;/FONT&gt;&lt;FONT size=2&gt;.Bit);&lt;/P&gt;
&lt;P&gt;&lt;/FONT&gt;&lt;FONT color=#0000ff size=2&gt;break&lt;/FONT&gt;&lt;FONT size=2&gt;;&lt;/P&gt;
&lt;P&gt;&lt;/FONT&gt;&lt;FONT color=#0000ff size=2&gt;case&lt;/FONT&gt;&lt;FONT size=2&gt; (&lt;/FONT&gt;&lt;FONT color=#a31515 size=2&gt;"System.DateTime"&lt;/FONT&gt;&lt;FONT size=2&gt;):&lt;/P&gt;
&lt;P&gt;DTTemp = &lt;/FONT&gt;&lt;FONT color=#0000ff size=2&gt;new&lt;/FONT&gt;&lt;FONT size=2&gt; &lt;/FONT&gt;&lt;FONT color=#2b91af size=2&gt;DataType&lt;/FONT&gt;&lt;FONT size=2&gt;(&lt;/FONT&gt;&lt;FONT color=#2b91af size=2&gt;SqlDataType&lt;/FONT&gt;&lt;FONT size=2&gt;.DateTime);&lt;/P&gt;
&lt;P&gt;&lt;/FONT&gt;&lt;FONT color=#0000ff size=2&gt;break&lt;/FONT&gt;&lt;FONT size=2&gt;;&lt;/P&gt;
&lt;P&gt;&lt;/FONT&gt;&lt;FONT color=#0000ff size=2&gt;case&lt;/FONT&gt;&lt;FONT size=2&gt; (&lt;/FONT&gt;&lt;FONT color=#a31515 size=2&gt;"System.Boolean"&lt;/FONT&gt;&lt;FONT size=2&gt;):&lt;/P&gt;
&lt;P&gt;DTTemp = &lt;/FONT&gt;&lt;FONT color=#0000ff size=2&gt;new&lt;/FONT&gt;&lt;FONT size=2&gt; &lt;/FONT&gt;&lt;FONT color=#2b91af size=2&gt;DataType&lt;/FONT&gt;&lt;FONT size=2&gt;(&lt;/FONT&gt;&lt;FONT color=#2b91af size=2&gt;SqlDataType&lt;/FONT&gt;&lt;FONT size=2&gt;.Int);&lt;/P&gt;
&lt;P&gt;&lt;/FONT&gt;&lt;FONT color=#0000ff size=2&gt;break&lt;/FONT&gt;&lt;FONT size=2&gt;;&lt;/P&gt;
&lt;P&gt;&lt;/FONT&gt;&lt;FONT color=#0000ff size=2&gt;case&lt;/FONT&gt;&lt;FONT size=2&gt; (&lt;/FONT&gt;&lt;FONT color=#a31515 size=2&gt;"System.SByte"&lt;/FONT&gt;&lt;FONT size=2&gt;):&lt;/P&gt;
&lt;P&gt;DTTemp = &lt;/FONT&gt;&lt;FONT color=#0000ff size=2&gt;new&lt;/FONT&gt;&lt;FONT size=2&gt; &lt;/FONT&gt;&lt;FONT color=#2b91af size=2&gt;DataType&lt;/FONT&gt;&lt;FONT size=2&gt;(&lt;/FONT&gt;&lt;FONT color=#2b91af size=2&gt;SqlDataType&lt;/FONT&gt;&lt;FONT size=2&gt;.Bit);&lt;/P&gt;
&lt;P&gt;&lt;/FONT&gt;&lt;FONT color=#0000ff size=2&gt;break&lt;/FONT&gt;&lt;FONT size=2&gt;;&lt;/P&gt;
&lt;P&gt;&lt;/FONT&gt;&lt;FONT color=#0000ff size=2&gt;case&lt;/FONT&gt;&lt;FONT size=2&gt; (&lt;/FONT&gt;&lt;FONT color=#a31515 size=2&gt;"System.UInt32"&lt;/FONT&gt;&lt;FONT size=2&gt;):&lt;/P&gt;
&lt;P&gt;DTTemp = &lt;/FONT&gt;&lt;FONT color=#0000ff size=2&gt;new&lt;/FONT&gt;&lt;FONT size=2&gt; &lt;/FONT&gt;&lt;FONT color=#2b91af size=2&gt;DataType&lt;/FONT&gt;&lt;FONT size=2&gt;(&lt;/FONT&gt;&lt;FONT color=#2b91af size=2&gt;SqlDataType&lt;/FONT&gt;&lt;FONT size=2&gt;.Int);&lt;/P&gt;
&lt;P&gt;&lt;/FONT&gt;&lt;FONT color=#0000ff size=2&gt;break&lt;/FONT&gt;&lt;FONT size=2&gt;;&lt;/P&gt;
&lt;P&gt;}&lt;/P&gt;
&lt;P&gt;&lt;/FONT&gt;&lt;FONT color=#0000ff size=2&gt;return&lt;/FONT&gt;&lt;FONT size=2&gt; DTTemp;&lt;/P&gt;
&lt;P&gt;}&lt;/P&gt;&lt;/FONT&gt;
&lt;P mce_keep="true"&gt;I am just using a prefix "sqlCC" while creating the target table. This is just for easy identification of the newly created tables in my target DB.&lt;/P&gt;
&lt;P mce_keep="true"&gt;&amp;nbsp;&lt;/P&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=8957035" width="1" height="1"&gt;</content><author><name>Ramoji</name><uri>http://blogs.msdn.com/Ramoji/ProfileUrlRedirect.ashx</uri></author></entry><entry><title>How to get missing values from an Identity column?</title><link rel="alternate" type="text/html" href="http://blogs.msdn.com/b/ramoji/archive/2008/09/17/how-to-get-missing-values-from-an-identity-column.aspx" /><id>http://blogs.msdn.com/b/ramoji/archive/2008/09/17/how-to-get-missing-values-from-an-identity-column.aspx</id><published>2008-09-17T12:56:00Z</published><updated>2008-09-17T12:56:00Z</updated><content type="html">&lt;FONT color=#0000ff size=2&gt;
&lt;P&gt;Let us assume that there is an Employee table with EmployeeId as the Identity column in which some values are missing. &amp;nbsp;The following batch will show all the missing values in that Identity column. The logic I preferred is to create another table with the same increment as that of the parent table but without any gaps. Finally, subtracting the parent table rows from the newly created table gives us the missed values. Rest of the&amp;nbsp;script is pretty straight forward and self explanatory.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;Declare&lt;/FONT&gt;&lt;FONT size=2&gt; @MinEmpId &lt;/FONT&gt;&lt;FONT color=#0000ff size=2&gt;int&lt;/P&gt;
&lt;P&gt;Declare&lt;/FONT&gt;&lt;FONT size=2&gt; @MaxEmpId &lt;/FONT&gt;&lt;FONT color=#0000ff size=2&gt;int&lt;/P&gt;
&lt;P&gt;Declare&lt;/FONT&gt;&lt;FONT size=2&gt; @sql &lt;/FONT&gt;&lt;FONT color=#0000ff size=2&gt;nvarchar&lt;/FONT&gt;&lt;FONT color=#808080 size=2&gt;(&lt;/FONT&gt;&lt;FONT size=2&gt;250&lt;/FONT&gt;&lt;FONT color=#808080 size=2&gt;)&lt;/P&gt;&lt;/FONT&gt;&lt;FONT color=#0000ff size=2&gt;
&lt;P&gt;select&lt;/FONT&gt;&lt;FONT size=2&gt; @MinEmpId &lt;/FONT&gt;&lt;FONT color=#808080 size=2&gt;=&lt;/FONT&gt;&lt;FONT size=2&gt; &lt;/FONT&gt;&lt;FONT color=#ff00ff size=2&gt;Min&lt;/FONT&gt;&lt;FONT color=#808080 size=2&gt;(&lt;/FONT&gt;&lt;FONT size=2&gt;EmployeeID&lt;/FONT&gt;&lt;FONT color=#808080 size=2&gt;),&lt;/FONT&gt;&lt;FONT size=2&gt;@MaxEmpId &lt;/FONT&gt;&lt;FONT color=#808080 size=2&gt;=&lt;/FONT&gt;&lt;FONT size=2&gt; &lt;/FONT&gt;&lt;FONT color=#ff00ff size=2&gt;Max&lt;/FONT&gt;&lt;FONT color=#808080 size=2&gt;(&lt;/FONT&gt;&lt;FONT size=2&gt;EmployeeID&lt;/FONT&gt;&lt;FONT color=#808080 size=2&gt;)&lt;/FONT&gt;&lt;FONT size=2&gt; &lt;/FONT&gt;&lt;FONT color=#0000ff size=2&gt;from&lt;/FONT&gt;&lt;FONT size=2&gt; Employee&lt;/P&gt;&lt;/FONT&gt;&lt;FONT color=#0000ff size=2&gt;
&lt;P&gt;SET&lt;/FONT&gt;&lt;FONT size=2&gt; @sql &lt;/FONT&gt;&lt;FONT color=#808080 size=2&gt;=&lt;/FONT&gt;&lt;FONT size=2&gt; &lt;/FONT&gt;&lt;FONT color=#ff0000 size=2&gt;'Create Table Temp1(Id int IDENTITY('&lt;/FONT&gt;&lt;FONT size=2&gt; &lt;/FONT&gt;&lt;FONT color=#808080 size=2&gt;+&lt;/FONT&gt;&lt;FONT size=2&gt; &lt;/FONT&gt;&lt;FONT color=#ff00ff size=2&gt;cast&lt;/FONT&gt;&lt;FONT color=#808080 size=2&gt;(&lt;/FONT&gt;&lt;FONT size=2&gt;@MinEmpId &lt;/FONT&gt;&lt;FONT color=#0000ff size=2&gt;as&lt;/FONT&gt;&lt;FONT size=2&gt; &lt;/FONT&gt;&lt;FONT color=#0000ff size=2&gt;varchar&lt;/FONT&gt;&lt;FONT color=#808080 size=2&gt;(&lt;/FONT&gt;&lt;FONT size=2&gt;25&lt;/FONT&gt;&lt;FONT color=#808080 size=2&gt;))+&lt;/FONT&gt;&lt;FONT size=2&gt; &lt;/FONT&gt;&lt;FONT color=#ff0000 size=2&gt;',1),DummyCol int)'&lt;/P&gt;&lt;/FONT&gt;&lt;FONT color=#0000ff size=2&gt;
&lt;P&gt;EXEC&lt;/FONT&gt;&lt;FONT size=2&gt; &lt;/FONT&gt;&lt;FONT color=#800000 size=2&gt;sp_executesql&lt;/FONT&gt;&lt;FONT size=2&gt; @sql&lt;/P&gt;&lt;/FONT&gt;&lt;FONT color=#0000ff size=2&gt;
&lt;P&gt;while&lt;/FONT&gt;&lt;FONT color=#808080 size=2&gt;(&lt;/FONT&gt;&lt;FONT size=2&gt;@MinEmpId &lt;/FONT&gt;&lt;FONT color=#808080 size=2&gt;&amp;lt;=&lt;/FONT&gt;&lt;FONT size=2&gt; @MaxEmpId&lt;/FONT&gt;&lt;FONT color=#808080 size=2&gt;)&lt;/P&gt;&lt;/FONT&gt;&lt;FONT color=#0000ff size=2&gt;
&lt;P&gt;begin&lt;/P&gt;&lt;/FONT&gt;&lt;FONT size=2&gt;
&lt;P&gt;&lt;/FONT&gt;&lt;FONT color=#0000ff size=2&gt;Insert&lt;/FONT&gt;&lt;FONT size=2&gt; &lt;/FONT&gt;&lt;FONT color=#0000ff size=2&gt;into&lt;/FONT&gt;&lt;FONT size=2&gt; Temp1&lt;/FONT&gt;&lt;FONT color=#808080 size=2&gt;(&lt;/FONT&gt;&lt;FONT size=2&gt;DummyCol&lt;/FONT&gt;&lt;FONT color=#808080 size=2&gt;)&lt;/FONT&gt;&lt;FONT size=2&gt; &lt;/FONT&gt;&lt;FONT color=#0000ff size=2&gt;Values&lt;/FONT&gt;&lt;FONT color=#808080 size=2&gt;(&lt;/FONT&gt;&lt;FONT size=2&gt;1&lt;/FONT&gt;&lt;FONT color=#808080 size=2&gt;)&lt;/P&gt;&lt;/FONT&gt;&lt;FONT size=2&gt;
&lt;P&gt;&lt;/FONT&gt;&lt;FONT color=#0000ff size=2&gt;set&lt;/FONT&gt;&lt;FONT size=2&gt; @MinEmpId &lt;/FONT&gt;&lt;FONT color=#808080 size=2&gt;=&lt;/FONT&gt;&lt;FONT size=2&gt; @MinEmpId &lt;/FONT&gt;&lt;FONT color=#808080 size=2&gt;+&lt;/FONT&gt;&lt;FONT size=2&gt; 1&lt;/P&gt;&lt;/FONT&gt;&lt;FONT color=#0000ff size=2&gt;
&lt;P&gt;end&lt;/P&gt;
&lt;P&gt;Select&lt;/FONT&gt;&lt;FONT size=2&gt; Id &lt;/FONT&gt;&lt;FONT color=#0000ff size=2&gt;from&lt;/FONT&gt;&lt;FONT size=2&gt; Temp1&lt;/P&gt;&lt;/FONT&gt;&lt;FONT color=#0000ff size=2&gt;
&lt;P&gt;Except&lt;/P&gt;
&lt;P&gt;Select&lt;/FONT&gt;&lt;FONT size=2&gt; EmployeeId &lt;/FONT&gt;&lt;FONT color=#0000ff size=2&gt;from&lt;/FONT&gt;&lt;FONT size=2&gt; Employee&lt;/P&gt;&lt;/FONT&gt;&lt;FONT color=#0000ff size=2&gt;
&lt;P&gt;Drop&lt;/FONT&gt;&lt;FONT size=2&gt; &lt;/FONT&gt;&lt;FONT color=#0000ff size=2&gt;Table&lt;/FONT&gt;&lt;FONT size=2&gt; Temp1&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT size=2&gt;The above script can be made reusable by making it a stored procedure using Dynamic Sql as shown below. It just accepts table name as a parameter and does the rest of the job.&lt;/FONT&gt;&lt;/P&gt;&lt;FONT color=#0000ff size=2&gt;
&lt;P&gt;CREATE&lt;/FONT&gt;&lt;FONT size=2&gt; &lt;/FONT&gt;&lt;FONT color=#0000ff size=2&gt;PROC&lt;/FONT&gt;&lt;FONT size=2&gt; GetMissingIds&lt;/FONT&gt;&lt;FONT color=#808080 size=2&gt;(&lt;/FONT&gt;&lt;FONT size=2&gt;@TableName &lt;/FONT&gt;&lt;FONT color=#0000ff size=2&gt;Varchar&lt;/FONT&gt;&lt;FONT color=#808080 size=2&gt;(&lt;/FONT&gt;&lt;FONT size=2&gt;50&lt;/FONT&gt;&lt;FONT color=#808080 size=2&gt;))&lt;/FONT&gt;&lt;FONT size=2&gt; &lt;/P&gt;&lt;/FONT&gt;&lt;FONT color=#0000ff size=2&gt;
&lt;P&gt;AS&lt;/FONT&gt;&lt;FONT size=2&gt; &lt;/P&gt;&lt;/FONT&gt;&lt;FONT color=#0000ff size=2&gt;
&lt;P&gt;BEGIN&lt;/FONT&gt;&lt;FONT size=2&gt; &lt;/P&gt;&lt;/FONT&gt;&lt;FONT color=#0000ff size=2&gt;
&lt;P&gt;Declare&lt;/FONT&gt;&lt;FONT size=2&gt; @MinEmpId &lt;/FONT&gt;&lt;FONT color=#0000ff size=2&gt;int&lt;/FONT&gt;&lt;FONT size=2&gt; &lt;/P&gt;&lt;/FONT&gt;&lt;FONT color=#0000ff size=2&gt;
&lt;P&gt;Declare&lt;/FONT&gt;&lt;FONT size=2&gt; @MaxEmpId &lt;/FONT&gt;&lt;FONT color=#0000ff size=2&gt;int&lt;/FONT&gt;&lt;FONT size=2&gt; &lt;/P&gt;&lt;/FONT&gt;&lt;FONT color=#0000ff size=2&gt;
&lt;P&gt;Declare&lt;/FONT&gt;&lt;FONT size=2&gt; @Increment &lt;/FONT&gt;&lt;FONT color=#0000ff size=2&gt;int&lt;/P&gt;
&lt;P&gt;Declare&lt;/FONT&gt;&lt;FONT size=2&gt; @sql &lt;/FONT&gt;&lt;FONT color=#0000ff size=2&gt;nvarchar&lt;/FONT&gt;&lt;FONT color=#808080 size=2&gt;(&lt;/FONT&gt;&lt;FONT size=2&gt;250&lt;/FONT&gt;&lt;FONT color=#808080 size=2&gt;)&lt;/FONT&gt;&lt;FONT size=2&gt; &lt;/P&gt;&lt;/FONT&gt;&lt;FONT color=#0000ff size=2&gt;
&lt;P&gt;SET&lt;/FONT&gt;&lt;FONT size=2&gt; @sql &lt;/FONT&gt;&lt;FONT color=#808080 size=2&gt;=&lt;/FONT&gt;&lt;FONT size=2&gt; &lt;/FONT&gt;&lt;FONT color=#ff0000 size=2&gt;'SELECT @Increment=IDENT_INCR('''&lt;/FONT&gt;&lt;FONT size=2&gt; &lt;/FONT&gt;&lt;FONT color=#808080 size=2&gt;+&lt;/FONT&gt;&lt;FONT size=2&gt; @TableName &lt;/FONT&gt;&lt;FONT color=#808080 size=2&gt;+&lt;/FONT&gt;&lt;FONT size=2&gt; &lt;/FONT&gt;&lt;FONT color=#ff0000 size=2&gt;''')'&lt;/P&gt;&lt;/FONT&gt;&lt;FONT color=#0000ff size=2&gt;
&lt;P&gt;EXEC&lt;/FONT&gt;&lt;FONT size=2&gt; &lt;/FONT&gt;&lt;FONT color=#800000 size=2&gt;sp_executesql&lt;/FONT&gt;&lt;FONT size=2&gt; @sql&lt;/FONT&gt;&lt;FONT color=#808080 size=2&gt;,&lt;/FONT&gt;&lt;FONT size=2&gt; N&lt;/FONT&gt;&lt;FONT color=#ff0000 size=2&gt;'@Increment Int OUTPUT'&lt;/FONT&gt;&lt;FONT color=#808080 size=2&gt;,&lt;/FONT&gt;&lt;FONT size=2&gt; @Increment &lt;/FONT&gt;&lt;FONT color=#0000ff size=2&gt;OUTPUT&lt;/FONT&gt;&lt;FONT size=2&gt; &lt;/P&gt;&lt;/FONT&gt;&lt;FONT color=#0000ff size=2&gt;
&lt;P&gt;SET&lt;/FONT&gt;&lt;FONT size=2&gt; @sql &lt;/FONT&gt;&lt;FONT color=#808080 size=2&gt;=&lt;/FONT&gt;&lt;FONT size=2&gt; &lt;/FONT&gt;&lt;FONT color=#ff0000 size=2&gt;'select @MinEmpId=Min($Identity),@MaxEmpId=Max($Identity) from '&lt;/FONT&gt;&lt;FONT size=2&gt; &lt;/FONT&gt;&lt;FONT color=#808080 size=2&gt;+&lt;/FONT&gt;&lt;FONT size=2&gt; @TableName &lt;/P&gt;&lt;/FONT&gt;&lt;FONT color=#0000ff size=2&gt;
&lt;P&gt;EXEC&lt;/FONT&gt;&lt;FONT size=2&gt; &lt;/FONT&gt;&lt;FONT color=#800000 size=2&gt;sp_executesql&lt;/FONT&gt;&lt;FONT size=2&gt; @sql&lt;/FONT&gt;&lt;FONT color=#808080 size=2&gt;,&lt;/FONT&gt;&lt;FONT size=2&gt; N&lt;/FONT&gt;&lt;FONT color=#ff0000 size=2&gt;'@MinEmpId Int OUTPUT,@MaxEmpId Int OUTPUT'&lt;/FONT&gt;&lt;FONT color=#808080 size=2&gt;,&lt;/FONT&gt;&lt;FONT size=2&gt;@MinEmpId &lt;/FONT&gt;&lt;FONT color=#0000ff size=2&gt;OUTPUT&lt;/FONT&gt;&lt;FONT color=#808080 size=2&gt;,&lt;/FONT&gt;&lt;FONT size=2&gt;@MaxEmpId &lt;/FONT&gt;&lt;FONT color=#0000ff size=2&gt;OUTPUT&lt;/FONT&gt;&lt;FONT size=2&gt; &lt;/P&gt;&lt;/FONT&gt;&lt;FONT color=#0000ff size=2&gt;
&lt;P&gt;SET&lt;/FONT&gt;&lt;FONT size=2&gt; @sql &lt;/FONT&gt;&lt;FONT color=#808080 size=2&gt;=&lt;/FONT&gt;&lt;FONT size=2&gt; &lt;/FONT&gt;&lt;FONT color=#ff0000 size=2&gt;'Create Table Temp1(Id int IDENTITY('&lt;/FONT&gt;&lt;FONT size=2&gt; &lt;/FONT&gt;&lt;FONT color=#808080 size=2&gt;+&lt;/FONT&gt;&lt;FONT size=2&gt; &lt;/FONT&gt;&lt;FONT color=#ff00ff size=2&gt;cast&lt;/FONT&gt;&lt;FONT color=#808080 size=2&gt;(&lt;/FONT&gt;&lt;FONT size=2&gt;@MinEmpId &lt;/FONT&gt;&lt;FONT color=#0000ff size=2&gt;as&lt;/FONT&gt;&lt;FONT size=2&gt; &lt;/FONT&gt;&lt;FONT color=#0000ff size=2&gt;varchar&lt;/FONT&gt;&lt;FONT color=#808080 size=2&gt;(&lt;/FONT&gt;&lt;FONT size=2&gt;25&lt;/FONT&gt;&lt;FONT color=#808080 size=2&gt;))+&lt;/FONT&gt;&lt;FONT size=2&gt; &lt;/FONT&gt;&lt;FONT color=#ff0000 size=2&gt;','&lt;/FONT&gt;&lt;FONT size=2&gt; &lt;/FONT&gt;&lt;FONT color=#808080 size=2&gt;+&lt;/FONT&gt;&lt;FONT size=2&gt; &lt;/FONT&gt;&lt;FONT color=#ff00ff size=2&gt;cast&lt;/FONT&gt;&lt;FONT color=#808080 size=2&gt;(&lt;/FONT&gt;&lt;FONT size=2&gt;@Increment &lt;/FONT&gt;&lt;FONT color=#0000ff size=2&gt;as&lt;/FONT&gt;&lt;FONT size=2&gt; &lt;/FONT&gt;&lt;FONT color=#0000ff size=2&gt;Varchar&lt;/FONT&gt;&lt;FONT color=#808080 size=2&gt;(&lt;/FONT&gt;&lt;FONT size=2&gt;10&lt;/FONT&gt;&lt;FONT color=#808080 size=2&gt;))&lt;/FONT&gt;&lt;FONT size=2&gt; &lt;/FONT&gt;&lt;FONT color=#808080 size=2&gt;+&lt;/FONT&gt;&lt;FONT size=2&gt; &lt;/FONT&gt;&lt;FONT color=#ff0000 size=2&gt;'),DummyCol int)'&lt;/FONT&gt;&lt;FONT size=2&gt; &lt;/P&gt;&lt;/FONT&gt;&lt;FONT color=#0000ff size=2&gt;
&lt;P&gt;EXEC&lt;/FONT&gt;&lt;FONT size=2&gt; &lt;/FONT&gt;&lt;FONT color=#800000 size=2&gt;sp_executesql&lt;/FONT&gt;&lt;FONT size=2&gt; @sql &lt;/P&gt;
&lt;P mce_keep="true"&gt;&amp;nbsp;&lt;/P&gt;&lt;/FONT&gt;&lt;FONT color=#0000ff size=2&gt;
&lt;P&gt;while&lt;/FONT&gt;&lt;FONT color=#808080 size=2&gt;(&lt;/FONT&gt;&lt;FONT size=2&gt;@MinEmpId &lt;/FONT&gt;&lt;FONT color=#808080 size=2&gt;&amp;lt;=&lt;/FONT&gt;&lt;FONT size=2&gt; @MaxEmpId&lt;/FONT&gt;&lt;FONT color=#808080 size=2&gt;)&lt;/FONT&gt;&lt;FONT size=2&gt; &lt;/P&gt;&lt;/FONT&gt;&lt;FONT color=#0000ff size=2&gt;
&lt;P&gt;begin&lt;/FONT&gt;&lt;FONT size=2&gt; &lt;/P&gt;
&lt;P&gt;&lt;/FONT&gt;&lt;FONT color=#0000ff size=2&gt;Insert&lt;/FONT&gt;&lt;FONT size=2&gt; &lt;/FONT&gt;&lt;FONT color=#0000ff size=2&gt;into&lt;/FONT&gt;&lt;FONT size=2&gt; Temp1&lt;/FONT&gt;&lt;FONT color=#808080 size=2&gt;(&lt;/FONT&gt;&lt;FONT size=2&gt;DummyCol&lt;/FONT&gt;&lt;FONT color=#808080 size=2&gt;)&lt;/FONT&gt;&lt;FONT size=2&gt; &lt;/FONT&gt;&lt;FONT color=#0000ff size=2&gt;Values&lt;/FONT&gt;&lt;FONT color=#808080 size=2&gt;(&lt;/FONT&gt;&lt;FONT size=2&gt;1&lt;/FONT&gt;&lt;FONT color=#808080 size=2&gt;)&lt;/FONT&gt;&lt;FONT size=2&gt; &lt;/P&gt;
&lt;P&gt;&lt;/FONT&gt;&lt;FONT color=#0000ff size=2&gt;set&lt;/FONT&gt;&lt;FONT size=2&gt; @MinEmpId &lt;/FONT&gt;&lt;FONT color=#808080 size=2&gt;=&lt;/FONT&gt;&lt;FONT size=2&gt; @MinEmpId &lt;/FONT&gt;&lt;FONT color=#808080 size=2&gt;+&lt;/FONT&gt;&lt;FONT size=2&gt; @Increment &lt;/P&gt;&lt;/FONT&gt;&lt;FONT color=#0000ff size=2&gt;
&lt;P&gt;end&lt;/FONT&gt;&lt;FONT size=2&gt; &lt;/P&gt;&lt;/FONT&gt;&lt;FONT color=#0000ff size=2&gt;
&lt;P&gt;SET&lt;/FONT&gt;&lt;FONT size=2&gt; @sql &lt;/FONT&gt;&lt;FONT color=#808080 size=2&gt;=&lt;/FONT&gt;&lt;FONT size=2&gt; &lt;/FONT&gt;&lt;FONT color=#ff0000 size=2&gt;'Select Id from Temp1 EXCEPT Select $Identity From '&lt;/FONT&gt;&lt;FONT size=2&gt; &lt;/FONT&gt;&lt;FONT color=#808080 size=2&gt;+&lt;/FONT&gt;&lt;FONT size=2&gt; @TableName&lt;/P&gt;&lt;/FONT&gt;&lt;FONT color=#0000ff size=2&gt;
&lt;P&gt;EXEC&lt;/FONT&gt;&lt;FONT size=2&gt; &lt;/FONT&gt;&lt;FONT color=#800000 size=2&gt;sp_executesql&lt;/FONT&gt;&lt;FONT size=2&gt; @sql &lt;/P&gt;
&lt;P mce_keep="true"&gt;&amp;nbsp;&lt;/P&gt;&lt;/FONT&gt;&lt;FONT color=#0000ff size=2&gt;
&lt;P&gt;Drop&lt;/FONT&gt;&lt;FONT size=2&gt; &lt;/FONT&gt;&lt;FONT color=#0000ff size=2&gt;Table&lt;/FONT&gt;&lt;FONT size=2&gt; Temp1 &lt;/P&gt;
&lt;P mce_keep="true"&gt;&amp;nbsp;&lt;/P&gt;&lt;/FONT&gt;&lt;FONT color=#0000ff size=2&gt;
&lt;P&gt;END&lt;/P&gt;&lt;/FONT&gt;
&lt;P&gt;&lt;FONT size=2&gt;Hope this helps.&lt;/P&gt;&lt;/FONT&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=8955385" width="1" height="1"&gt;</content><author><name>Ramoji</name><uri>http://blogs.msdn.com/Ramoji/ProfileUrlRedirect.ashx</uri></author></entry></feed>