title: C# Sql Connection String
body: <p>I'm a 17 year old software engineering student and am having trouble with linking my sql database to my C# Win App. I was able to accomplish this task using a access database but the database needs to be in SQL. Any Help would be greatly appreciated! 
  The code i have so far is :</p>
  
  <pre><code>Form1.cs
  using System;
  using System.Collections.Generic;
  using System.ComponentModel;
  using System.Data;
  using System.Drawing;
  using System.Linq;
  using System.Text;
  using System.Threading.Tasks;
  using System.Windows.Forms;
  
  using System.Data.OleDb; // all Non-SqlServer Databases ie oracle, access, sqlLite
  using System.Configuration;
  
  namespace SqlWinApp
  {
      public partial class Form1 : Form
      {
          // Declare and init data objects
          // Connect to an external data source
          //OleDbConnection cnDataCon =
          //    new OleDbConnection("Provider=Microsoft.ACE.OLEDB.12.0; Data Source=H:/SEWD/ASP/dataTestJr/App_Data/dbWaxStax.accdb");
          SqlConnection cnDataCon =
             new SqlConnection(ConfigurationManager.ConnectionStrings["cnExternalData"].ConnectionString);
          // dataset: Container object for data tables  
          DataSet dsData = new DataSet();
  
          public Form1()
          {
              InitializeComponent();
          }
  
          private void Form1_Load(object sender, EventArgs e)
          {
              try
              {
                  cnDataCon.Open();
                  {
                      loadDdlTitles();
                  }
              }
              catch (Exception errDesc)
              {
                  string strMsgError = "Error encountered on open: " + errDesc.Message.ToString().Replace('\'', ' ');
                  MessageBox.Show(@"&lt;script language='javascript'&gt;alert('" + strMsgError + "')&lt;/script&gt;");
                  MessageBox.Show(@"&lt;script language='javascript'&gt;alert('Application will terminate')&lt;/script&gt;");
                  return;
              }
          }
          private void loadDdlTitles()
          {
              //Response.Write(@"&lt;script language='javascript'&gt;alert('loadDDlTitles')&lt;/script&gt;");
              // store sql into a string in order to be utilized at a later time.
              string strSqlTitles = "SELECT * FROM tblTitles ORDER BY title";
              // data adapters act as data filters
              OleDbDataAdapter daTitles = new OleDbDataAdapter();
              // command syncs the data source with the filter (data sdapter) and readies it for instantiation
              OleDbCommand cmNameTitles = new OleDbCommand(strSqlTitles, cnDataCon);
              // select command syncs the filter with the data 
              daTitles.SelectCommand = cmNameTitles;
              try
              {
                  daTitles.Fill(dsData, "tblTitlesInternal"); // blow pt.
              }
              catch (Exception errDesc)
              {
                  string strMsgError = "Error encountered in data adapter object: " + errDesc.Message.ToString().Replace('\'', ' ');
                  MessageBox.Show(@"&lt;script language='javascript'&gt;alert('" + strMsgError + "')&lt;/script&gt;");
                  MessageBox.Show(@"&lt;script language='javascript'&gt;alert('Application will terminate')&lt;/script&gt;");
              }
              // Connect control obj to datasource and populate 
              ddlTitle.DataSource = dsData.Tables["tblTitlesInternal"];
              ddlTitle.DisplayMember = "nameTitle";
              ddlTitle.ValueMember = "nameTitlesID";
          }
  
      } 
  
  }
  </code></pre>
  
  <p>In my App.config i have:</p>
  
  <pre><code>&lt;?xml version="1.0" encoding="utf-8" ?&gt;
  &lt;configuration&gt;
    &lt;configSections&gt;
    &lt;/configSections&gt;
    &lt;connectionStrings&gt;
      &lt;add name="cnExternalData" connectionString="Data Source=|DataDirectory|215-6576.All-Purpose Handyman.dbo; Provider=Microsoft.ACE.OLEDB.12.0" /&gt;
      &lt;add name="SqlWinApp.Properties.Settings.ConnectionString" connectionString="Data Source=215-6576;User ID=sa"
        providerName="System.Data.SqlClient" /&gt;
    &lt;/connectionStrings&gt;
      &lt;startup&gt; 
          &lt;supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.5" /&gt;
      &lt;/startup&gt;
  &lt;/configuration&gt;
  </code></pre>
  
  <p>Finally, My database is named 215-6576.All-PurposeHandyman.dbo and the table i am using is named tblTitles. Any help again would be greatly appreciated! Thank you!</p>