Results 1 to 3 of 3

Thread: Call 2 different databases

  1. #1

    Thread Starter
    Addicted Member raptormanad's Avatar
    Join Date
    Oct 2008
    Posts
    224

    Call 2 different databases

    Is it possible to call 2 different databases on different machines? Say one local database and one off site through ODBC while using a loop? Something like:

    Code:
    Dim objConn As New ADODB.Connection
    objConn.Open "dsn=connone;UID=one;pwd=one;database=one"
    
    SQL = "SELECT * FROM db1.dbo.tblone "
    Set RS = objConn.execute
    
    While not RS.eof
    
    Dim objConn As New ADODB.Connection
    objConn.Open "dsn=conntwo;UID=two;pwd=two;database=two"
    
    SQL = "UPDATE blah blah blah"
    
    RS.Movenext
    Wend
    RS.close
    Set Rs = Nothing

  2. #2
    Frenzied Member
    Join Date
    Mar 2009
    Posts
    1,182

    Re: Call 2 different databases

    hmmm.... more like...

    pseudo code...

    adoCn00.open "connection string for db1"
    adoCn01.open "connection string for db2"

    adoRs00.Open "SELECT * FROM tablename", adoCn00, ...
    Do While Not adoRs00.EOF
    strSQL = "INSERT INTO tablename(textfieldname, numberfieldname) VALUE('" & adoRs00.Fields("textField") & "'," & adoRs00.Fields("NumberField") & ")"
    adoCn01.Execute strSQL
    DoEvents ' to keep program responsive
    Loop

    But some database will allow you to get external data... even from other databases which would be more efficient especially if you are using three machines, ie, two servers and one transaction machine because it would really hit your network hard going from S1 to T1 and then back out to S2 (Server/Transaction/Server), instead of going from S1 to S2. So check the documentation of the DBMS you are using before trying to go this pull/loop/push route...



    Good Luck
    Option Explicit should not be an Option!

  3. #3
    Super Moderator si_the_geek's Avatar
    Join Date
    Jul 2002
    Location
    Bristol, UK
    Posts
    41,974

    Re: Call 2 different databases

    Thread moved to 'Database Development' forum (the 'VB6' forum is only meant for questions which don't fit in more specific forums)

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