title: Create DLL to access database c#
body: <p>Would it be wise to Use a Dll to access a database When a application starts.</p>
  
  <p>This is the code i have to call in every page in my app</p>
  
  <pre><code>  SqlConnection myConnection = new SqlConnection();
      myConnection.ConnectionString = "Data Source=CRYSTAL5\\INSTANCE1;Initial Catalog=Pharmacy;Integrated Security=True";
      myConnection.Open(); 
  </code></pre>
  
  <p>and the dll code i wrote</p>
  
  <pre><code>public  class DBConnect
      {
          public DBConnect()
          {
              Initialize();
          }
          private SqlConnection connection;
          //Constructor
  
  
      //Initialize values
      private void Initialize()
      {
          string connectionString;
          connectionString = "Data Source=CRYSTAL5\\INSTANCE1;Initial Catalog=Pharmacy;Integrated Security=True";
  
          connection = new SqlConnection(connectionString);
      }
  </code></pre>
  
  <p>i then added <code>using DBCon;</code> in my app and tried to run this code</p>
  
  <pre><code>DBConnect myConnection = new DBConnect();
          SqlCommand myCommand = new SqlCommand("select doc_fname,doc_lname,gender,department,education ,NMC_no  from ph.doctor_info where unit_id =0", myConnection);
  </code></pre>
  
  <p>it won't work.</p>
  
  <p>sorry for the crappy description</p>
  
  <p>The best overloaded method match for 'System.Data.SqlClient.SqlCommand.SqlCommand(string, System.Data.SqlClient.SqlConnection)' has some invalid arguments<br>
      is the error i get</p>
  
  <p>What would i do without stack overflow.</p>