title: Connection string for SQL Server Compact - windows home server
body: <p>I'm using SQL Server Compact 4.0 and hosting the site on Windows Home Server 2011, program is written in C#  - Visual Web Developer. </p>
  
  <p>I've tried every possible connection string variation that I can think of but I keep getting this error:</p>
  
  <blockquote>
    <p>Format of the initialization string does not conform to specification starting at index 0.</p>
  </blockquote>
  
  <p>This is the string I have currently</p>
  
  <pre><code>&lt;add name="Inventory" 
       connectionString="Data Source=C:\Program Files\Windows Server\Bin\WebApps\Site\App_Data\PHSInventory.sdf;"  /  &gt;
  </code></pre>
  
  <p>I've also tried to point to it with <code>|data directory|</code>. I've run out of blue links on Google to click on. </p>
  
  <blockquote>
    <p>STACK TRACE</p>
    
    <p>[ArgumentException: Format of the initialization string does not conform to specification starting at index 0.]
       System.Data.SqlServerCe.ConStringUtil.GetKeyValuePair(Char[] connectionString, Int32 currentPosition, String&amp; key, Char[] valuebuf, Int32&amp; vallength, Boolean&amp; isempty) +1182
       System.Data.SqlServerCe.ConStringUtil.ParseStringIntoHashtable(String conString, Hashtable values) +188
       System.Data.SqlServerCe.ConStringUtil.ParseConnectionString(String&amp; connectionString) +128
       System.Data.SqlServerCe.SqlCeConnection.set_ConnectionString(String value) +679
       System.Data.SqlServerCe.SqlCeConnection..ctor(String connectionString) +46
       System.Data.SqlServerCe.SqlCeDataAdapter..ctor(String selectCommandText, String selectConnectionString) +73
       DataAccess.FillDataTable(String SQL) +149
       Default.Page_Load(Object sender, EventArgs e) +378
       System.Web.Util.CalliEventHandlerDelegateProxy.Callback(Object sender, EventArgs e) +51
       System.Web.UI.Control.OnLoad(EventArgs e) +92
       System.Web.UI.Control.LoadRecursive() +54
       System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +772</p>
  </blockquote>
  
  <p>DATA ACCESS</p>
  
  <pre><code>using System;
  
  using System.Data;
  
  using System.Data.SqlClient;
  
  using System.Web.Configuration;
  
  using System.Data.SqlServerCe;
  
  public class DataAccess
  {
  
      private int count = -1;
  
      public int Count
      { get { return count; } }
  
      private string connectionString;
      public string ConnectionName
      {
          set
          {
              if (WebConfigurationManager.ConnectionStrings[value] == null)
              {
                  throw new Exception("Cannot find connection string named '" +
                     value + "' in web.config");
              }
              //Retrieve connection string from web.config.
              connectionString =
                 WebConfigurationManager.ConnectionStrings[value].ConnectionString;
          }
      }
  
      public DataAccess(string connectionName)
      {
          ConnectionName = connectionName;
      }
  
      public DataTable FillDataTable(string SQL)
      {
          // Fill dataTable.
           WriteToTraceLogForDebugging(SQL);
          SqlCeConnection sqlConn = new SqlCeConnection("Data Source=D:\\InventoryData\\PHSInventory.sdf;");
          SqlCeDataAdapter objAdapter = new SqlCeDataAdapter(SQL, sqlConn);
          DataTable dt = new DataTable();
          objAdapter.Fill(dt);
          count = dt.Rows.Count;  
          return dt;
      }
      public int ExecuteNonQuery(string SQL)
      {
          WriteToTraceLogForDebugging(SQL);
          SqlCeConnection sqlConn = new SqlCeConnection(connectionString);
          sqlConn.Open();
          SqlCeCommand objCmd = new SqlCeCommand(SQL, sqlConn);
          count = objCmd.ExecuteNonQuery();
          return count;
      }
  
      public object ExecuteScalar(String SQL)
      {
          WriteToTraceLogForDebugging(SQL);
          SqlCeConnection sqlConn = new SqlCeConnection(connectionString);
          sqlConn.Open();
          SqlCeCommand objCmd = new SqlCeCommand(SQL, sqlConn);
          //calling code needs to cast data (to integer, string, double, etc.) upon receipt. 
          return objCmd.ExecuteScalar();
      }
  
      private void WriteToTraceLogForDebugging(string sql)
      {
          System.Web.HttpContext.Current.Trace.Write("sql****", sql);
          System.Web.HttpContext.Current.Trace.Write("CONNECTION*****", connectionString);
      }
  
  }
  </code></pre>