SQL Server Compact 4.0未在x86上运行 C#项目/Visual Studio 2015 构建64位PC Windows 7 Pro 客户端PC Windows 7 32位(x86) SQL Server Compact 4.0/.net Framework 4.5

SQL Server Compact 4.0未在x86上运行 C#项目/Visual Studio 2015 构建64位PC Windows 7 Pro 客户端PC Windows 7 32位(x86) SQL Server Compact 4.0/.net Framework 4.5,c#,.net,x86,sql-server-ce-4,C#,.net,X86,Sql Server Ce 4,代码: // ///连接此实例。 /// /// 公共布尔连接() { bool connected=true; 字符串cs=Properties.Settings.Default.ConnectionString; 尝试 { cnn=新的SqlCeConnection(cs); cnn.Open(); 连接=真; } catch(System.ae异常) { 连接=错误; 如果(ae.HResult==-2146233067) { MessageBox.Show(“请检查数据库位置设置”,

代码:

//
///连接此实例。
/// 
/// 
公共布尔连接()
{
bool connected=true;
字符串cs=Properties.Settings.Default.ConnectionString;
尝试
{
cnn=新的SqlCeConnection(cs);
cnn.Open();
连接=真;
}
catch(System.ae异常)
{
连接=错误;
如果(ae.HResult==-2146233067)
{
MessageBox.Show(“请检查数据库位置设置”,“Arkema数据库连接错误”,MessageBoxButton.OK,MessageBoxImage.Error);
}
回流连接;
}
catch(SqlCeException-ex)
{
连接=错误;
Show(例如ToString(),“Arkema数据库连接错误”,MessageBoxButton.OK,MessageBoxImage.Error);
回流连接;
}
回流连接;
}
数据库文件未损坏且未加密。应用程序按照构建PC上的设计工作

当应用程序尝试连接到客户端PC上的数据库时,收到以下错误:

System.Data.SqlServerCe.SqlCeException(x800004005):数据库文件可能已损坏。运行修复实用程序以检查数据库文件

我曾使用CompactView修复数据库,并收到以下消息:

System.Data.SqlServerCe.SqlCeException(x800004005):数据库加密模式无效

我将
sqlce…40.dll
文件添加到应用程序文件夹中,但这也不起作用

还尝试关闭首选32位,尝试x86而不是任何CPU


救命

时间太长,压力太大。我使用了SQLite“.db”扩展名,而不是SQLCompact扩展名“.sdf”


非常尴尬。谢谢ErikEJ询问有关连接字符串的问题

连接字符串,谢谢!使用客户端pc上的SQL Server Compact Tolbox打开文件时会发生什么情况?连接字符串通常为“Datasource=C:\SomeFolder\SomeDatabase.sdf”SQL Server Compact Toolbox是Visual Studio外接程序。这需要在客户端PC上安装Visual Studio。使用CompactView,我可以查看数据。
/// <summary>
/// Connects this instance.
/// </summary>
/// <returns></returns>
public bool Connect()
{
            bool connected = true;
            string cs =  Properties.Settings.Default.ConnectionString;

            try
            {
                cnn = new SqlCeConnection(cs);
                cnn.Open();
                connected = true;
            }
            catch(System.ArgumentException ae)
            {
                connected = false;

                if(ae.HResult == -2146233067)
                {
                    MessageBox.Show("Please check database location setting", "Arkema Database Connection Error", MessageBoxButton.OK, MessageBoxImage.Error);
                }
                return connected;
            }
            catch(SqlCeException ex)
            {
                connected = false;
                MessageBox.Show(ex.ToString(), "Arkema Database Connection Error", MessageBoxButton.OK, MessageBoxImage.Error);
                return connected;
            }

            return connected;
}