作者在 2008-11-06 17:28:05 发布以下内容
前提:
1.在PC上安装Microsoft SQL Server CE 2.0
2.PC上已经安装了Microsoft SQL Server服务器
3.已经下载了Microsoft SQL Server升级到SP4的升级包
4.已经下载了Microsoft SQL Server CE 2.0升级到SP4的安装包
软件配置:
1.安装Microsoft SQL Server CE 2.0,在安装时会提示有错误,此时点OK结束安 装,错误的原因时Microsoft SQL Server和Microsoft SQL Server CE 2.0不兼容,微 软使用升级Microsoft SQL Server CE 2.0和Microsoft SQL Serve的方法解决了不兼 容问题。
2.安装完Microsoft SQL Server CE 2.0后,将Microsoft SQL Server升级到SP4.
3.然后将Microsoft SQL Server CE 2.0升级到SP4,升级的过程中可以根据提示配置 虚拟目录。
RDA代码:
1.在PC上安装Microsoft SQL Server CE 2.0
2.PC上已经安装了Microsoft SQL Server服务器
3.已经下载了Microsoft SQL Server升级到SP4的升级包
4.已经下载了Microsoft SQL Server CE 2.0升级到SP4的安装包
软件配置:
1.安装Microsoft SQL Server CE 2.0,在安装时会提示有错误,此时点OK结束安 装,错误的原因时Microsoft SQL Server和Microsoft SQL Server CE 2.0不兼容,微 软使用升级Microsoft SQL Server CE 2.0和Microsoft SQL Serve的方法解决了不兼 容问题。
2.安装完Microsoft SQL Server CE 2.0后,将Microsoft SQL Server升级到SP4.
3.然后将Microsoft SQL Server CE 2.0升级到SP4,升级的过程中可以根据提示配置 虚拟目录。
RDA代码:
Public Class sqlce
Private dbPath As String = "Flash File Store\sql1.sdf"
'创建数据库
Public Function createDataBase() As Boolean
If File.Exists(dbPath) Then
File.Delete(dbPath)
End If
Dim dbEngine As SqlCeEngine = New SqlCeEngine
dbEngine.LocalConnectionString = "Data Source=" + dbPath
Try
dbEngine.CreateDatabase()
Return True
Catch ex As SqlCeException
Throw New Exception("数据库创建失败,原因是:" + ex.Message)
Return False
End Try
End Function
Private dbPath As String = "Flash File Store\sql1.sdf"
'创建数据库
Public Function createDataBase() As Boolean
If File.Exists(dbPath) Then
File.Delete(dbPath)
End If
Dim dbEngine As SqlCeEngine = New SqlCeEngine
dbEngine.LocalConnectionString = "Data Source=" + dbPath
Try
dbEngine.CreateDatabase()
Return True
Catch ex As SqlCeException
Throw New Exception("数据库创建失败,原因是:" + ex.Message)
Return False
End Try
End Function
'为数据库添加表
Public Function createTable() As Boolean
Dim connDB As SqlCeConnection = New SqlCeConnection
Dim cmdDB As SqlCeCommand = New SqlCeCommand
connDB.ConnectionString = "Data Source=" + dbPath
connDB.Open()
cmdDB.Connection = connDB
'下面是创建Item Master表的SQL语句
cmdDB.CommandText = "create table linkman " + "(id nchar(10) " + ",name nchar(10) " + ",address nchar(50) " + ",phone nchar(11))"
Try
cmdDB.ExecuteNonQuery()
connDB.Close()
Return True
Catch ex As SqlCeException
Throw New Exception("添加表失败,原因是:" + ex.Message)
connDB.Close()
Return False
End Try
End Function
Public Function createTable() As Boolean
Dim connDB As SqlCeConnection = New SqlCeConnection
Dim cmdDB As SqlCeCommand = New SqlCeCommand
connDB.ConnectionString = "Data Source=" + dbPath
connDB.Open()
cmdDB.Connection = connDB
'下面是创建Item Master表的SQL语句
cmdDB.CommandText = "create table linkman " + "(id nchar(10) " + ",name nchar(10) " + ",address nchar(50) " + ",phone nchar(11))"
Try
cmdDB.ExecuteNonQuery()
connDB.Close()
Return True
Catch ex As SqlCeException
Throw New Exception("添加表失败,原因是:" + ex.Message)
connDB.Close()
Return False
End Try
End Function
'Public Sub updateDB(ByVal sqlstr As String)
' Dim connDB As SqlCeConnection = New SqlCeConnection
' Dim cmdDB As SqlCeCommand = New SqlCeCommand
' Dim connDB As SqlCeConnection = New SqlCeConnection
' Dim cmdDB As SqlCeCommand = New SqlCeCommand
' connDB.ConnectionString = "Data Source=" + dbPath
' connDB.Open()
' cmdDB.Connection = connDB
' connDB.Open()
' cmdDB.Connection = connDB
' cmdDB.CommandText = sqlstr
' cmdDB.ExecuteNonQuery()
' connDB.Close()
'End Sub
'下载服务器上的数据到Mobile
Public Function downDataFromServer() As Boolean
'连接服务器的字符串
Dim radOleDbConnecString As String = "Provider=sqloledb; Data Source=HIGHTONEZWC;Initial Catalog=Northwind; " + "User Id=sa;Password = sa"
Dim rda As SqlCeRemoteDataAccess
' cmdDB.ExecuteNonQuery()
' connDB.Close()
'End Sub
'下载服务器上的数据到Mobile
Public Function downDataFromServer() As Boolean
'连接服务器的字符串
Dim radOleDbConnecString As String = "Provider=sqloledb; Data Source=HIGHTONEZWC;Initial Catalog=Northwind; " + "User Id=sa;Password = sa"
Dim rda As SqlCeRemoteDataAccess
Dim tableName As String
tableName = "Customers"
Dim sqlString As String = "IF Exists(Select 1 From sysObjects Where Name ='" + tableName + "' And Type In ('S','U')) drop table " + tableName
tableName = "Customers"
Dim sqlString As String = "IF Exists(Select 1 From sysObjects Where Name ='" + tableName + "' And Type In ('S','U')) drop table " + tableName
Try
rda = New SqlCeRemoteDataAccess
'IIS允许匿名访问所以不用网络名和密码
'rda.InternetLogin = "MyLogin"
'rda.InternetPassword = "password"
rda.InternetUrl = "http://192.168.0.72/sqlce/sscesa20.dll"
rda.LocalConnectionString = "Provider=Microsoft.SQLSERVER.OLEDB.CE.2.0;Data Source=Flash File Store\sql1.sdf"
rda.Pull(tableName, "select * from Customers", radOleDbConnecString, RdaTrackOption.TrackingOn)
rda.Dispose()
Return True
Catch ex As SqlException
Throw New Exception("下载数据失败,原因是:" + ex.Message)
rda.Dispose()
Return False
End Try
End Function
rda = New SqlCeRemoteDataAccess
'IIS允许匿名访问所以不用网络名和密码
'rda.InternetLogin = "MyLogin"
'rda.InternetPassword = "password"
rda.InternetUrl = "http://192.168.0.72/sqlce/sscesa20.dll"
rda.LocalConnectionString = "Provider=Microsoft.SQLSERVER.OLEDB.CE.2.0;Data Source=Flash File Store\sql1.sdf"
rda.Pull(tableName, "select * from Customers", radOleDbConnecString, RdaTrackOption.TrackingOn)
rda.Dispose()
Return True
Catch ex As SqlException
Throw New Exception("下载数据失败,原因是:" + ex.Message)
rda.Dispose()
Return False
End Try
End Function
'将Mobile里的数据上传的服务器
Public Function uploadDataToServer() As Boolean
'连接服务器的字符串
Dim radOleDbConnecString As String = "Provider=sqloledb; Data Source=HIGHTONEZWC;Initial Catalog=Northwind; " + "User Id=sa;Password = sa"
Dim rda As SqlCeRemoteDataAccess
Public Function uploadDataToServer() As Boolean
'连接服务器的字符串
Dim radOleDbConnecString As String = "Provider=sqloledb; Data Source=HIGHTONEZWC;Initial Catalog=Northwind; " + "User Id=sa;Password = sa"
Dim rda As SqlCeRemoteDataAccess
Try
rda = New SqlCeRemoteDataAccess
'IIS允许匿名访问所以不用网络名和密码
'rda.InternetLogin = "MyLogin"
'rda.InternetPassword = "<password>"
rda.InternetUrl = "http://192.168.0.72/sqlce/sscesa20.dll"
rda.LocalConnectionString = "Provider=Microsoft.SQLSERVER.OLEDB.CE.2.0;Data Source=Flash File Store\sql1.sdf"
rda = New SqlCeRemoteDataAccess
'IIS允许匿名访问所以不用网络名和密码
'rda.InternetLogin = "MyLogin"
'rda.InternetPassword = "<password>"
rda.InternetUrl = "http://192.168.0.72/sqlce/sscesa20.dll"
rda.LocalConnectionString = "Provider=Microsoft.SQLSERVER.OLEDB.CE.2.0;Data Source=Flash File Store\sql1.sdf"
rda.Push("Customers", radOleDbConnecString)
rda.Dispose()
Return True
Catch ex As SqlCeException
Throw New Exception("上传数据失败,原因是:" + ex.Message)
rda.Dispose()
Return False
End Try
End Function
End Class
rda.Dispose()
Return True
Catch ex As SqlCeException
Throw New Exception("上传数据失败,原因是:" + ex.Message)
rda.Dispose()
Return False
End Try
End Function
End Class