title: C# database wrapper design
body: <p>I am designing a database wrapper for C#. 
  Below are the two options I have:</p>
  
  <p>Option A:</p>
  
  <pre><code>class DBWrapper:IDisposable
  {
       private SqlConnection sqlConn;
  
       public DBWrapper()
       {
              sqlConn = new SqlConnection("my connection string");
              sqlConn.Open();
       }
  
       public DataTable RunQuery(string Sql)
       {
                implementation......
       }
  
       public Dispose()
       {
              if(sqlConn != null)
                     sqlConn.Close();
       }
  }
  </code></pre>
  
  <p>Option B:</p>
  
  <pre><code>class DBWrapper
  {
       public DBWrapper()
       {            
       }
  
       public DataTable RunQuery(string Sql)
       {
               SqlConnection sqlConn = new SqlConnection("my connection string");
               .....implementation......
               sqlConn.Close();               
       }   
  }
  </code></pre>
  
  <p>For option A connection is opened when class is instantiated. So no matter how many times the caller calls RunQuery the connection is always ready. But If the application instantiates DBWrapper early in the application, the connection will be just opened and doing nothing until the application is finished. Also, it could have many DBWrapper instantiated during the execution. So, it's kinda wasting resources.</p>
  
  <p>For option B it doesn't have the problem option A has, but the a new connection has to be opened and closed everytime the caller calls RunQuery. I am not sure how much it will hurt the performance.</p>
  
  <p>Please share your expertise. Thank you for reading.</p>