none
SQL Server Compact: Incompatible Database Version

    Question

  • I just upgraded my project from Visual Studio 2008 to Visual Studio 2012 and upgraded my SQL Serevr Compact Database to a 4.0 version and I get the following error when I try and write to the database:

          string conStr = Properties.Settings.Default.alertsConnectionString;
          AlertsDataContext db = new AlertsDataContext(conStr);

          ActivityLog param = new ActivityLog();
          param.date = DateTime.Now;
          param.type = type;
          param.message = message;

          db.ActivityLog.InsertOnSubmit(param);
          // Submit the change to the database.
          try
          {
            db.SubmitChanges();
          }
          catch (Exception ex)
          {
            Console.WriteLine(ex);
            db.SubmitChanges();
          }

    I get the following error on db.SubmitChanges()

    Incompatible Database Version. If this was a compatible file, run repair. For other cases refer to documentation. [ Db version = 4000000,Requested version = 3505053

    I am referencing:

    C:\Program Files (x86)\Microsoft SQL Server Compact Edition\v4.0\Desktop\System.Data.SqlServerCe.dll

    • Edited by roboyak Wednesday, July 10, 2013 5:24 PM
    Wednesday, July 10, 2013 4:37 PM

Answers

All replies

  • You must initialize the DataContext with a SqlCeConnection object, not a connect string fir Linq To SQL to Work with 4,0. See my blog post here: http://erikej.blogspot.dk/2012/04/using-linq-to-sql-with-sql-server.html


    Please mark as answer, if this was it. Visit my SQL Server Compact blog Windows 8 Apps Showcase

    • Marked as answer by roboyak Wednesday, July 10, 2013 8:45 PM
    Wednesday, July 10, 2013 7:35 PM
  • aha.. ok let me give that a try!
    Wednesday, July 10, 2013 7:40 PM
  • you are a rockstar.. that worked like a charm.. thank you!
    Wednesday, July 10, 2013 8:45 PM
  • final code looks like this:

          using (SqlCeConnection conn = new SqlCeConnection(conStr))
          {
              using (AlertsDataContext db = new AlertsDataContext(conn))
              {
                  ActivityLog param = new ActivityLog();
                  param.date = DateTime.Now;
                  param.type = type;
                  param.message = message;

                  db.ActivityLog.InsertOnSubmit(param);
                  try
                  {
                      db.SubmitChanges();
                  }
                  catch (Exception ex)
                  {
                      Console.WriteLine(ex);
                  }
              }
          }

    Wednesday, July 10, 2013 8:48 PM
  • wow from last 2 days i was searching for it... you are great man... but what is problem in 3.5 Sql Compact version i was giving connection string to datacontext and in 4.0 why connection object? again thanks a lot 

    Thursday, July 18, 2013 9:16 AM
  • Tapan: Thanks. The problem is the Linq to SQL code (System.Data.Linq.dll) - if you specify a connection string, it is hardcoded to use version 3.5 to create a DbConnection. If you provide a SqlCeConnection object, it will use that to create the DbConnection object.

    Please mark as answer, if this was it. Visit my SQL Server Compact blog Windows 8 Apps Showcase

    Thursday, July 18, 2013 9:36 AM