Using SQL-DMO Transfer Object

  • Has anyone used the Transfer object in association with the Database object using VB, I need to transfer some tables from one database to the another on the same SQL Server. I know there is something simple that I am missing.

  • I have not. Andy is out of touch for the holidays for the most part, but I will try and contact him.

    Steve Jones

    steve@dkranch.net

  • Thanks, I will be looking forward to any insights he might have.

  • I have not tried it yet. Im catching up on email, give me a day or so and I'll see what I can come up with.

    Andy

  • Here is sample code to copy the structure of a table from Northwind to Pubs and then append the data.

    Dim oServer As SQLDMO.SQLServer

    Dim oDatabase As SQLDMO.Database

    Dim otransfer As SQLDMO.Transfer

    Set oServer = New SQLDMO.SQLServer

    With oServer

    .LoginSecure = True

    .Connect

    End With

    Set oDatabase = oServer.Databases("Northwind")

    Set otransfer = New Transfer

    With otransfer

    .AddObjectByName "Categories", SQLDMOObj_UserTable

    .CopyData = SQLDMOCopyData_Append

    .DestServer = "."

    .DestDatabase = "Pubs"

    .DestUseTrustedConnection = True

    End With

    oDatabase.Transfer otransfer

    Set oDatabase = Nothing

    oServer.DisConnect

    Set oServer = Nothing

    It's an interesting object, lots of times it might be handy! I'll probably do an article or two in the next couple months just to document things I find as I explore it more. Depending on what you're trying to accomplish it may be helpful to walk through the wizard to think about exactly which options you're setting, then explore how to do it code. An easier way is to create a package that does the task for you and tweak until it's correct, then save out as VB code.

    Andy

  • Worked like a charm! That saves me alot of coding.

  • Glad we could help!

    Andy

Viewing 7 posts - 1 through 6 (of 6 total)

You must be logged in to reply to this topic. Login to reply