如何使用Sql Server Compact Edition创建可移植应用程序? [英] How Do I Create A Portable Application With Sql Server Compact Edition?

查看:67
本文介绍了如何使用Sql Server Compact Edition创建可移植应用程序?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这个工作完美吗?

但是当我在另一台电脑上打开它时会发出错误信息。



i知道数据库文件在目的地C:\\



但我无法将该数据库文件复制到项目文件夹中,我可以将其复制到我的笔中。 />


i在另一台机器上创建了一个相同的数据库文件夹?但是这也行不通?



当我在另一台电脑上打开它时会给我一个错误的说法?



您的应用程序中发生了未处理的异常。如果单击继续,应用程序将忽略此错误并尝试继续。如果单击退出,应用程序将立即关闭。



无法加载文件或程序集'System.Data.SqlServerCe,Version = 4.0.0.0,Culture = netural, PublicKey Token = 89845dcd8080cc91'或其依赖项之一。系统找不到指定的文件。



我能为此做些什么?



this one works perfectly?
but when i open this in another pc it will give an error message.

i know database file in destination C:\\

but cant i copy that database file in project folder where i can bring this any where by copying it to my pen.

i have created a same database folder in another machine? but that also won't work?

when i open this in another pc it gives me an error saying?

Unhandled exception has occured in your application. if you click continue, the application will ignore this error and attempt to continue. if you click quit, the application will close immediately.

Could not load file or assembly 'System.Data.SqlServerCe, Version=4.0.0.0, Culture=netural, PublicKey Token=89845dcd8080cc91' or one of its dependencies. The system cannot find the file specified.

What i can do for this?

string connetionString = null;

            //string sql = null;
            string name = "";
            string pass = "";

            connetionString = "Data Source=C:\\Users\\businesssupport\\Documents\\stockDb.sdf";

            using (SqlCeConnection con = new SqlCeConnection(connetionString))
            {
                //
                // Open the SqlConnection.
                //
                con.Open();
                //
                // The following code uses an SqlCommand based on the SqlConnection.
                //

                using (SqlCeCommand command = new SqlCeCommand("SELECT * FROM Login WHERE userName=@Usr", con))
                {

                    command.Parameters.AddWithValue("@Usr", uName.Text);
                    SqlCeDataReader reader = command.ExecuteReader();
                    while (reader.Read())
                    {
                        name = reader.GetString(1);  // Name string
                        pass = reader.GetString(2); // Password string
                    }

                    if (name == uName.Text && pass == uPass.Text)
                    {

                        //ClassEnq.Uname = UName.Text;
                        MessageBox.Show("Password Accepted");
                        //this.Close();
                        //setEnableToolStripMenuItem(true);
                        //setEnableToolStripMenuItem1(true);
                        //setDisableToolStripMenuItem(false);

                    }

                    else
                    {
                        MessageBox.Show("Password Incorrect, Please Re-Enter Your Password");
                        //setEnableToolStripMenuItem(false);
                        //setEnableToolStripMenuItem1(false);
                    }
                }

推荐答案

你必须安装具有相关DLL文件的SQLce:为SQL Compact创建私有安装 [ ^ ]
You have to install SQLce of have the related DLL files : Creating a Private Installation for SQL Compact[^]


这篇关于如何使用Sql Server Compact Edition创建可移植应用程序?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