Wednesday, March 21, 2012

Generating Scripts from SQL Server 2000 using DMO and C#

Hi,

I'm generate scripts from a sql server 2000 database using DMO and C#.

the probelm am having is that when i try to generate views i get views *and* tables!

i tried to get rid of the tables:

SQLDMO.Transfer2 transfer = new SQLDMO.Transfer2Class();

transfer.CopyAllViews = true;

transfer.CopyAllTables = false;

transfer.IncludeDependencies = false;

i tried adding the views using AddObject:

foreach (SQLDMO.DBObject o in db.ListObjects(SQLDMO.SQLDMO_OBJECT_TYPE.SQLDMOObj_View, SQLDMO.SQLDMO_OBJSORT_TYPE.SQLDMOObjSort_Name))

transfer.AddObject(o);

but still tables got generated!

what am i doing wrong? i know that this is doable coz i can do it using enterprise manager (it also uses DMO right?)

any help is greatly appreciated.

Thank you.

aghoneim

P.S.

Script generation options:

transfer.ScriptType = SQLDMO.SQLDMO_SCRIPT_TYPE.SQLDMOScript_Default |

SQLDMO.SQLDMO_SCRIPT_TYPE.SQLDMOScript_Drops |

SQLDMO.SQLDMO_SCRIPT_TYPE.SQLDMOScript_ToFileOnly;

transfer.Script2Type = SQLDMO.SQLDMO_SCRIPT2_TYPE.SQLDMOScript2_UnicodeFile;

Is there a particular reason you want to use DMO? You could easily achieve what you want through SMO, which works fine against SQL 2000 You might be able to achieve what you want through DMO, but off hand I am not sure of code. If SMO won't work for you, I will try to dig up some DMO samples that "may" help you...Enterprise Manager does use DMO, but it may be doing some additional filtering on the client.

Peter

|||

Hi Peter,

I have to use DMO coz we own SQL 2000, and also coz of build server restrictions (this is for a build script).

But assuming i got perm for installing SMO on the build server, can i get SMO without buying SQL 2005?

Thanks.

aghoneim

|||Hi,

good news, yes you can.

http://www.microsoft.com/downloads/details.aspx?FamilyID=d09c1d60-a13c-4479-9b91-9e8b9d835cdc&DisplayLang=en

HTH, Jens Suessmeyer.

http://www.sqlserver2005.de
|||

Hey,

Thanks alot :)

aghoneim

sql

No comments:

Post a Comment