1

I'm trying to find out how to run a script in C# to create tables and data for a SQL Server CE database. I'm getting the following error when ExecutingNonQuery off of command:

There was an error parsing the query. [ Token line number = 1,Token line offset = 1,Token in error = USE ]

Code:

public static void CreateDatabase()
{
    string connStr = "Data Source='C:\\DataBases/MyDatabase.sdf'; LCID=1033; Case Sensitive = TRUE";

    if (File.Exists(@"C:\\DataBases\MyDatabase.sdf"))
        File.Delete(@"C:\\Databases\MyDatabase.sdf");

    SqlCeEngine engine = new SqlCeEngine(connStr);
    engine.CreateDatabase();

    string originalDatabaseScriptFile = Helpers.Instance.GetAppPath() + "ApplicationHelpers\\MyDatabase.sql";

    //run script
    FileInfo file = new FileInfo(originalDatabaseScriptFile);
    string script = file.OpenText().ReadToEnd();

    SqlCeConnection sqlCeConnection = new SqlCeConnection(connStr);
    sqlCeConnection.Open();

    SqlCeCommand ceCommand = new SqlCeCommand(script, sqlCeConnection);
    ceCommand.ExecuteNonQuery(); //Get error here

    engine.Dispose();
}

The script I use works for SQL Server Express (.mdf) but I want to use for SQL Server CE (.sdf)

Any advice on what could be going wrong? Thanks for any advice.

marc_s
  • 732,580
  • 175
  • 1,330
  • 1,459
TMan
  • 4,044
  • 18
  • 63
  • 117
  • **SHOW US** the script! SQL Server CE is limited is several ways: it has only a small subset of datatypes, and it's T-SQL implementation is limited, too (e.g. you cannot execute more than 1 statement in a single script) – marc_s Apr 16 '14 at 05:01
  • My SQL Script is too big to break down into separate statements. I changed back to using .\SQLExpress – TMan Apr 18 '14 at 14:41

0 Answers0