Changing/Igoring text in stored procedures

Brian DonahueBrian Donahue Posts: 6,590 New member
edited August 9, 2004 11:35AM in SQL Toolkit Previous Versions
Hi Ben,

I think that the best thing to do for now would be to do the
modifications outside of the SQLCompare.Engine namespace. If you are writing
an application that is running the migration SQL rather than simply saving a
file to disk, you could use System.Data.SqlClient to run the migration SQL
produced by Toolkit and modify the SQL before you run it. Here is an example
of what I mean:

/* Assume you've already done a comparison and have an ExecutionBlock
returned by BuildFromDifferences */
ExecutionBlock eb = obWork.ExecutionBlock;
Batch b;
SqlConnection conn=new
SqlCommand sc=new SqlCommand();
for (int iCount=0; iCount<eb.BatchCount; iCount++)
/* Replace server1 with server2 before running this! */
sc.CommandText=b.Contents.Replace("Server1", "Server2");
if (!b.Marker) sc.ExecuteNonQuery();
catch (SqlException se)
Console.WriteLine("SQL Execution failed with error:

I hope this helps!


Brian Donahue
Red Gate Technical Support

"Benjamin S. Lam" <[email protected]> wrote in message
news:BszKmv%[email protected]
> Hi!
> I'm currently evaluating the toolkit.
> We have a number of related databases and in many of the stored procedures
> and views we use 3 and 4-part names. When we move database objects to a
> different environment (QA, Production), we replace the server and/or
> database names in the objects.
> So, when I compare from my Development servers to my Production or QA
> servers, I know that all instances of "server1.database1.dbo.SP1" should
> replaced with "server2.database1.dbo.SP1" or "database1.dbo.SP1" should be
> replaced with "database2.dbo.SP1" so that I don't end up with thousands of
> differences that I expect.
> Is there anyway to do this string replacement before starting the compare
> after either registering a live database connection or loading the
> from disk? For instance, I looked at modifying the "Text" property of an
> Item of the StoredProcedures collection, but this property is read-only.
> there another way to do this or would it be possible to make the "Text"
> property writable as well?
> Thanks for your time and assistance,
> Ben Lam
This discussion has been closed.