各位专家大家好,问一个问题困扰了我很久就是sqlce 2.0与sql 2000 同步的问题
我的开发环境为
vb 2005 +sqlce 2.0 sp3与sql 2000 sp3 +IIS 5.1
我是在wince 5.0的mini2440 板上进行测试的
在板上验证IIS的配置 http://10.8.1.59/sqlce/sscesa20.dll 好像也成功了出现"SQL Server CE Server Agent"
程序参照如下:
http://dev.yesky.com/322/2672322_1.shtml 窦瑞欣写的
Imports System.Data
Imports System.Data.SqlServerCe
Imports System.IO
Public Class Form1
Const ProgramPath = "my documents" '应用程序路径
Const LocalDatabaseFile = ProgramPath & "\Task.sdf" '本地Pocket PC数据库文件-sdf文件的路径
Const LocalConnString = "Data Source=" & LocalDatabaseFile '本地数据库连接字符串
Private SqlCESvrAgentUrl As String '运行 SQL Server Ce Server Agent的计算机的 Web 地址
Private RemoteSqlServerName As String '远程Sql Server 2000数据库服务器名称
Private RemoteConnString As String '连接远程Sql Server 2000的连接字符串
Private CurrentLogonUserID, CurrentLogonUserName As String
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
If LogOnRemoteHost(txtInternetUrl.Text, txtSqlServer.Text, txtUserID.Text, txtPassword.Text) Then
GetTaskListOfEMP_ID(txtUserID.Text)
MsgBox("验证成功。")
Else
MsgBox("验证失败,请核对员工ID号和密码,然后重新输入。")
End If
End Sub
Function LogOnRemoteHost(ByVal SqlAgentUrl As String, ByVal SqlServerName As String, ByVal EMPId As String, ByVal Password As String) As Boolean
Dim en As SqlCeEngine = Nothing
Dim rda As SqlCeRemoteDataAccess = Nothing
Dim connLocalUserInfo As SqlCeConnection = Nothing
Dim daLocalUserInfo As SqlCeDataAdapter = Nothing
Dim dtLocalUserInfo As DataTable = Nothing
SqlCESvrAgentUrl = SqlAgentUrl
RemoteSqlServerName = SqlServerName
RemoteConnString = [String].Format("Provider=sqloledb; Data Source={0}; Initial Catalog=Task; Integrated Security=SSPI", _
RemoteSqlServerName)
If (File.Exists(LocalDatabaseFile)) Then
File.Delete(LocalDatabaseFile)
End If
' 创建本地的用户数据库文件用于RDA的PULL
en = New SqlCeEngine("Data Source=" & LocalDatabaseFile)
en.CreateDatabase()
rda = New SqlCeRemoteDataAccess
rda.LocalConnectionString = "Data Source=" & LocalDatabaseFile
rda.InternetUrl = SqlCESvrAgentUrl
rda.InternetLogin = ""
rda.InternetPassword = ""
Try
' 下载允许登录PPC的合法的用户信息数据到本地
rda.Pull("UserInfo", "Select * from employee where emp_id='" + EMPId + "' and emp_password='" + Password + "'", RemoteConnString, RdaTrackOption.TrackingOff)
Finally
' 释放 RDA Object.
rda.Dispose()
End Try
' 创建 SQL Server CE 本地连接.
connLocalUserInfo = New SqlCeConnection("Data Source=" & LocalDatabaseFile)
' 创建一个 data adapter.
daLocalUserInfo = New SqlCeDataAdapter
daLocalUserInfo.SelectCommand = connLocalUserInfo.CreateCommand()
daLocalUserInfo.SelectCommand.CommandText = "SELECT * FROM UserInfo"
' 创建一个数据库表保存用户信息数据.
dtLocalUserInfo = New DataTable("UserInfo")
Try
daLocalUserInfo.Fill(dtLocalUserInfo) '填充数据 DataTable
If dtLocalUserInfo.Rows.Count > 0 Then '验证通过
CurrentLogonUserID = dtLocalUserInfo.Rows(0).Item("emp_id").ToString
CurrentLogonUserName = dtLocalUserInfo.Rows(0).Item("emp_name").ToString
Return True
Else '验证失败,返回false
Return False
End If
Catch e As SqlCeException
MsgBox(e.Message)
Return False
End Try
End Function
Function GetTaskListOfEMP_ID(ByVal EMPId As String) As DataTable
Dim en As SqlCeEngine = Nothing
Dim rda As SqlCeRemoteDataAccess = Nothing
Dim connLocalTask As SqlCeConnection = Nothing
Dim daLocalTask As SqlCeDataAdapter = Nothing
Dim dtLocalTask As DataTable = Nothing
RemoteConnString = [String].Format("Provider=sqloledb; Data Source={0}; Initial Catalog=Task; Integrated Security=SSPI", _
RemoteSqlServerName)
' 创建本地的用户数据库文件用于RDA的PULL
en = New SqlCeEngine("Data Source=" & LocalDatabaseFile)
rda = New SqlCeRemoteDataAccess
' Set the RDA properties.
'
rda.LocalConnectionString = "Data Source=" & LocalDatabaseFile
rda.InternetUrl = SqlCESvrAgentUrl
rda.InternetLogin = ""
rda.InternetPassword = ""
' 创建 SQL Server CE 本地连接.
connLocalTask = New SqlCeConnection("Data Source=" & LocalDatabaseFile)
DropItemListTable()
Try
' 下载允许登录PPC的合法的用户信息数据到本地
rda.Pull("itemlist", "Select * from itemlist where emp_id='" + EMPId + "'", RemoteConnString, RdaTrackOption.TrackingOnWithIndexes)
Finally
' 释放 RDA Object.
rda.Dispose()
End Try
' 创建一个 data adapter.
daLocalTask = New SqlCeDataAdapter
daLocalTask.SelectCommand = connLocalTask.CreateCommand()
daLocalTask.SelectCommand.CommandText = "SELECT * FROM itemlist"
' 创建一个数据库表保存信息数据.
'
dtLocalTask = New DataTable("itemlist")
Try
daLocalTask.Fill(dtLocalTask) '填充数据 DataTable
If Not dtLocalTask.Rows.Count > 0 Then
MsgBox("没有任务记录!")
End If
Catch e As SqlCeException
MsgBox(e.Message)
End Try
Return dtLocalTask
End Function
Private Function RdaSync() As Boolean
RdaSync = False
'Dim sqlCmd As String
Dim rda As New SqlCeRemoteDataAccess
' Set the RDA properties.
'
rda.LocalConnectionString = "Data Source=" & LocalDatabaseFile
rda.InternetUrl = SqlCESvrAgentUrl
rda.InternetLogin = ""
rda.InternetPassword = ""
Try
rda.Push("itemlist", RemoteConnString, RdaBatchOption.BatchingOn)
'DataGrid1.DataSource = GetTaskListOfEMP_ID(txtUserID.Text)
Return True
Finally
' Dispose of the RemoteDataAccess object.
'
rda.Dispose()
End Try
End Function
下面还有一些程序写不下了~~~~~~~~~~~
出现如下错误
Internal error: HTTP header information is either corrupted or missing in the transport message. It could be a network transmission error or an IIS problem.
位于 System.Data.SqlServerCe.NativeMethods.CheckHRESULT()
位于 System.Data.SqlServerCe.SqlCeRemoteDataAccess.Pull()
求各们高手指教,这一个问题搞的我花了二周了,几乎快崩溃了,谢谢
问题就出在这边,我运行到这里就提示错误
' 下载允许登录PPC的合法的用户信息数据到本地
rda.Pull("itemlist", "Select * from itemlist where emp_id='" + EMPId + "'", RemoteConnString, RdaTrackOption.TrackingOnWithIndexes)
是否是我的IIS配置问题???
It could be a network transmission error or an IIS problem.
可能是网络传输错误或者IIS问题。。。。。
1.IIS只要你能访问网页的话就应该没问题。。。
2.检查下你的数据库控件。不知道你用的是ADO还是什么的。。这个要检查下。。。
3.访问权限?这个也是个问题。。。是否有访问修改数据库的权限。
个人理解。仅供参考。
回feishanm:
1、在CE浏览器里输入 http://10.8.1.59/sqlce/sscesa20.dll 有看到
SQL Server CE Server Agent
2、是什么意思我不清楚???我是新手能否具体一些???
还有一个我怀疑是不是我程序中引用的
System.Data.SqlServerCe 版本是3.0.3600.0
路径是D:\Program Files\Microsoft Visual Studio 8\SmartDevices\SDK\SQL Server\Mobile\v3.0
是不是说我安装vs 2005它使用的是sqlce 3.0或是sql 3.5???
而我配置的是sqlce 2.0+sql 2000服务器所导致不能同步的问题????
IIS中是否要配置什么指向SQL 2000中的数据库???
我是新手,一边学一边做,要赶着做论文,哪位好心的大哥能否帮小弟一把,感激涕零。我的QQ:45039535 ,如果成功定给酬谢!!
2、是什么意思我不清楚???我是新手能否具体一些???
---------------------
比如你需要同步到CE的表名为test,要先保证SQL CE没test这表,才可以同步下来。
另:你CE引用的sqlce3.0的版本,在服务器上也配置3.0的试试吧。
我也在弄这个,我这里可以PULL了.但是不能PUSH.....还在试
我的QQ:49440483