Saturday, February 25, 2012

Developing Microsoft SQL Server CE 2.0 Merge Replication Using .NET Compact Framework

We are developing Microsoft SQL Server CE 2.0 Merge Replication Using .NET Compact Framework. There is need of sinhronizations between SQL 2005 Mobile Edition witch resides on Barcode terminal (Windows CE) and SQL 2005 Developer Edition (on Windows XP). Everything is done by the book. There is few lines of code that we are using:
public bool Replicate()
{ bool ret = true;
SqlCeReplication repl = null;
try {
// Instantiate and configure
SqlCeReplication object repl = new SqlCeReplication();
string dbFile = ........
repl.InternetUrl = this.InternetUrl;
repl.InternetLogin = this.InternetLogin;
repl.InternetPassword = this.InternetPassword;
repl.Publisher = this.Publisher;
repl.PublisherDatabase = this.PublisherDatabase;
repl.PublisherLogin = this.PublisherLogin;
repl.PublisherPassword = this.PublisherPassword;
repl.Publication = this.Publication;
repl.Subscriber = this.Subscriber;
repl.SubscriberConnectionString ="Data Source=" +dbFile;
if (!System.IO.File.Exists(dbFile))
{ repl.AddSubscription(AddOption.CreateDatabase);
}
repl.Synchronize();
}
IIS is configured, but in log on the server we've got this error:
2007/08/09 15:33:02 Hr=80004005 ACK:Error for DistributorSessionID = 58 2007/08/09 15:33:02 Hr=80004005 The SQL statement failed to execute. [,,,SQL statement,,] 28560 Please give us posible solution of this problem, we have searched on forums but with no result. p.s. I'ts urgentWe are developing Microsoft SQL Server CE 2.0 Merge Replication Using .NET Compact Framework. There is need of sinhronizations between SQL 2005 Mobile Edition witch resides on Barcode terminal (Windows CE) and SQL 2005 Developer Edition (on Windows XP). Everything is done by the book. There is few lines of code that we are using:
public bool Replicate()
{ bool ret = true;
SqlCeReplication repl = null;
try {
// Instantiate and configure
SqlCeReplication object repl = new SqlCeReplication();
string dbFile = ........
repl.InternetUrl = this.InternetUrl;
repl.InternetLogin = this.InternetLogin;
repl.InternetPassword = this.InternetPassword;
repl.Publisher = this.Publisher;
repl.PublisherDatabase = this.PublisherDatabase;
repl.PublisherLogin = this.PublisherLogin;
repl.PublisherPassword = this.PublisherPassword;
repl.Publication = this.Publication;
repl.Subscriber = this.Subscriber;
repl.SubscriberConnectionString ="Data Source=" +dbFile;
if (!System.IO.File.Exists(dbFile))
{ repl.AddSubscription(AddOption.CreateDatabase);
}
repl.Synchronize();
}
IIS is configured, but in log on the server we've got this error:
2007/08/09 15:33:02 Hr=80004005 ACK:Error for DistributorSessionID = 58 2007/08/09 15:33:02 Hr=80004005 The SQL statement failed to execute. [,,,SQL statement,,] 28560 Please give us posible solution of this problem, we have searched on forums but with no result. p.s. I'ts urgent|||

i hope this will be usefull

Public Shared Function CreateDatabase(ByVal strUserName As String, ByVal strPassword As String) As Boolean
Dim strPublisher, strPublisherDataBase, strPublication As String
Dim strDistributor, strInternetURL As String
Dim strSubscriberDatabasePassword As String
Dim strSubscriberDatabasePath As String
Try
Dim rmReplication As New System.Resources.ResourceManager( _
"RoadRunner.Replication", _
System.Reflection.Assembly.GetExecutingAssembly())
' Assign the resource manager values to data members
strPublication = rmReplication.GetString("Publication")
strPublisher = rmReplication.GetString("Publisher")
strPublisherDataBase = rmReplication.GetString("PublisherDatabase")
strDistributor = rmReplication.GetString("Distributor")
strInternetURL = rmReplication.GetString("InternetUrl")
strSubscriberDatabasePassword = rmReplication.GetString("SubscriberDatabasePassword")
strSubscriberDatabasePath = rmReplication.GetString("SubscriberDatabasePath")

Catch ex As Exception

' MessageBox.Show(ex.Message)
LogFile.AddEntry(ex.Message)
Cursor.Current = Cursors.Default
' if any error occured while reading from resource file, exit function
Return False

End Try
' Declare replication object
Dim replicate As SqlServerCe.SqlCeReplication


Try
' 1: Instantiate replication option
replicate = New SqlServerCe.SqlCeReplication

'***********************************************************
' SQL server 2000 machine name and database for replication
'***********************************************************
replicate.Publisher = strPublisher
replicate.PublisherDatabase = strPublisherDataBase
'**********************************************************
' Publisher server info
'**********************************************************
replicate.Publication = strPublication
replicate.PublisherLogin = strUserName
replicate.PublisherPassword = strPassword
replicate.PublisherSecurityMode = SqlServerCe.SecurityType.NTAuthentication
'**********************************************************
' Distributor server info
'**********************************************************
replicate.Distributor = strDistributor
replicate.DistributorLogin = strUserName
replicate.DistributorPassword = strPassword
replicate.DistributorSecurityMode = SqlServerCe.SecurityType.NTAuthentication
'***********************************************************
' Set subscriber info for salesman and db on PDA
'***********************************************************
replicate.Subscriber = "BTCHH"
replicate.SubscriberConnectionString = "Provider=Microsoft.SQLSERVER.OLEDB.CE.2.0;" _
& "Data Source=" & strSubscriberDatabasePath _
& ";Password=" & strSubscriberDatabasePassword
'***********************************************************
' IIS server info
'***********************************************************
replicate.InternetUrl = strInternetURL
replicate.InternetLogin = strUserName
replicate.InternetPassword = strPassword
' if database doesn't exist then create it
If System.IO.File.Exists(strSubscriberDatabasePath) = False Then
Try
replicate.AddSubscription(SqlServerCe.AddOption.CreateDatabase)

replicate.Synchronize()
Return True
Catch ex As SqlServerCe.SqlCeException
System.IO.File.Delete(strSubscriberDatabasePath)
ReplicationOperationErrors(ex)
Cursor.Current = Cursors.Default
Return False
End Try
End If

Try
' BuildObject.Compact(strSubscriberDatabasePath)
replicate.ReinitializeSubscription(True)
replicate.Synchronize()
'BuildObject.Dispose()

Catch ex As SqlServerCe.SqlCeException

replicate.Dispose()
MsgBox(ex.Message)
End Try

Return True
Catch ex As SqlServerCe.SqlCeException
ReplicationOperationErrors(ex)
Cursor.Current = Cursors.Default
Return False
Finally
'BuildObject.Dispose()
replicate.Dispose()
End Try
End Function

No comments:

Post a Comment