G
Gary W. Smith
I'm running into an odd problem. I'm working on a PPC2003se
application that will pull information form a central database and dump
in into a local database. The backend database is SQL 2005 Express and
the local is SQL 2005 CE.
I have enabled virtual NE2000 network card in the enulated PPC and when
I start it I can open connections to various external web sites. All
looks well. When I start VS 2005 and run the app I loose network
connectivity. This was the first odd problem. So I enabled DMA
network transfers and cradled the PPC and I can open up connections to
various web sites after the app is deployed from VS 2005. So I know I
have some connectitivy now.
When I run the code sniplet below I always get failed access to the
network. I have also tested this with the firewall on my workstation
off. Basically I continually get "SQL Server does not exist or access
denied." The login does indeed work as I can hit it with SQL Manager
using these credentials, IP and port.
Basically I have two questions; 1) is the code sniplet below rational
for connecting to a SQL server from a Pocket PC 2) what is the best way
to emulate network connectivity in a development environment, given
that the end users will either be connected via wireless (LAN) or via
cradle.
Calling function...
Dim oRepl As New Replicatio
oRepl.LocalDBName = frmMain.AppPath & "\mobile.sdf"
oRepl.LocalDBEncrypt = False
oRepl.LocalDBPass = ""
oRepl.RemoteDBUser = "MobileUser"
oRepl.RemoteDBPass = "password"
oRepl.RemoteDBName = "dev_mobile"
oRepl.RemoteDBServer = "10.0.54.2\SQLEXPRESS,27858" 'Verified
that TCP is enabled.
oRepl.Push()
oRepl.Pull()
Public Class Replication
Private _sLocalDBName As String
Private _sLocalDBPass As String
Private _bLocalDBEncrypt As Boolean
Private _sRemoteDBServer As String
Private _sRemoteDBName As String
Private _sRemoteDBUser As String
Private _sRemoteDBPass As String
Public Function Pull() As Integer
Dim oLocalConn As New SqlServerCe.SqlCeConnection
Dim oLocalCommand As SqlServerCe.SqlCeCommand
Dim oLocalRS As SqlServerCe.SqlCeDataReader
Dim oRemoteConn As New SqlClient.SqlConnection
Dim oRemoteCommand As SqlClient.SqlCommand
Dim oRemoteRS As SqlClient.SqlDataReader
oLocalConn.ConnectionString = "data source=" & _sLocalDBName &
";password=" & _sLocalDBPass & ";encrypt database=" &
_bLocalDBEncrypt.ToString
oLocalConn.Open()
' Clear Clients
oLocalCommand = New SqlServerCe.SqlCeCommand("DELETE FROM
clients", oLocalConn)
oLocalCommand.ExecuteNonQuery()
oRemoteConn.ConnectionString = "server=" & _sRemoteDBServer &
";uid=" & _sRemoteDBUser & ";pwd=" & _sRemoteDBPass & ";database=" &
_sRemoteDBName
oRemoteConn.Open()
oRemoteCommand = New SqlClient.SqlCommand("SELECT client_id,
client_name FROM clients ORDER BY client_id", oRemoteConn)
oRemoteRS = oRemoteCommand.ExecuteReader
If oRemoteRS.Read Then
oLocalCommand = New SqlServerCe.SqlCeCommand("INSERT INTO
clients(client_id, client_name, is_new) VALUES(@client_id,
@client_name, 0)", oLocalConn)
Dim iClientID As Integer
Dim sClientName As String
Do
If Not IsDBNull(oRemoteRS("client_id")) Then iClientID
= oRemoteRS("client_id") Else iClientID = 0
If Not IsDBNull(oRemoteRS("client_name")) Then
sClientName = oRemoteRS("client_name") Else sClientName = ""
oLocalCommand.Parameters.Clear()
oLocalCommand.Parameters.Add("@client_id",
SqlDbType.Int).Value = iClientID
oLocalCommand.Parameters.Add("@client_name",
SqlDbType.NVarChar).Value = sClientName
oLocalCommand.ExecuteNonQuery()
Loop While oRemoteRS.Read
End If
oRemoteRS.Close()
oRemoteConn.Close()
oLocalConn.Close()
MsgBox("finished pull replication")
End Function
... Write only set functions removed...
End Class
application that will pull information form a central database and dump
in into a local database. The backend database is SQL 2005 Express and
the local is SQL 2005 CE.
I have enabled virtual NE2000 network card in the enulated PPC and when
I start it I can open connections to various external web sites. All
looks well. When I start VS 2005 and run the app I loose network
connectivity. This was the first odd problem. So I enabled DMA
network transfers and cradled the PPC and I can open up connections to
various web sites after the app is deployed from VS 2005. So I know I
have some connectitivy now.
When I run the code sniplet below I always get failed access to the
network. I have also tested this with the firewall on my workstation
off. Basically I continually get "SQL Server does not exist or access
denied." The login does indeed work as I can hit it with SQL Manager
using these credentials, IP and port.
Basically I have two questions; 1) is the code sniplet below rational
for connecting to a SQL server from a Pocket PC 2) what is the best way
to emulate network connectivity in a development environment, given
that the end users will either be connected via wireless (LAN) or via
cradle.
Calling function...
Dim oRepl As New Replicatio
oRepl.LocalDBName = frmMain.AppPath & "\mobile.sdf"
oRepl.LocalDBEncrypt = False
oRepl.LocalDBPass = ""
oRepl.RemoteDBUser = "MobileUser"
oRepl.RemoteDBPass = "password"
oRepl.RemoteDBName = "dev_mobile"
oRepl.RemoteDBServer = "10.0.54.2\SQLEXPRESS,27858" 'Verified
that TCP is enabled.
oRepl.Push()
oRepl.Pull()
Public Class Replication
Private _sLocalDBName As String
Private _sLocalDBPass As String
Private _bLocalDBEncrypt As Boolean
Private _sRemoteDBServer As String
Private _sRemoteDBName As String
Private _sRemoteDBUser As String
Private _sRemoteDBPass As String
Public Function Pull() As Integer
Dim oLocalConn As New SqlServerCe.SqlCeConnection
Dim oLocalCommand As SqlServerCe.SqlCeCommand
Dim oLocalRS As SqlServerCe.SqlCeDataReader
Dim oRemoteConn As New SqlClient.SqlConnection
Dim oRemoteCommand As SqlClient.SqlCommand
Dim oRemoteRS As SqlClient.SqlDataReader
oLocalConn.ConnectionString = "data source=" & _sLocalDBName &
";password=" & _sLocalDBPass & ";encrypt database=" &
_bLocalDBEncrypt.ToString
oLocalConn.Open()
' Clear Clients
oLocalCommand = New SqlServerCe.SqlCeCommand("DELETE FROM
clients", oLocalConn)
oLocalCommand.ExecuteNonQuery()
oRemoteConn.ConnectionString = "server=" & _sRemoteDBServer &
";uid=" & _sRemoteDBUser & ";pwd=" & _sRemoteDBPass & ";database=" &
_sRemoteDBName
oRemoteConn.Open()
oRemoteCommand = New SqlClient.SqlCommand("SELECT client_id,
client_name FROM clients ORDER BY client_id", oRemoteConn)
oRemoteRS = oRemoteCommand.ExecuteReader
If oRemoteRS.Read Then
oLocalCommand = New SqlServerCe.SqlCeCommand("INSERT INTO
clients(client_id, client_name, is_new) VALUES(@client_id,
@client_name, 0)", oLocalConn)
Dim iClientID As Integer
Dim sClientName As String
Do
If Not IsDBNull(oRemoteRS("client_id")) Then iClientID
= oRemoteRS("client_id") Else iClientID = 0
If Not IsDBNull(oRemoteRS("client_name")) Then
sClientName = oRemoteRS("client_name") Else sClientName = ""
oLocalCommand.Parameters.Clear()
oLocalCommand.Parameters.Add("@client_id",
SqlDbType.Int).Value = iClientID
oLocalCommand.Parameters.Add("@client_name",
SqlDbType.NVarChar).Value = sClientName
oLocalCommand.ExecuteNonQuery()
Loop While oRemoteRS.Read
End If
oRemoteRS.Close()
oRemoteConn.Close()
oLocalConn.Close()
MsgBox("finished pull replication")
End Function
... Write only set functions removed...
End Class