简体   繁体   中英

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

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.

确保您(1)知道数据库是哪个版本的SQL Server CE,以及​​(2)从与该SQL CE版本匹配的项目中引用了相应的System.Data.SqlServerCe.DLL

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM