简体   繁体   English

无法访问数据库(SQL Server CE / Windows Mobile 6.5)

[英]Unable to access database (SQL Server CE / Windows Mobile 6.5)

I'm creating an application for a Windows Mobile 6.5 device, part of which is supposed to replicate a SQL database when the device plugged in, to have a local copy when unplugged (because no connection). 我正在为Windows Mobile 6.5设备创建一个应用程序,该应用程序的一部分应该在设备插入时复制SQL数据库,在拔出设备时具有本地副本(因为没有连接)。

So, to have a local database I followed the "Northwind" tutorial for SQL Server CE (with my own test database), but constantly run into the issue that the device can't connect to the database. 因此,要拥有本地数据库,我遵循了有关SQL Server CE的“罗斯文”教程 (带有我自己的测试数据库),但始终遇到设备无法连接到数据库的问题。 I can't debug (because I have to transfer the program to the device to test it every time) but I get this error message (whatever the connection string I try to use): 我无法调试(因为每次都必须将该程序传输到设备以对其进行测试),但是我收到此错误消息(无论我尝试使用的连接字符串如何):

SQL database error: Unspecified error [.\\userdb.sdf] SQL数据库错误:未指定的错误[。\\ userdb.sdf]

I tried multiple connection strings, and I can see the database can be accessed if I bind the data sources to the forms using the designer. 我尝试了多个连接字符串,如果使用设计器将数据源绑定到表单,我可以看到可以访问数据库。 But I need to manually set up some query as they will be a lot more complicated than just filling forms. 但是我需要手动设置一些查询,因为它们比仅填写表单要复杂得多。

Here's my code, it's just supposed to fill a form but the next step would be a login/password check: 这是我的代码,只应该填写一个表格,但是下一步将是登录/密码检查:

public partial class UserLogin : Form
{
    private SqlCeConnection _conn;

    public UserLogin()
    {
        InitializeComponent();

        _conn = new SqlCeConnection(@"Data Source=.\userdb.sdf;Password=PASSWORD;Persist Security Info=True");  
    }

    private void buttonCancel1_Click(object sender, EventArgs e)
    {
        this.Close();
    }

    private void buttonLoad1_Click(object sender, EventArgs e)
    {
        try
        {
            SqlCeCommand cmd = new SqlCeCommand();
            cmd.Connection = _conn;
            cmd.CommandText = "SELECT userid, username, password FROM Users";

            _conn.Open();
            SqlCeResultSet resultSet = cmd.ExecuteResultSet(ResultSetOptions.Scrollable | ResultSetOptions.Updatable);
            this.bindingSource1.DataSource = resultSet;

        }
        catch (SqlCeException sql_ex)
        {
            MessageBox.Show("SQL database error: " + sql_ex.Message);
        }
    }

Also something different I tried, where the forms are filled with a DataSet from designer but I still can't manually access the database: https://pastebin.com/10P3wGeP 我也尝试了一些不同的方法,其中表单中填充了设计师的数据集,但仍然无法手动访问数据库: https : //pastebin.com/10P3wGeP

Windows Mobile neither knows about drive letters nor a 'current' directory. Windows Mobile既不知道驱动器号也不知道“当前”目录。 That is why "Data Source=.\\userdb.sdf" will always fail. 这就是为什么“数据源=。\\ userdb.sdf”将始终失败的原因。

On windows mobile you always have to use a full qualified path name to access a file. 在Windows Mobile上,您始终必须使用完整的限定路径名来访问文件。

You may use 您可以使用

 string path = System.IO.Path.GetDirectoryName( 
  System.Reflection.Assembly.GetExecutingAssembly().GetName().CodeBase );

to get the path to the directory of where the executable is started. 获取可执行文件启动目录的路径。

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

相关问题 损坏的数据库Sql Server CE(Windows Mobile CE 5.0) - Corrupted Database Sql Server CE (Windows Mobile CE 5.0) 在Windows CE mobile(OS Windows CE)中访问SQLCE(Microsoft Sql Compact Edition)数据库的最快方法是什么? - Which is Fastest way to access SQLCE(Microsoft Sql Compact Edition) Database in Windows CE mobile(OS Windows CE))? 在具有Windows CE 5的设备上使用SQL Server CE数据库进行CRUD操作 - CRUD Opertaions with SQL Server CE database on device with Windows CE 5 插入,更新,删除不适用于Windows Mobile的SQL Server CE数据库文件 - Insert, Update, Delete are not applied on SQL Server CE database file for Windows Mobile 在单独的文件夹中安装SQL Server CE数据库[Windows Mobile 6 Smart device ap] - Install SQL Server CE database in separate folder [Windows Mobile 6 Smart device ap] 在Windows Mobile 5上将数据加载到Sql CE数据库的最快方法 - Fastest way to load data into Sql CE database on windows mobile 5 从Windows Mobile 6.5访问网络共享 - access network share from windows mobile 6.5 从移动设备(Windows Mobile 6.5)到sql Server 2008的连接问题 - connection issues to sql server 2008 from mobile device (Windows mobile 6.5) 使用Windows CE 6.0连接到SQL Server或MySQL数据库 - Connecting to a SQL Server or MySQL database with Windows CE 6.0 SQL Server CE与远程访问数据库的两种同步方式 - SQL Server CE two way sync with remote Access database
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM