CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 3 of 3
  1. #1
    Join Date
    Aug 2003
    Location
    NJ,USA
    Posts
    7

    How to copy stored procedures

    Hi All,

    I want to copy all stored procedures from one DB server to another(on different machine) .
    I know how to do tables and using query builder as well.
    Is there any generic method to import/export all stored procedures?

    thanks

  2. #2
    Join Date
    May 2003
    Location
    upstate NY
    Posts
    168
    Try this

    Code:
    DECLARE @objDMO int
    DECLARE @objDatabase int
    DECLARE @dbname varchar(200)
    DECLARE @procedurename varchar(200)
    DECLARE @cmd varchar(300)
    DECLARE @temp varchar(8000)
    
    SET @dbname = 'Your Database'
    SET @procedurename = 'dbo.PROCEDURE_NAME'
    
    EXEC sp_OACreate 'SQLDMO.SQLServer', @objDMO OUT
    EXEC sp_OASetProperty @objDMO, 'loginsecure', 'true'
    EXEC sp_OAMethod @objDMO, 'Connect', NULL, '(local)'
    
    SET @cmd = 'Databases("' + @dbname + '").Procedur("' + @procedurename + '").Script'
    EXEC sp_OAMethod @objDMO, @cmd , @temp OUTPUT, 4
    PRINT @temp
    
    EXEC sp_OADestroy @objDMO
    
    SELECT * FROM SYSOBJECTS
    
    declare @cmd2 varchar(255)
    declare GetTriggers cursor fast_forward
    for
    select 'sp_helptext [' + name + ']' from sysobjects where type = 'P'
    open GetTriggers
    fetch next from GetTriggers into @cmd2
    
    while @@fetch_status = 0
    begin
    exec (@cmd2)
    print 'GO'
    fetch next from GetTriggers into @cmd2
    end
    Will
    --------------------------------------------
    Tell me and I will forget
    Show me and I will remember
    Teach me and I will learn

  3. #3
    Join Date
    Aug 2003
    Location
    NJ,USA
    Posts
    7

    Re: How to copy stored procedures

    Thank you very much for your reply.
    But I'm still not sure how will I execute this method.

    Let's say my config is as follows then where & what parameters need to be passed...

    Source Machine Name - M1
    Source DB Name - DB1

    Destination Machine Name - M2
    Destination DB Name - DB2

    waiting for reply...
    thanks.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured