You are trying to access an older version of a SQL Server Compact Edition database

4.1k views Asked by At

I am getting error when I am trying to open connection. My DB.sdf file is in my application folder

here i stored db.sdf

{

string ConnectionString=  new System.IO.FileInfo(System.Reflection.Assembly.GetExecutingAssembly().Location).DirectoryName + @"\APP_DATA\DB.sdf";


public int ExecuteNonQuery(string query){

        int res = -1;
        try
        {                
            using (SqlCeConnection conn = new SqlCeConnection(ConnectionString))
            {
                SqlCeCommand command = new SqlCeCommand(query, conn);
                command.CommandType = CommandType.Text;
                conn.Open();
                res = command.ExecuteNonQuery();
            }
        }
        catch (Exception e)
        {
            new Logs().TraceProcessError(e.Message);
        }
        return res;
    }

}

Error:

You are trying to access an older version of a SQL Server Compact Edition database. If this is a SQL Server CE 1.0 or 2.0 database, run upgrade.exe. If this is a SQL Server Compact Edition 3.0 or later database, run Compact / Repair. [ Db version = 3505053,Requested version = 3004180,File name = D:\DB.sdf ]"

and I am using SQL Server Compact 3.5., VS2010, SQLServer 2008R2.

please help. thanks.

3

There are 3 answers

1
Daan On

Make sure that you (1) know which version of SQL Server CE you database is, and (2) that you reference the appropriate System.Data.SqlServerCe.DLL from you project that matches that version of SQL CE.

0
Amarnath Balasubramanian On
0
Keith Loughnane On

Download SQL Server compact toolbox from here

https://sqlcetoolbox.codeplex.com/

Run it against your data base file and note down the version number (eg. 3.5)

Go into visual studio click on System.Data.SqlServerCe under resources and then click under the properties. In properties note down the version number (eg. 3.0)

If the the library version number is older. Download the SQL Server Compact installer and run. http://www.microsoft.com/en-IE/download/details.aspx?id=12264

Once installed. Delete the references to System.Data.SqlServerCe and System.Data.SqlClient from your project and add their equivalent 3.5 versions. Found on my system at.

C:\Program Files (x86)\Microsoft SQL Server Compact Edition\v3.5\Devices\System.Data.SqlServerCe.dll

and

C:\Program Files (x86)\Microsoft SQL Server Compact Edition\v3.5\Devices\Client\System.Data.SqlClient.dll

Clean and then rebuild. Like I mentioned in the comment, this undid itself at some point on VS 2008 so if you get the error again double check the path is going to the above.