title: How should I structure an application that uses inline SQL to generate data from a database?
body: <p>I currently have a Data Access Layer that is also exposing some API using a web service.</p>
  <h3>API Call</h3>
  <pre><code>[WebMethod]
  public List&lt;GlobalStat&gt; GetStats()
  {
      List&lt;GlobalStat&gt; Stats = new List&lt;GlobalStat&gt;();
  
      string sql = @&quot;
         A huge multi-line SQL query
      &quot;;
  
      try
      {
          string ConString = Constants.connString;
          con = new SqlConnection(ConString);
  
          cmd = new SqlCommand(sql, con);
          con.Open();
          dr = cmd.ExecuteReader();
  
          while (dr.Read())
          {
              GlobalStat stat = new GlobalStat();
              stat.Key = dr[0].ToString();
              stat.Value = int.Parse(dr[1].ToString());
  
              Stats.Add(stat);
          }
  
      }
      catch (Exception x)
      {
  
          Response.Write(x);
      }
  
      return Stats;
  }
  </code></pre>
  <p>I am a bit worried about the how the SQL is written.</p>
  <p>There are so many things hard-coded into this: Database name, Table names etc.</p>
  <p>To solve this problem, do I just create a separate global file with all SQL commands at one place or is there a better paradigm? I am not creating the SQL tables inside the application but these tables reside on a different pre-built database.</p>
  <p>How should I structure an application that uses inline SQL to generate data from a database?</p>