在wincd5.0和mobile6的设备上,运行用vs2005编写的sqlserverce的程序,都出现“无法加载 DLL“sqlceme30.dll”: 找不到指定的模块”的错误,原因是dll的版本太低。到微软的网站下载3.5版本的Microsoft SQL Server Compact ,更新到移动设备上,程序就可以正常运行。

下载地址  

http://download.microsoft.com/download/5/f/7/5f7010a7-80f0-4413-aac1-ef8f54d5e063/SSCEDeviceRuntime-CHS.msi

安装完3.5版本的程序后, C:""Program Files""Microsoft SQL Server Compact Edition""v3.5""Devices""wce500""armv4i""sqlce.wce5.armv4i.CAB拷贝到设备的sd卡上,

安装完成就可以了。

如果之前已经安装的低版本的sqlserverce,则应该先卸载。

附一段例子程序,测试没有问题

using   System;  
using   System.IO;  
using   System.Text;  
using   System.Data;  
using   System.Data.SqlServerCe;  
using   System.Collections;  
using   System.Windows.Forms;  
using   System.Data.Common;

namespace DeviceApplication2
{
    public partial class Form1 : Form
    {

        public Form1()
        {
            InitializeComponent();
        }
        private void button1_Click(object sender, EventArgs e)
        {
            SqlCeConnection conn = null;

            try
            {
                if (File.Exists("Test.sdf"))
                    File.Delete("Test.sdf");

                SqlCeEngine engine = new SqlCeEngine("Data Source = Test.sdf");
                engine.CreateDatabase();

                conn = new SqlCeConnection("Data Source = Test.sdf");
                conn.Open();

                SqlCeCommand cmd = conn.CreateCommand();

                cmd.CommandText =
                        "CREATE   TABLE   TestTbl   (col1   INT   PRIMARY   KEY,   col2   NTEXT,   col3   MONEY)";

                cmd.ExecuteNonQuery();

                cmd.CommandText =
                        "INSERT   INTO   TestTbl   (col1,   col2,   col3)   VALUES   (0,   'abc',   15.66)";

                cmd.ExecuteNonQuery();

                cmd.CommandText = "INSERT   INTO   TestTbl   (col1,   col2,   col3)   VALUES   (?,   ?,   ?)";

                cmd.Parameters.Add(new SqlCeParameter("p1", SqlDbType.Int));
                cmd.Parameters.Add(new SqlCeParameter("p2", SqlDbType.NText));
                cmd.Parameters.Add(new SqlCeParameter("p3", SqlDbType.Money));

                cmd.Parameters["p2"].Size = 50;

                cmd.Prepare();

                cmd.Parameters["p1"].Value = 1;
                cmd.Parameters["p2"].Value = "abc";
                cmd.Parameters["p3"].Value = 15.66;
                cmd.ExecuteNonQuery();

                cmd.Parameters.Clear();

                cmd.CommandText = "SELECT   *   FROM   TestTbl";

                SqlCeDataReader rdr = cmd.ExecuteReader();

                while (rdr.Read())
                {
                    MessageBox.Show("   col1   =   " + rdr.GetInt32(0) +
                            "   col2   =   " + rdr.GetString(1) +
                            "   col3   =   " + rdr.GetSqlMoney(2));
                }

                cmd.CommandText = "UPDATE   TestTbl   set   col2='some   new   value'   WHERE   col1=0";
                cmd.ExecuteNonQuery();

                cmd.CommandText = "SELECT   *   FROM   TestTbl";

                rdr = cmd.ExecuteReader();

                while (rdr.Read())
                {
                    MessageBox.Show("   col1   =   " + rdr.GetInt32(0) +
                            "   col2   =   " + rdr.GetString(1) +
                            "   col3   =   " + rdr.GetSqlMoney(2));
                }

            }
            catch (SqlCeException ex)
            {
                ShowErrors(ex);
            }
            finally
            {
                if (conn.State == ConnectionState.Open)
                    conn.Close();
            }
        }

        public static void ShowErrors(SqlCeException e)
        {
            SqlCeErrorCollection errorCollection = e.Errors;

            StringBuilder bld = new StringBuilder();
            Exception inner = e.InnerException;

            foreach (SqlCeError err in errorCollection)
            {
                bld.Append(""n   Error   Code:   " + err.HResult.ToString("X"));
                bld.Append(""n   Message       :   " + err.Message);
                bld.Append(""n   Minor   Err.:   " + err.NativeError);
                bld.Append(""n   Source         :   " + err.Source);

                foreach (int numPar in err.NumericErrorParameters)
                {
                    if (0 != numPar) bld.Append(""n   Num.   Par.   :   " + numPar);
                }

                foreach (string errPar in err.ErrorParameters)
                {
                    if (String.Empty != errPar) bld.Append(""n   Err.   Par.   :   " + errPar);
                }

                MessageBox.Show(bld.ToString());
                bld.Remove(0, bld.Length);
            }
        }
    }

}

 

问题。vs2005编译程序时用的还是3.0.的库文件System.Data.SqlServerCe.dll,在仿真机上运行没有问题,

到了真实的设备上确不行。

参考:http://forums.microsoft.com/MSDN-CHT/ShowPost.aspx?PostID=2926161&SiteID=14

 

posted on 2008-12-10 23:34  白沙河  阅读(6633)  评论(2编辑  收藏  举报