multiple database access

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • svbs tech
    New Member
    • Jan 2012
    • 7

    multiple database access

    hi
    i am using vb6 and i want to access two database in single query. both the databases are password protected. i want to select all records from first database which are not in the second database..
    please help me..
  • Rabbit
    Recognized Expert MVP
    • Jan 2007
    • 12517

    #2
    You can't do it in one query. You'll have to use two recordsets and then compare both in code.

    Comment

    • svbs tech
      New Member
      • Jan 2012
      • 7

      #3
      i did it in one single query without password proctected database. but i dont know how to write query for password protected databases.
      the code is

      Dim AdoConn As ADODB.Connectio n, AdoRSet As ADODB.Recordset
      Dim AdoConn1 As ADODB.Connectio n, AdoRSet1 As ADODB.Recordset
      Dim sCon As String
      Dim AdoPassword As String
      Dim AdoErr As Byte

      AdoDatabasePath = App.Path & "\db.mdb"
      AdoPassword = "xyz"
      'CONNECTION STRING
      sCon = "Provider=Micro soft.Jet.OLEDB. 4.0;Password=;" & _
      "User ID=Admin;Data Source=" & AdoDatabasePath & ";" & _
      "Jet OLEDB:Database Password='" & AdoPassword & "'"
      Set AdoConn = New ADODB.Connectio n
      AdoConn.Open sCon

      AdoDatabasePath = App.Path & "\db1.mdb"
      sCon = "Provider=Micro soft.Jet.OLEDB. 4.0;Password=;" & _
      "User ID=Admin;Data Source=" & AdoDatabasePath & ";" & _
      "Jet OLEDB:Database Password='" & AdoPassword & "'"
      Set AdoConn1 = New ADODB.Connectio n
      AdoConn1.Open AdoConn.Execute ("select * from test")

      qu = "select distinct(a.test ) from test a where a.test not in (select * from [;database=" & AdoConn1 & "].test12 ) "

      Set AdoRSet = AdoConn.Execute (qu)

      Comment

      • Rabbit
        Recognized Expert MVP
        • Jan 2007
        • 12517

        #4
        Please use code tags when posting code.

        I stand corrected, you can access other databases from the SQL engine.

        However, with a secured Access database, you have to set other options because Access does not use the username and pwd sections of a connection string.

        You need to use
        Code:
        ' Establish the location of the SYSTEM.MDA files if in another
           ' directory other than the \WINDOWS directory:
           SetDataAccessOption 1, "C:\MYDIR\MYAPP.INI"
           ' Log on to a valid account:
           SetDefaultWorkspace "admin", "<password>"
        to set up the needed access.

        Source: http://support.microsoft.com/kb/113701

        Also, according to the source, the connection only needs to be set up with the path
        Code:
        [;database=C:\ACCESS\DB1.MDB]

        Comment

        • svbs tech
          New Member
          • Jan 2012
          • 7

          #5
          please tell me how to specify password in [;database=C:\AC CESS\DB1.MDB] statement to connect with the second database.

          Comment

          • Rabbit
            Recognized Expert MVP
            • Jan 2007
            • 12517

            #6
            You don't, at least not through the connection string. You set it up using the options I posted before that.

            Comment

            Working...