Open 2 Database Connections?

Results 1 to 3 of 3

Thread: Open 2 Database Connections?

  1. #1
    Dee Guest

    Default Open 2 Database Connections?

    I need to do a SQL join of two tables in different databases. I know the SQL code to do this but I need to know if it is possible to have two database connections at the same time and how I might go about doing that. Any help would be great. Thanks

  2. #2
    Join Date
    Dec 1969
    Posts
    64

    Default RE: Open 2 Database Connections?

    This is how I&#039ve done it, but without a join. I hope this makes sense.<BR><BR>&#039-- set connection for queries <BR>If Not IsObject(Connect) Then<BR>&nbsp;&nbsp;&nbsp;Set Connect = Server.CreateObject("ADODB.Connection")<BR>End If<BR>&#039-- query 1<BR>Set rs1 = Server.CreateObject("ADODB.RecordSet")<BR>Connect. Open ConnectionString<BR>SQLStmt = "SELECT DISTINCT " & _<BR>&nbsp;&nbsp;&nbsp;"field1," & _<BR>&nbsp;&nbsp;&nbsp;"field_etc" & _<BR>&nbsp;&nbsp;&nbsp;"FROM table_name"<BR>rs1.Open SQLStmt,Connect<BR>Do While Not rs1.EOF<BR>&nbsp;&nbsp;field1 = rs1("field1")<BR>&nbsp;&nbsp;field_etc = rs1("field_etc")<BR>&nbsp;&nbsp;Response.Write "field1 = " & field1 & "&lt;br&gt;"<BR>&nbsp;&nbsp;Response.Write "field_etc = " & field_etc & &lt;br&gt;"<BR>&nbsp;&nbsp;&#039-- set connection for query 2 <BR>&nbsp;&nbsp;&#039-- this was only way I could get it to work:<BR>&nbsp;&nbsp;If IsObject(Connect2) Then<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Connect2.Clo se<BR>&nbsp;&nbsp;End If<BR>&nbsp;&nbsp;If Not IsObject(Connect2) Then<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Set Connect2 = Server.CreateObject("ADODB.Connection")<BR>&nbsp;& nbsp;End If<BR><BR>&nbsp;&nbsp;&#039-- query 2<BR>&nbsp;&nbsp;Connect2.Open ConnectionString<BR>&nbsp;&nbsp;SQLStmt2 = "SELECT * FROM table2 " & _<BR>&nbsp;&nbsp;&nbsp;&nbsp;"WHERE field1 = &#039" & field1 &"&#039"<BR>&nbsp;&nbsp;Set rs2 = Connect2.Execute(SQLStmt2)<BR>&nbsp;&nbsp;&#039-- assign variables, printout variables<BR><BR>&nbsp;&nbsp;rs.MoveNext<BR>loop<B R>&#039 --- Close connections ---------------------------------------<BR>Connect2.Close<BR>Connect.Close<BR>

  3. #3
    Join Date
    Dec 1969
    Posts
    64

    Default RE: Open 2 Database Connections?

    (Oops. There&#039s a quote missing in the code I posted.) :o)<BR><BR>Response.Write "field_etc = " & field_etc & "&lt;brgt;"

Posting Permissions

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