您的位置:首页 > 数据库

简述如何创建一个SQL SERVER 2005 MOBILE数据库(我的个人成功案例 )

2007-08-07 23:08 801 查看
一、首先保证这样一个开发环境。
Development environment

1. Microsoft Visual Studio 2005
2. One of the following operating systems: Microsoft Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional, Windows XP Tablet PC Edition, Windows 2000 Professional SP4 or later versions, Windows 2000 Server SP4 or later versions
3. Microsoft Internet Explorer 6.0 or later versions. Required to access SQL Server Mobile Books Online
4. Microsoft ActiveSync 4.0 or later versions. Required to debug and deploy applications
Client environment

1. Any device that runs Microsoft Windows CE 5.0, Microsoft Windows XP Tablet PC Edition, Microsoft Mobile Pocket PC 2003, Microsoft Mobile Version 5.0 Pocket PC, or Microsoft Mobile Version 5.0 Smart Phone.
2. Between 2 MB and 3 MB of available storage space, depending on processor type and components installed.
Server environment¹

1. Microsoft SQL Server 2000 SP3a or later versions
2. SQL Server 2005 . Intel or compatible Pentium 600 MHz or greater processor (recommended processor speed is1 GHz or greater), 256 MB RAM minimum (recommended RAM 512 MB or more), hard disk space 250 MB For information about operating system requirements, see "Hardware and Software Requirements for Installing SQL Server 2005" in SQL Server 2005 Books Online.
3. IIS. Supported on Windows Server 2003, Windows 2000 SP4 or later versions, and Windows XP 120 MB of available disk space on the server
4. Microsoft ActiveSync 4.0 or later versions. Required when you use SQL Server 2005 Management Studio to manage SQL Server Mobile databases on connected devices.
5. Microsoft Internet Explorer 6.0 or later versions

二、安装SQL SERVER MOBILE,实现本地数据库
This topic describes how to install the Microsoft SQL Server 2005 Mobile Edition (SQL Server Mobile) Server tools on a computer that is running Microsoft Internet Information Services (IIS).

This procedure assumes that you have Microsoft SQL Server 2005 installed on the computer that is running IIS. If you do not, you must download SQL Server Mobile Server Tools from Microsoft SQL Server 2005 Mobile Edition Home.

Installing Server Tools
1. From the <drive>:/Program Files/Microsoft SQL Server/90/Tools/Binn/VSShell/Common7/IDE folder, double-click Sqlce30setupen.msi.
2. Click Next.
3. Accept the License Agreement, and then click Next.
4. If the System Configuration Check passes all checks, click Next. Otherwise, click More next to the failed checks for information about correcting the problem.
5. The installation wizard automatically detects the versions of SQL Server to which you can synchronize data. The default path is <drive>:/Program Files/Microsoft SQL Server 2005 Mobile Edition. Modify the installation path by clicking Browse if required. Then, click Next.
6. Click Install.
7. Click Finish.
To install SQL Server 2005 Replication Components
1. On the computer that is running IIS, insert the SQL Server 2005 CD and run Setup.exe.
2. In the SQL Server Installation Wizard, on the Components to Install page, click Advanced.
3. On the Feature Selection page, click Client Components, and then click Connectivity Components to install the SQL Server 2005 replication components.
If you use Microsoft Visual Studio to build a .NET application that uses Microsoft SQL Server 2005 Mobile Edition (SQL Server Mobile), the first time that you deploy the application to a device, the SQL Server Mobile engine is automatically installed on the device. You can also install SQL Server Mobile to a device by manually copying the .cab files to the device. If you are building a native application, you must manually copy the .cab files.
To manually install SQL Server Mobile on a device
1. Install the .NET Compact Framework on the device. Copy the NETCFv2.<platform>.<processor>.cab file to your device from the following directory:
C:/Program Files/Microsoft Visual Studio 8/SDK/v2.0/CompactFramework/WindowsCE/<platform>/<processor>/
2. On the device, click the .cab file to install the .NET Compact Framework.
3. Copy the sqlce30.platform.processor.cab and sqlce30.repl.platform.processor.cab files to your device from the following directory:
C:/Program Files/Microsoft Visual Studio 8/SmartDevices/SDK/SQL Server/Mobile/v3.0/<platform>/<processor>/
If you use Microsoft Visual Studio to build a .NET application that uses Microsoft SQL Server 2005 Mobile Edition (SQL Server Mobile), and you deploy the application in debug mode, the SQL Server Mobile engine and Query Analyzer are automatically installed on the device. You can also install the Query Analyzer by copying the .cab file to the device. If you are building a native application, you must manually copy the .cab file.
SQL Server Mobile Query Analyzer is not available with Smart Phone 2005.
To manually install the Query Analyzer
1. Install the .NET Compact Framework on the device. Copy the following file to your device:
/Program Files/Microsoft Visual Studio 8/SDK/version/CompactFramework/WindowsCE/platform/processor/NETCFversion.platform.processor.cab.
2. On the device, click the .cab file to install the .NET Compact Framework.
3. Copy the sqlce30.dev.ENU.<platform>.<processor>.cab file to your device from the following directory:
C:/Program Files/Microsoft Visual Studio 8/SmartDevices/SDK/SQL Server/Mobile/v3.0/platform/processor/
4. On the device, click the .cab file to install the Query Analyzer.
5. A shortcut to Query Analyzer is added to the Start menu of the device.
The Microsoft SQL Server 2005 Mobile Edition (SQL Server Mobile) Database Upgrade tool lets you upgrade a SQL Server Mobile 1.0 or 2.0 database to work with SQL Server 2005 Mobile Edition. This command-line tool must run on the smart device, and both the source and destination databases must be located on the device.
To download and install the SQL Server Mobile Database Upgrade tool
1. The database upgrade tool is installed with Visual Studio 2005 as part of SqlMobile30DevTools[lang].msi file. The default location of the file is <drive>:/Program Files/Microsoft Visual Studio 8/SmartDevices/SDK/SQL Server/Mobile/v3.0/[platform]/[processor]/upgrade.exe.
2. Using ActiveSync, copy the upgrade.exe file to the My Device folder on the smart device.
To open a command line on the smart device
1. To open the command prompt window on a Pocket PC device, press and hold the action or enter button on the device.
2. While pressing the action or enter button, tap and hold the clock icon in the top menu bar.
3. Release the action or enter button. A menu with two options (Run and Clock) is displayed.
4. Click Run. The command prompt window is displayed.
It is important to note that this method of opening a command line might not work on all smart devices. For Pocket PC 2003 devices, you can install Windows Mobile Developer Power Toys, which includes the PPC Command Shell.
To run the upgrade tool
1. In the Open text box of the command prompt window, type the command to upgrade your database. The upgrade tool uses the following syntax:

