title: C# WinForms - SQL Server Compact Edition : keyword not supported : initial catalog
body: <p>I want to get data from a database server (SQL Server 2012) to write what I got into a local database (SQL Server Compact Edition 4.0 - WinForms app - VS 2013)</p>
  
  <ul>
  <li>Create <code>.SDF</code> database file via code -> ok.</li>
  <li>Open local connection to <code>.SDF</code> file -> ok. </li>
  <li><p>Create table via code -> ok.</p></li>
  <li><p>Open connection to database server -> NOT ok ! :(</p></li>
  </ul>
  
  <p>I got this error message : </p>
  
  <blockquote>
    <p>System.ArgumentException: Keyword not supported: 'initial catalog'</p>
  </blockquote>
  
  <p>Here is my code :</p>
  
  <pre><code>class MySqlCeEngine
  {
      private const string LOCAL_SDF_FILE = "LocalDB.sdf";
      private const string LOCAL_CONN_STRING = "Data Source='|DataDirectory|LocalDB.sdf'; LCID=1033; Password=3C670F044A; Encrypt=TRUE;";
      private const string SOURCE_CONN_STRING = "Data Source=SQL\\SERVER;Initial Catalog=myDB;Integrated Security=True;Pooling=False;
  
      public static void CreateDB()
      {
          if (File.Exists(LOCAL_SDF_FILE))
          {
              File.Delete(LOCAL_SDF_FILE);
          }
  
          SqlCeEngine engine = new SqlCeEngine(LOCAL_CONN_STRING);
          engine.CreateDatabase();
          engine.Dispose();
  
          SqlCeConnection localCnx = null;
  
          try
          {
              localCnx = new SqlCeConnection(LOCAL_CONN_STRING);
              localCnx.Open();
  
              SqlCeCommand localCmd = localCnx.CreateCommand();
  
              #region CREATE TABLE t_Address
              localCmd.CommandText = @"CREATE TABLE t_Address(
                                      Address_ID int IDENTITY(1,1) NOT NULL,
                                      Address_Main nvarchar(4000) NULL,
                                      Address_CityName nvarchar(50) NULL,
                                      Address_CityZipCode nvarchar(50) NULL,
                                      Address_CountryID int NULL,
                                      Address_CustomerID int NULL,
                                      Address_SiteID int NULL,
                                      Address_IsVisible bit NOT NULL,
                                   CONSTRAINT PK_t_AdressID PRIMARY KEY (Address_ID)
                                  )";
  
              localCmd.ExecuteNonQuery();
              #endregion
  
              using (SqlCeConnection sourceCnx = new SqlCeConnection(SOURCE_CONN_STRING))
              {
                  try
                  {
                      sourceCnx.Open();
  
                      SqlCeCommand SourceCmd = sourceCnx.CreateCommand();
                      SourceCmd.CommandText = "SELECT * FROM t_Address";
                      SqlCeDataReader reader = SourceCmd.ExecuteReader();
  
                      using (SqlBulkCopy bulkCopy = new SqlBulkCopy(LOCAL_CONN_STRING))
                      {
                          bulkCopy.DestinationTableName = "t.Address";
  
                          try
                          {
                              // Write from the source (DB server) to the destination (local wibe)
                              bulkCopy.WriteToServer(reader);
                          }
                          catch (Exception ex)
                          {
                              MessageBox.Show(ex.ToString(), "An error occurred", MessageBoxButtons.OK, MessageBoxIcon.Error);
                          }
                          finally
                          {
                              reader.Close();
                          }
                      }
                  }
                  catch (Exception ex)
                  {
                      MessageBox.Show(ex.ToString(), "An error occurred", MessageBoxButtons.OK, MessageBoxIcon.Error);
                  }
                  finally
                  {
                      sourceCnx.Close();
                  }
              }
          }
          catch(Exception ex)
          {
              MessageBox.Show(ex.ToString(), "An error occurred", MessageBoxButtons.OK, MessageBoxIcon.Error);
          }
          finally
          {
              localCnx.Close();
          }
      }
  }
  </code></pre>
  
  <p>I did some searches on the web and found that I should add "ProviderName=System.Data.SqlClient" but I still have this issue.</p>
  
  <p>I also tried with the System.Data.Entity.Database class method "OpenConnectionString" but it doesn't work (VS tells me that this class does not contain a definition for this method).</p>
  
  <p>I don't know what to do although I'm trying some things found here and there.</p>
  
  <p>Thanks,</p>
  
  <p>Hellcat</p>