how to get to individual script from differences object
yzguy
Posts: 23 Bronze 2
How do I get to the script for each of the objects in each db from a Differences object?
I found a round about way to get to the stored procedures, looking up each one by name through the data base object
_differences[100].ObjectIn1.Database.StoredProcedures["dbo", "sp_name"].Text
above is assuming the 100 index is an sp with the name "sp_name", but really the index I use there does not matter, because it is just getting to the db, it is really looking it up by name. I assume there is a way to get to the scipt object directly from the differences instance. Something like:
_differences[100].ObjectIn1.ScriptText
or if there is not a more direct way of getting the script text, how do I get the complete create table script (I could live with the round about method for getting SP scripts, but don't see any way to get the complete table scripts)? something like this?
_differences[0].ObjectIn1.Database.Tables["dbo", "test"].??
I found a round about way to get to the stored procedures, looking up each one by name through the data base object
_differences[100].ObjectIn1.Database.StoredProcedures["dbo", "sp_name"].Text
above is assuming the 100 index is an sp with the name "sp_name", but really the index I use there does not matter, because it is just getting to the db, it is really looking it up by name. I assume there is a way to get to the scipt object directly from the differences instance. Something like:
_differences[100].ObjectIn1.ScriptText
or if there is not a more direct way of getting the script text, how do I get the complete create table script (I could live with the round about method for getting SP scripts, but don't see any way to get the complete table scripts)? something like this?
_differences[0].ObjectIn1.Database.Tables["dbo", "test"].??
Comments
You can also create a Work object and use the Work.ScriptObject method.
Redgate Software
Work work = new Work();
// Retrieve the script for a particular table
Regions regions = work.ScriptObject(_differences[0].ObjectIn1.Database.Tables["dbo", "acct"], o);
string tmp = regions.ToString();
but the question still remains, is there a more direct method from the differences object to get the indvidual scripts?
You should also be able to use the ScriptObject method in Work directly on the ObjectIn1 / ObjectIn2 objects rather than having to go through the Database property.
Redgate Software
Thanks