【问题标题】:windows mobile 6 application database connect with server databasewindows mobile 6 应用程序数据库与服务器数据库连接
【发布时间】:2012-11-30 05:22:54
【问题描述】:

我正在开发 windows 移动应用程序。我想将我的本地数据库与服务器数据库连接。我的设备有 LAN 连接。我如何连接这两个。请给我一些链接..

【问题讨论】:

  • 嗨,我有点困惑。您有一个本地(在移动设备上)和一个服务器数据库,或者您有一个要从 Windows 移动设备访问的服务器数据库。第一个需要服务器和客户端数据库之间的数据同步。第二个只需要 SqlCEClient 和到服务器的有效 TCP/IP 连接。

标签: sql-server windows-mobile c#-3.0 sql-server-ce windows-7-x64


【解决方案1】:

首先,确保您的设备可以浏览到服务器,如下面的屏幕截图所示:

一旦您能够使用一些用户名和密码访问服务器,您就可以在 SQL 连接字符串中使用相同的用户名和密码。

这应该就是你所需要的。

【讨论】:

    【解决方案2】:

    如果要连接到 SQL Server(不是本地 SQLCE Server),首先需要导入数据和 sqlclient 命名空间(并添加对项目的引用)。

    using System.Data;
    using System.Data.SqlClient;
    

    那么你需要建立一个连接字符串:

    // Connection string
    private string strConn =
        "data source=OurServer;" +
        "initial catalog=Northwind;" +
        "user id=DeliveryDriver;" +
        "pwd=DD;" +
        "workstation id=OurDevice;" +
        "packet size=4096;" +
        "persist security info=False;";
    

    然后你可以创建一个连接:

    // A connection, a command, and a reader
    SqlConnection connDB = new SqlConnection(strConn);
    

    并使用 SQL 查询构建 SQLCommand(即“SELECT * FROM Products;”):

    SqlCommand cmndDB =new SqlCommand(sqlQueryString, connDB);
    

    然后可以使用数据读取器读取结果:

    SqlDataReader drdrDB;
    

    现在阅读结果:

    try
    {
        // Open the connection.
        connDB.Open();
        // Submit the SQL statement and receive
        // the SqlReader for the results set.
        drdrDB = cmndDB.ExecuteReader();
        // Read each row.
        while ( drdrDB.Read() )
        {
           //access fields of the result
        }
        drdrDB.Close();
    }
    ...
    //Close the connection
    connDB.Close();
    

    就是这样。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2017-09-14
      • 2023-03-30
      • 2010-10-15
      • 2018-02-01
      • 2014-03-23
      相关资源
      最近更新 更多