SQL-DMO problems
From: Zoury (yanick_lefebvre_at_hotmail.com)
Date: 05/05/04
- Next message: Ilya Margolin: "Re: IP-addresse"
- Previous message: Rick Charnes: "Question about Query Analyzer"
- Next in thread: Zoury: "Re: SQL-DMO problems"
- Reply: Zoury: "Re: SQL-DMO problems"
- Messages sorted by: [ date ] [ thread ]
Date: Wed, 5 May 2004 11:08:46 -0400
Hi all! :O)
I'm trying to generate the sql script for a given database. For some reason
the script file isn't created on the disk.. I can see the beginning of the
script on the first row of the [Grids] tab though (QA)... any idea?
--- declare @DatabaseCollection int declare @Server int declare @Transfer int declare @Database int declare @hr int declare @src varchar(255) declare @desc varchar(255) -- intializes the server object exec @hr = sp_OACreate 'SQLDMO.SQLServer', @Server OUT exec @hr = sp_OASetProperty @Server, 'LoginSecure', 'TRUE' -- connects to the server exec @hr = sp_OAMethod @Server, 'Connect', null, null, null ,null if @hr <> 0 begin exec sp_OAGetErrorInfo @Server, @src OUT, @desc OUT select convert(varbinary(4), @hr) as hr, @src as Source, @desc as [Description] return end -- get the database collection exec @hr = sp_OAGetProperty @Server, 'Databases', @DatabaseCollection OUT if @hr <> 0 begin exec sp_OAGetErrorInfo @Server, @src OUT, @desc OUT select convert(varbinary(4), @hr) as hr, @src as Source, @desc as [Description] return end -- get database we want from the collection exec @hr = sp_OAMethod @DatabaseCollection, 'Item', @Database OUT, 'te' if @hr <> 0 begin exec sp_OAGetErrorInfo @Server, @src OUT, @desc OUT select convert(varbinary(4), @hr) as hr, @src as Source, @desc as [Description] return end -- intializes the transfer object exec @hr = sp_OACreate 'SQLDMO.Transfer', @Transfer OUT exec @hr = sp_OASetProperty @Transfer, 'CopySchema', 1 exec @hr = sp_OASetProperty @Transfer, 'CopyAllObjects', 1 exec @hr = sp_OASetProperty @Transfer, 'CopyData', 0 -- launch the script generation exec @hr = sp_OAMethod @Database, 'ScriptTransfer', null, @Transfer, 2, 'c:\myscript.sql' if @hr <> 0 begin exec sp_OAGetErrorInfo @Server, @src OUT, @desc OUT select convert(varbinary(4), @hr) as hr, @src as Source, @desc as [Description] return end -- disconnect from the server exec @hr = sp_OAMethod @Server, 'DisConnect' -- clean up exec sp_OADestroy @Database exec sp_OADestroy @DatabaseCollection exec sp_OADestroy @Transfer exec sp_OADestroy @Server --- -- Best Regards Yanick Lefebvre
- Next message: Ilya Margolin: "Re: IP-addresse"
- Previous message: Rick Charnes: "Question about Query Analyzer"
- Next in thread: Zoury: "Re: SQL-DMO problems"
- Reply: Zoury: "Re: SQL-DMO problems"
- Messages sorted by: [ date ] [ thread ]
Relevant Pages
|