简体   繁体   English

您正在尝试访问SQL Server Compact Edition数据库的旧版本

[英]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 我的DB.sdf文件在我的应用程序文件夹中

here i stored db.sdf 我在这里存储了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. 您正在尝试访问SQL Server Compact Edition数据库的旧版本。 If this is a SQL Server CE 1.0 or 2.0 database, run upgrade.exe. 如果这是SQL Server CE 1.0或2.0数据库,请运行upgrade.exe。 If this is a SQL Server Compact Edition 3.0 or later database, run Compact / Repair. 如果这是SQL Server Compact Edition 3.0或更高版本的数据库,请运行“压缩/修复”。 [ Db version = 3505053,Requested version = 3004180,File name = D:\\DB.sdf ]" [Db版本= 3505053,请求的版本= 3004180,文件名= D:\\ DB.sdf]“

and I am using SQL Server Compact 3.5., VS2010, SQLServer 2008R2. 我正在使用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 从此处下载SQL Server紧凑型工具箱

https://sqlcetoolbox.codeplex.com/ https://sqlcetoolbox.codeplex.com/

Run it against your data base file and note down the version number (eg. 3.5) 针对您的数据库文件运行它,并记下版本号(例如3.5)

Go into visual studio click on System.Data.SqlServerCe under resources and then click under the properties. 进入Visual Studio,在资源下单击System.Data.SqlServerCe,然后在属性下单击。 In properties note down the version number (eg. 3.0) 在属性中记下版本号(例如3.0)

If the the library version number is older. 库版本号是否较旧。 Download the SQL Server Compact installer and run. 下载SQL Server Compact安装程序并运行。 http://www.microsoft.com/en-IE/download/details.aspx?id=12264 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. 从您的项目中删除对System.Data.SqlServerCe和System.Data.SqlClient的引用,并添加它们等效的3.5版本。 Found on my system at. 在我的系统上找到。

C:\\Program Files (x86)\\Microsoft SQL Server Compact Edition\\v3.5\\Devices\\System.Data.SqlServerCe.dll 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 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. 就像我在评论中提到的那样,它在VS 2008上的某个时候本身就很不安全,因此如果再次遇到错误,请再次检查路径是否指向上面。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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