title: C# - Public Global connection to SQL Server 2005
body: <p>I am new to C# and I started studying just yesterday.</p>
  
  <p>I have created class to connect to SQL Server:</p>
  
  <pre><code>namespace Exchange_Ofiice.Classes
  {
      public class sqlConn
      {
          public void connectionMethod()
          {
              SqlConnection myConnection = new SqlConnection("user id=ID;password=PASS;server=SERVER;database=DB;");
              try
              {
                  myConnection.Open();
              }
              catch
              {
                  MessageBox.Show("Невозможно подключиться к Базе данных. Пожалуйста обратитесь к программистам!", "Ошибка подключения к Базе данных", MessageBoxButtons.OK, MessageBoxIcon.Error);
              }
              finally
              {
                  myConnection.Close();
              }        
          }
      }
  }
  </code></pre>
  
  <p>and another class for user authentification:</p>
  
  <pre><code>namespace Exchange_Ofiice.Classes
  {
      public class auth:sqlConn
      {
  
          public void authMethod() 
          {
              SqlCommand myCommand = new SqlCommand("Command String", myConnection);                          
          }
  
      }
  }
  </code></pre>
  
  <p>How to get (use) SQL connection result (<code>myConnection</code>) in second class?</p>
  
  <p>P.S. line <code>SqlCommand myCommand = new SqlCommand("Command String", myConnection);</code> does not work.</p>
  
  <p>P.S.S. Sorry, if I have mistake, my english is not perfect.</p>