title: How to connect multi server and database in C#
body: <pre><code>public class MyDatabaseConnection
  {
      string connectionString = "Data Source= my DS3;Initial Catalog = MyCATA;Persist Security Info=True;User ID=sa;Password=mypsw*";
  
      public MyDatabaseConnection(string connectionString)
      {
          this.connectionString = connectionString;
          // create a database connection perhaps
      }
  
      // some methods for querying a database
      public void execute(string query) { }
  }
  </code></pre>
  
  <p>and this is my code</p>
  
  <pre><code>public partial class Form1 : Form
  {
      public Form1()
      {
          InitializeComponent();
      }
  
      string connectionString ;
  
      public void searchOnAllDatabases(string query)
      {
  
          MyDatabaseConnection con1 = new MyDatabaseConnection("Data Source= 10.232.1.15\\SERVER1;Initial Catalog = My Catalog;Persist Security Info=True;User ID=sa;Password=myPSW");  //----1st search here 
          MyDatabaseConnection con2 = new MyDatabaseConnection("Data Source= 10.232.1.15\\SERVER2;Initial Catalog = My Catalog;Persist Security Info=True;User ID=sa;Password=myPSW");  //---- 2nd search here 
          MyDatabaseConnection con3 = new MyDatabaseConnection("Data Source= 10.232.1.15\\SERVER3;Initial Catalog = My Catalog;Persist Security Info=True;User ID=sa;Password=myPSW");  //---- 3rd search here 
  
          MyDatabaseConnection[] cons = new MyDatabaseConnection[] { con1, con2, con3 };
  
          foreach (MyDatabaseConnection con in cons)
          {
  
  
              MessageBox.Show(Convert.ToString(cons)); //--to see the result only
          }
  
      }
  </code></pre>
  
  <p>My objective is when I search this filename it will search entire database from different server. example it will search on server 1 database if not found it will proceed to next server 2 databases to server 3 database if found it will give me the result in datagridview</p>