title: How to execute a query which uses multiple database
body: <p>I am developing an ASP.Net website. I have to execute a query which fetches data from two different database.</p>
  
  <p>I have two SqlConnection objects for these connections.</p>
  
  <p>I have both the connections open. But in SqlCommand object, I can specify just one SqlConnection object.</p>
  
  <pre><code>     SqlConnection conn = new SqlConnection("Data Source=xxx;Initial Catalog=xxx1;User ID=web_writeonly;Password=aaa;Network Library=DBMSSOCN");
       SqlConnection conn1 = new SqlConnection("Data Source=xxx;Initial Catalog=xxx2;User ID=randomUser;Password=bbb;Network Library=DBMSSOCN");
  
         conn.open();
  
         conn1.open();
  
         SqlCommand cmdUserInfo = new SqlCommand("&lt;query goes here&gt;", conn);
      cmdUserInfo.Parameters.Add("@ifa", SqlDbType.NVarChar).Value = ifacode;
      SqlDataAdapter sdaUserInfo = new SqlDataAdapter(cmdUserInfo);
      sdaUserInfo.Fill(dtSummaryTbl);
  
      conn.Close();
      conn1.Close();
  </code></pre>
  
  <p>When I execute this code snippet, I get an error "The SELECT permission was denied on the object '<em>*</em>', database 'xxx2', schema 'dbo'."</p>
  
  <p>Please help me out in sorting this problem.</p>
  
  <p>Thanks!    </p>