CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 6 of 6
  1. #1
    Join Date
    Jan 2006
    Posts
    197

    How to copy data from a DB to other DB in different server

    I have to query one table and insert the result in a table on another database in another server
    The query is "select ID, name from Table"
    The other table exists and have the same fields.
    How can I do this?
    thanks!

  2. #2
    Join Date
    Jan 2006
    Location
    Fox Lake, IL
    Posts
    15,007

    Re: How to copy data from a DB to other DB in different server

    Write two queries. Copy from one, then save to the other. Use two connection strings, to different servers.
    David

    CodeGuru Article: Bound Controls are Evil-VB6
    2013 Samples: MS CODE Samples

    CodeGuru Reviewer
    2006 Dell CSP
    2006, 2007 & 2008 MVP Visual Basic
    If your question has been answered satisfactorily, and it has been helpful, then, please, Rate this Post!

  3. #3
    Join Date
    Jan 2006
    Posts
    197

    Re: How to copy data from a DB to other DB in different server

    Quote Originally Posted by dglienna View Post
    Write two queries. Copy from one, then save to the other. Use two connection strings, to different servers.
    Sorry, That is what I have now :S sorry about not telling that before
    I have the 2 connection strings, have the first query.
    But dont know what to do with the result of the first query (sorry Im new in VB.NET) in VB6 i think I would be using recordsets...filling the recordset and loop while inserting each value in the seccond DB.
    What will be the best approach in .NET?
    Thanks again dglienna

  4. #4
    Join Date
    Jun 2004
    Location
    Kashmir, India
    Posts
    6,808

    Re: How to copy data from a DB to other DB in different server

    In a similar way, you could open a Datareader and then loop through the datareader and insert 1 record at a time in the second database.

  5. #5
    Join Date
    Nov 2009
    Posts
    4

    Re: How to copy data from a DB to other DB in different server

    yes the data reader approach will work but to have an optimized solution in your case, I think you have to avoid the data reader in this situation since the source and target are in different servers.

    using dataadaptor approch is better in this scenario. (Get the whole data without looping, then close the connection, then paste the data to other server)
    what i mean is to minimize the connection opened between both servers while looping or doing any stuff.

    Generally the design of ado.net is different than classic ado in terms of continues connectivity to the database.

  6. #6
    Join Date
    Jan 2006
    Location
    Fox Lake, IL
    Posts
    15,007

    Re: How to copy data from a DB to other DB in different server

    Quote Originally Posted by Eltokhy View Post
    yes the data reader approach will work but to have an optimized solution in your case, I think you have to avoid the data reader in this situation since the source and target are in different servers.
    The other table exists and have the same fields.

    The DR is a good thing.
    David

    CodeGuru Article: Bound Controls are Evil-VB6
    2013 Samples: MS CODE Samples

    CodeGuru Reviewer
    2006 Dell CSP
    2006, 2007 & 2008 MVP Visual Basic
    If your question has been answered satisfactorily, and it has been helpful, then, please, Rate this Post!

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