title: How to connect to two databases in one connection string in C#?
body: <p>Normally, when I need to connect to a database using C#, I would use the following command routines below:<br>
  - define a mysql connection.<br>
  - open a mysql connection.<br>
  - define a sql statement / query.<br>
  - use MySqlCommand to execute the query.    </p>
  
  <p>Sample codes:  </p>
  
  <pre><code>string con1 = "server=&lt;db1 IP&gt;;User Id=user;password=password;Persist Security Info=True;database=db1";
  string con2 = "server=&lt;db2 IP&gt;;User Id=user;password=password;Persist Security Info=True;database=db2";
  MySqlConnection cn1 = new MySqlConnection(con1);
  MySqlConnection cn2 = new MySqlConnection(con2);
  MySqlCommand com
  
  cn1.Open();
  string sql = "some query";
  com = new MySqlCommand(sql, cn1);
  com.executeNonQuery();  
  cn1.Close();
  </code></pre>
  
  <p>My problem above is on the part where I use the MySqlCommand command because it is where a database connection is indicated so that it will now which database to query to like  </p>
  
  <pre><code>MySqlCommand com = new MySqlCommand(sql, con);  
  </code></pre>
  
  <p>where sql is a sql statement and con is a connection to be used for the query.</p>
  
  <p>How do I query two databases in one sql statement?<br>
  Consider the following: (I'm using MySQL)</p>
  
  <pre><code>- I have two databases, db1 and db2.
  - db1 is located in City A
  - db1 is located in City B
  - Both databases have one table (tbl) and they both have the same structure.
  - Table structure for tbl:
      +-------------+--------------+------+-----+---------+-------+
      | Field       | Type         | Null | Key | Default | Extra |
      +-------------+--------------+------+-----+---------+-------+
      | id          | int(9)       | NO   | PRI |         |       |
      | ref_no      | int(9)       | NO   |     |         |       |
      | name        | varchar(10)  | YES  |     | NULL    |       |
      +-------------+--------------+------+-----+---------+-------+
  - I want to run a query on db1.tbl against db2.tbl
  - Example query: "select ref_no from db1.tbl where ref_no not in (select ref_no from db2.tbl)"  
  </code></pre>
  
  <p>Or is there another way for this kind of problem?...</p>