SQL Server CE error Cannot open '|DataDirectory|\Test.sdf'. Provider 'System.Data.SqlServerCe.3.5' not installed.

Answered SQL Server CE error Cannot open '|DataDirectory|\Test.sdf'. Provider 'System.Data.SqlServerCe.3.5' not installed.

  • Friday, February 08, 2013 2:13 PM
     
      Has Code

    I am trying to use SQL Server CE in my MVC 4 web app. I have a class library and I have added the reference to System.Data.SqlServerCe.dll (V4)

    The code to create the SDF is:

    String connString = "Data Source=|DataDirectory|\HomeController.sdf";
    SqlCeEngine engine = new SqlCeEngine(connString);
    engine.CreateDatabase();

    Which create a SDF with no problems

    Next I try to work with the SDF like this:

    XmlDocument xmlDoc = new XmlDocument();
    XmlTextReader xmlReader = new XmlTextReader(ConfigurationManager.AppSettings["ApplicationSettingsPath"] + @"\CreateHomeControllerDatabase.xml");
    try
    {
        xmlReader.Read();
        xmlDoc.Load(xmlReader);
    
        foreach (XmlNode jobNode in xmlDoc.SelectSingleNode("Jobs"))
        {
            //TODO look at the old version on my old machine and debug this to see what the issue is
            DataContext db = new DataContext(DATABASE);
            db.ExecuteCommand(jobNode.InnerXml.Replace("<![CDATA[", String.Empty).Replace("]]>", String.Empty).Trim());
        }
    }
    catch (Exception ex)
    {
        //ErrorHandler.ErrorDelegate.LogError(ex); TODO
    }

    As soon as it it hits DataContext db = new DataContext(DATABASE); I get the exception Cannot open '|DataDirectory|\Test.sdf'. Provider 'System.Data.SqlServerCe.3.5' not installed.

    First things that looks strange is why is it asking for 3.5 when I added the 4.0 instance of the dll? I have not installed the SQL CE 4.0 on my machine as the intention of using CE was to easily install this on a client by just adding the dlls. I have added the other dlls in that folder where possible but it just errors.

    Any ideas please?


    • Edited by Davearia Friday, February 08, 2013 3:20 PM
    •  

All Replies