upgrade.exe /s "/dir1/source.sdf" /sp "password1" /d "/dir2/destination.sdf" /dp “password2" /e /q

2. For more information about the parameters used with upgrade.exe, see the table later in this topic.
3. When the upgrade is completed, a message box displays the results, success or failure.
Combining a little deduction with some guesswork we fixed the problem by including the following PB catalog feature in our image:
Applications and Services Development -> Component Services -> Component Object Model -> COM -> CoCreateGuid functionality for OLE32
做完上述操作,就可以在平台上用鼠标点击查询分析器(Query Analyzer)来进行操作,但是此时还不能够用应用程序下载到平台上对数据库进行操作。如下图一样。

如果出现如下问题:
Additional information: Can't find PInvoke DLL 'sqlceme30.dll'.
那么按下述描写修改你的PB即可

上述过程用Query Analyzer建立了一个Mobile数据库。下面介绍如何能用应用程序对Mobile数据库进行操作:
Sometimes you might want to deploy an application that uses Microsoft SQL Server 2005 Mobile Edition (SQL Server Mobile) to a Windows-based computer. For example, you might want to stress-test your application or test connectivity functionality. To do this, you develop a Windows application that references the appropriate SQL Server Mobile .dll files. Deploying the application does not require special deployment steps.
To build and deploy a SQL Server Mobile Windows application
1. Open Windows Explorer and locate the following directory:
C:/Program Files/Microsoft Visual Studio 8/Common7/IDE
2. Select and copy the following files:

.dll file

Function
sqlceca30.dll

The SQL Server Mobile Client Agent. Required for applications that connect to SQL Server by using replication or remote data access.

sqlcecompact30.dll

Provides the compact database functionality. Required if your application will use compaction.

sqlceer30[language].dll

Contains error strings for SQL Server Mobile-generated errors. Required for all SQL Server Mobile applications.

sqlceme30.dll

Contains code required by the System.Data.SqlServerCe.dll file. Required for all SQL Server Mobile applications.

sqlceoledb30.dll

Provides OLE DB connectivity to SQL Server Mobile databases. Required only if your application uses OLE DB to connect to the SQL Server Mobile database.

sqlceqp30.dll

The SQL Server Mobile Query Processor. Required for all SQL Server Mobile applications.

sqlcese30.dll

The SQL Server Mobile Engine. Required for all SQL Server Mobile applications.

System.Data.SqlServerCe.dll

Contains the SQL Server Mobile namespace, which you reference in your application code. Required for all SQL Server Mobile applications.

1. Locate the bin folder of your Windows application.
2. Paste the files you copied in step 2 to the bin folder.
3. In your Microsoft Visual Studio 2005 project, add a reference to the copy of the System.Data.SqlServerCe.dll file that is in the bin folder. For more information, see Building a SQL Server Mobile Application for Tablet PCs.
4. When you deploy your application, copy all the .dll files together with your application's .exe and .dll files. This enables your application to use SQL Server Mobile without requiring a separate product installation.
通过上述步骤,编写操作数据库的代码,例如(我的一个最基本的测试程序)

Try {
string mySelectQuery = "SELECT chy FROM based Where temp=33";
SqlCeConnection myConnection = new SqlCeConnection("Data Source=/qaa.sdf;");
myConnection.Open();
SqlCeCommand myCommand = new SqlCeCommand(mySelectQuery, myConnection);
myCommand.CommandType = CommandType.Text;
SqlCeDataReader dtr = myCommand.ExecuteReader(0);
dtr.Read();
textBox1.Text = dtr.GetString(0);
myConnection.Close();
}
catch (SqlCeException ee)
{
MessageBox.Show(ee.Message);
}

SqlCeCommand myCommand = new SqlCeCommand(mySelectQuery, myConnection);
myCommand.CommandType = CommandType.Text;
SqlCeDataReader dtr = myCommand.ExecuteReader(0);
dtr.Read();
textBox1.Text = dtr.GetString(0);
myConnection.Close();
}
catch (SqlCeException ee)
{
MessageBox.Show(ee.Message);
}

将程序下载到平台上,运行,结果如下图所示:
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: 
相关文章推荐