Showing posts with label merge. Show all posts
Showing posts with label merge. Show all posts

Tuesday, March 20, 2012

Applying the updates to SQL Mobile Server?!

Dear MSDN Support,

Here i am back with an inquiry about the last process of Merge Replication between SQL Mobile 2005 and SQL Server 2005.

Well i have performed all the steps found in the tutorial of the SQL Mobile Edition Books Online, and everything went on so fine and smooth. Now when i deploy my application on the Pocket PC emulator all possible SQL queries work and modify the data only in the emulator, i had installed ActiveSync 4.0 and it synchronizes the SQL Mobile data with the SQL Mobile server only when i copy the database from the emulator to my desktop, and this way is not efficient to my project, i need a better way to synchronize the data between the database on the emulator and that on the SQL Mobile Server.

I'll be looking forward to getting your help as soon as possible.

Thank you for your attention.

Best Regards;

Just FYI: there's no “MSDN support” on these forums, all answers are provided by

volunteers including your fellow developers, MVPs and Microsoft's employees.

|||

Thank you for your notice, and thank you for spotting at my problem!

|||

Mr Ahmad,

Just checking - did you figure out how to perform replication from your emulator to SQL Server? I couldn't tell from yor last post if you had solved your issue and are doing ok now. Let us know.

Thanks,

Darren

|||

Dear Darren,

I appreciate your reply alot, regarding the replication from the emulator to SQL Server, i had written the following code to my project and i am calling the function synchronize from a simple button.Here is the code i wrote for the Sync.

Dim repl As New SqlCeReplication()

repl.InternetUrl = "http://TOSHIBAMAN/Clinic/sqlcesa30.dll"

repl.Publisher = "TOSHIBAMAN"

repl.PublisherDatabase = "Clinic"

repl.PublisherSecurityMode = SecurityType.NTAuthentication

repl.Publication = "Clinic"

repl.Subscriber = "Clinic"

repl.SubscriberConnectionString = "Data Source=\My Documents\Clinic.sdf; Max Database Size=128;Default Lock Escalation =100;"

Try

repl.AddSubscription(AddOption.ExistingDatabase)

repl.Synchronize()

Catch err As SqlCeException

MessageBox.Show(err.ToString)

End Try

When clicking the button Synchronize the emulator fires the following message:

The SQL Mobile subscription already exists. Publisher, PublisherDatabase,and Publication for
this subscription should be different from any existing subscription

So what i do is to sync the database in the emulator and that in the SQL Mobile through the ActiveSync 4.0 then i connect to my database in the SQL Mobile and expand Replication right click on the subscription and choose to Synchronize the subscription.

But after i read some threads here, and the books online i do believe that there is a way which synchronizes the subscription from the emulator to the SQL Mobile to the original database engine!!

I'll be looking forward to getting your comments and advices.

Thank you alot for your attention!

Best Regards;

|||

Mr Ahmed,

Your code is very close - here are some corrections:

1. if you choose to use NT Authentication, you will have to provide the InternetLogin and InternetPassword properties as well. I suggest you start out by just using anonymous authentication until you have the replication working and then add more security afterwards.

2. in the connection string, it is not necessary to say max database size = 128 and Lock Escalation = 100 because these are the default values for SQL Mobile

3. if you are trying to dynamically create the Clinic.sdf SQL Mobile database upon the first merge replication synchronize, then you want to use AddOption.CreateDatabase.

So some sample code would look like this:

Public Function GetReplication() As SqlCeReplication

Dim repl As SqlCeReplication = Nothing

Try
repl = New SqlCeReplication()

repl.InternetUrl = Configuration.GetAppSetting("REPLICATION_URL")
repl.Publisher = Configuration.GetAppSetting("REPLICATION_PUBLISHER")
repl.PublisherDatabase = Configuration.GetAppSetting("REPLICATION_PUBLISHER_DB")
repl.PublisherSecurityMode = SecurityType.NTAuthentication
repl.Publication = Configuration.GetAppSetting("REPLICATION_PUBLICATION")
repl.Subscriber = Configuration.GetAppSetting("REPLICATION_SUBSCRIBER")
repl.SubscriberConnectionString = Configuration.GetAppSetting("REPLICATION_SUBSCRIBER_CONNECTION_STRING")

If Not System.IO.File.Exists(_dbmsFile) Then
repl.AddSubscription(AddOption.CreateDatabase)
End If

Catch ex As Exception
DisplaySQLCEErrors(ex)
Return Nothing
End Try

Return repl

End Function

Where the value of _dbmsFile (in your case) is "\My Documents\Clinic.sdf"

The point of the code sample above is to show you the minumum set of properties you need to set on the SqlCeReplication object in order for it to work, as well as how to handle dynamically creating the SQL Mobile database the first time (if it doesn't already exist)

Since you are using an emulator, you need to ensure that the emulator's network settings are configured to communicate with IIS and SQL Server on the server (which I can see is the same development machine you are running the emulator on). So open Pocket Internet Explorer on the emulator and try the URL http://TOSHIBAMAN/Clinic/sqlcesa30.dll to verify that you can get to the SQL Mobile server tools directory on IIS.

Darren

sql

Applying the snapshot for Merge rep fails everytime because Connection is reset?

Hi guys, Im desperately hoping someone here can help me. Ive been trying to set up merge replication between 2 servers all weekend and it keeps failing. Im setting this up as follows
The Publisher/Distributor is a SQL Server 2005 machine, the database being replicated is 4gb, and the only subscriber is a SQL Server 2000 SP4 machine. I set up my publication normally, and set up the push subscription, adn set it to initialize immediately. It weill then start bulk copying and go on for about 3-4 hours before it fails and gives me the errors:

Error messages:
The merge process was unable to deliver the snapshot to the Subscriber. If using Web synchronization, the merge process may have been unable to create or write to the message file. When troubleshooting, restart the synchronization with verbose history logging and specify an output file to which to write. (Source: MSSQL_REPL, Error number: MSSQL_REPL-2147201001)
Get help: http://help/MSSQL_REPL-2147201001
The process could not bulk copy into table '"dbo"."CONTENT"'. (Source: MSSQL_REPL, Error number: MSSQL_REPL20037)
Get help: http://help/MSSQL_REPL20037
An existing connection was forcibly closed by the remote host. (Source: MSSQLServer, Error number: 0)
Get help: http://help/0
One or more BLOB columns could not be sent to the server, attempt to recover from the problem failed. (Source: MSSQLServer, Error number: 0)
Get help: http://help/0
Communication link failure (Source: MSSQLServer, Error number: 0)
Get help: http://help/0
Unspecified error (Source: MSSQLServer, Error number: 0)
Get help: http://help/0
Failed to send batch after max errors (Source: MSSQLServer, Error number: 0)

This is driving me crazy as I havent slept in ages trying to get this fixed. Anyone have any idea whats going on? Its always one of 2 tables so far that keep failing, ContactLog and Content, what can I do?

For anyone who finds an error similar to this one, its the line "forcibly closed by the remote host" that was the most interesting. Well, found the solution here, in section 4.1.2, http://support.microsoft.com/kb/910228
Basically, SP1 for Win 2K3 includes a lovely feature to prevent DOS attacks, and rather cleverly it thinks SQL Server applying a snapshot is a DOS attack so closes the connection after a set amount of Connect/Disconnects. Jeebus wept. 1 simple registry key cost me my weekend :-|

Hopefully this will save someone the same heartache!

Keep up the good work guys
|||Hello Shane,

Did you find the solution to your problem if yes then please let me know also because i am also facing the same problem from last two weeks and i am not able to solve it and its causing a headache for me please tell me if u have the solution.
my email id is dr_hunaindurrani@.hotmail.com.

Thanks in advance.

Applying the snapshot for Merge rep fails everytime because Connection is reset?

Hi guys, Im desperately hoping someone here can help me. Ive been trying to set up merge replication between 2 servers all weekend and it keeps failing. Im setting this up as follows
The Publisher/Distributor is a SQL Server 2005 machine, the database being replicated is 4gb, and the only subscriber is a SQL Server 2000 SP4 machine. I set up my publication normally, and set up the push subscription, adn set it to initialize immediately. It weill then start bulk copying and go on for about 3-4 hours before it fails and gives me the errors:

Error messages:
The merge process was unable to deliver the snapshot to the Subscriber. If using Web synchronization, the merge process may have been unable to create or write to the message file. When troubleshooting, restart the synchronization with verbose history logging and specify an output file to which to write. (Source: MSSQL_REPL, Error number: MSSQL_REPL-2147201001)
Get help: http://help/MSSQL_REPL-2147201001
The process could not bulk copy into table '"dbo"."CONTENT"'. (Source: MSSQL_REPL, Error number: MSSQL_REPL20037)
Get help: http://help/MSSQL_REPL20037
An existing connection was forcibly closed by the remote host. (Source: MSSQLServer, Error number: 0)
Get help: http://help/0
One or more BLOB columns could not be sent to the server, attempt to recover from the problem failed. (Source: MSSQLServer, Error number: 0)
Get help: http://help/0
Communication link failure (Source: MSSQLServer, Error number: 0)
Get help: http://help/0
Unspecified error (Source: MSSQLServer, Error number: 0)
Get help: http://help/0
Failed to send batch after max errors (Source: MSSQLServer, Error number: 0)

This is driving me crazy as I havent slept in ages trying to get this fixed. Anyone have any idea whats going on? Its always one of 2 tables so far that keep failing, ContactLog and Content, what can I do?

For anyone who finds an error similar to this one, its the line "forcibly closed by the remote host" that was the most interesting. Well, found the solution here, in section 4.1.2, http://support.microsoft.com/kb/910228
Basically, SP1 for Win 2K3 includes a lovely feature to prevent DOS attacks, and rather cleverly it thinks SQL Server applying a snapshot is a DOS attack so closes the connection after a set amount of Connect/Disconnects. Jeebus wept. 1 simple registry key cost me my weekend :-|

Hopefully this will save someone the same heartache!

Keep up the good work guys
|||Hello Shane,

Did you find the solution to your problem if yes then please let me know also because i am also facing the same problem from last two weeks and i am not able to solve it and its causing a headache for me please tell me if u have the solution.
my email id is dr_hunaindurrani@.hotmail.com.

Thanks in advance.

Monday, March 19, 2012

applying snapshot from alternate location

Hi


We are using HTTPS merge replication - is it possible to specify an alternative location when applying the initial snapshot ?


Thanks
Bruce

yes, it's possible. Is it not working in your case?|||

I'm talking about where the subscriberType is anonymous if that helps...

Our setup is as follows...

subscription.CreateSyncAgentByDefault = False -- I wrote a windows service to synchronise
subscription.UseWebSynchronization = True
subscription.InternetSecurityMode = AuthenticationMethod.BasicAuthentication
subscription.SubscriberType = MergeSubscriberType.Anonymous

I can't see anything in the doco about specifying alternate snapshot location in this case (where subscription.SyncType = SubscriptionSyncType.None)

At the moment we are persisting with downloading the initial snapshot over the 'net - which for some of our clients in regional Australia takes forever - they are on horrible dial-up connections - it's the darkages in parts of this country !

So if I can download the initial snapshot locally to get them going it'll be a relief !

Thanks
Bruce

|||

Hi Bruce,

From your posts, I gather that you are using a no-sync subscription.

You can specify an alternate snapshot location. BOL has more info on that.

However in such a scenario, I do not see the need to download all the files because it is a no-sync subscription and need only few files. But due to a bug, we indeed do download all the files from the snapshot location.

So even if you do provide an alternate snapshot location, the files will still be downloaded even though all may not be applied.

I have seen this happen internally concurrently and I happened to read your post today.

I hope that we can fix it in the Service Pack 2 timeframe. Till then, you will have to bear ths burden of downloading the files.

applying snapshot from alternate location

Hi


We are using HTTPS merge replication - is it possible to specify an alternative location when applying the initial snapshot ?


Thanks
Bruce

yes, it's possible. Is it not working in your case?|||

I'm talking about where the subscriberType is anonymous if that helps...

Our setup is as follows...

subscription.CreateSyncAgentByDefault = False -- I wrote a windows service to synchronise
subscription.UseWebSynchronization = True
subscription.InternetSecurityMode = AuthenticationMethod.BasicAuthentication
subscription.SubscriberType = MergeSubscriberType.Anonymous

I can't see anything in the doco about specifying alternate snapshot location in this case (where subscription.SyncType = SubscriptionSyncType.None)

At the moment we are persisting with downloading the initial snapshot over the 'net - which for some of our clients in regional Australia takes forever - they are on horrible dial-up connections - it's the darkages in parts of this country !

So if I can download the initial snapshot locally to get them going it'll be a relief !

Thanks
Bruce

|||

Hi Bruce,

From your posts, I gather that you are using a no-sync subscription.

You can specify an alternate snapshot location. BOL has more info on that.

However in such a scenario, I do not see the need to download all the files because it is a no-sync subscription and need only few files. But due to a bug, we indeed do download all the files from the snapshot location.

So even if you do provide an alternate snapshot location, the files will still be downloaded even though all may not be applied.

I have seen this happen internally concurrently and I happened to read your post today.

I hope that we can fix it in the Service Pack 2 timeframe. Till then, you will have to bear ths burden of downloading the files.

Sunday, March 11, 2012

Apply ROWCOUNT on one Table in UNION

I have these two SELECTs in my SPROC... how can I merge the two tables
together so that my result is one table? UNION won't work as the
ROWCOUNTs are different, I can't use TOP as it's a sproc and you'll
notice I'm randomly sorting the top table and not the bottom. Thanks
for any help.
SET ROWCOUNT @.iNumRows
SELECT a.*
FROM tbl_1
WHERE badge = 0
ORDER BY NewID()
SET ROWCOUNT 100 PERCENT
SELECT a.*
FROM tbl_1
WHERE badge = @.iFilter
~Greg"Bac2Day1" <Bac2Day1@.gmail.com> wrote in message
news:1136411031.683766.39540@.g49g2000cwa.googlegroups.com...
>I have these two SELECTs in my SPROC... how can I merge the two tables
> together so that my result is one table? UNION won't work as the
> ROWCOUNTs are different, I can't use TOP as it's a sproc and you'll
> notice I'm randomly sorting the top table and not the bottom. Thanks
> for any help.
> SET ROWCOUNT @.iNumRows
> SELECT a.*
> FROM tbl_1
> WHERE badge = 0
> ORDER BY NewID()
> SET ROWCOUNT 100 PERCENT
> SELECT a.*
> FROM tbl_1
> WHERE badge = @.iFilter
>
> ~Greg
>
Please always state what version of SQL Server you are using. In SQL Server
2005 the following is possible:
DECLARE @.iNumRows INTEGER, @.iFilter INTEGER
SELECT x, badge
FROM
(SELECT TOP (@.inumrows) x, badge
FROM tbl_1 AS a
WHERE badge = 0
ORDER BY NEWID()
UNION ALL
SELECT x, badge
FROM tbl_1 AS a
WHERE badge = @.iFilter
) AS T ;
To do that in 2000 you would have to use dynamic SQL to construct the TOP
query because TOP doesn't otherwise allow a parameter for the number of
rows.
One alternative might be to insert the first result into a table variable
(use SET ROWCOUNT) and then UNION it with the second result. That would make
me slightly uneasy however, because the effect of ORDER BY in an INSERT
SELECT statement is buggy or at least poorly defined under some conditions.
Failing that I think I would opt for the dynamic query solution or combine
the result sets in the calling code rather than in the proc.
David Portas
SQL Server MVP
--|||>> In SQL Server 2005 the following is possible:
Is this a documented construct? To allow ORDER BY in the first SELECT seems
like an oversight, left unchecked in the parser.
Anith

Apply ROWCOUNT on one Table in UNION

I have these two SELECTs in my SPROC... how can I merge the two tables
together so that my result is one table? UNION won't work as the
ROWCOUNTs are different, I can't use TOP as it's a sproc and you'll
notice I'm randomly sorting the top table and not the bottom. Thanks
for any help.
SET ROWCOUNT @.iNumRows
SELECT a.*
FROM tbl_1
WHERE badge = 0
ORDER BY NewID()
SET ROWCOUNT 100 PERCENT
SELECT a.*
FROM tbl_1
WHERE badge = @.iFilter
~Greg
"Bac2Day1" <Bac2Day1@.gmail.com> wrote in message
news:1136411031.683766.39540@.g49g2000cwa.googlegro ups.com...
>I have these two SELECTs in my SPROC... how can I merge the two tables
> together so that my result is one table? UNION won't work as the
> ROWCOUNTs are different, I can't use TOP as it's a sproc and you'll
> notice I'm randomly sorting the top table and not the bottom. Thanks
> for any help.
> SET ROWCOUNT @.iNumRows
> SELECT a.*
> FROM tbl_1
> WHERE badge = 0
> ORDER BY NewID()
> SET ROWCOUNT 100 PERCENT
> SELECT a.*
> FROM tbl_1
> WHERE badge = @.iFilter
>
> ~Greg
>
Please always state what version of SQL Server you are using. In SQL Server
2005 the following is possible:
DECLARE @.iNumRows INTEGER, @.iFilter INTEGER
SELECT x, badge
FROM
(SELECT TOP (@.inumrows) x, badge
FROM tbl_1 AS a
WHERE badge = 0
ORDER BY NEWID()
UNION ALL
SELECT x, badge
FROM tbl_1 AS a
WHERE badge = @.iFilter
) AS T ;
To do that in 2000 you would have to use dynamic SQL to construct the TOP
query because TOP doesn't otherwise allow a parameter for the number of
rows.
One alternative might be to insert the first result into a table variable
(use SET ROWCOUNT) and then UNION it with the second result. That would make
me slightly uneasy however, because the effect of ORDER BY in an INSERT
SELECT statement is buggy or at least poorly defined under some conditions.
Failing that I think I would opt for the dynamic query solution or combine
the result sets in the calling code rather than in the proc.
David Portas
SQL Server MVP
|||>> In SQL Server 2005 the following is possible:
Is this a documented construct? To allow ORDER BY in the first SELECT seems
like an oversight, left unchecked in the parser.
Anith

Apply ROWCOUNT on one Table in UNION

I have these two SELECTs in my SPROC... how can I merge the two tables
together so that my result is one table? UNION won't work as the
ROWCOUNTs are different, I can't use TOP as it's a sproc and you'll
notice I'm randomly sorting the top table and not the bottom. Thanks
for any help.
SET ROWCOUNT @.iNumRows
SELECT a.*
FROM tbl_1
WHERE badge = 0
ORDER BY NewID()
SET ROWCOUNT 100 PERCENT
SELECT a.*
FROM tbl_1
WHERE badge = @.iFilter
~Greg"Bac2Day1" <Bac2Day1@.gmail.com> wrote in message
news:1136411031.683766.39540@.g49g2000cwa.googlegroups.com...
>I have these two SELECTs in my SPROC... how can I merge the two tables
> together so that my result is one table? UNION won't work as the
> ROWCOUNTs are different, I can't use TOP as it's a sproc and you'll
> notice I'm randomly sorting the top table and not the bottom. Thanks
> for any help.
> SET ROWCOUNT @.iNumRows
> SELECT a.*
> FROM tbl_1
> WHERE badge = 0
> ORDER BY NewID()
> SET ROWCOUNT 100 PERCENT
> SELECT a.*
> FROM tbl_1
> WHERE badge = @.iFilter
>
> ~Greg
>
Please always state what version of SQL Server you are using. In SQL Server
2005 the following is possible:
DECLARE @.iNumRows INTEGER, @.iFilter INTEGER
SELECT x, badge
FROM
(SELECT TOP (@.inumrows) x, badge
FROM tbl_1 AS a
WHERE badge = 0
ORDER BY NEWID()
UNION ALL
SELECT x, badge
FROM tbl_1 AS a
WHERE badge = @.iFilter
) AS T ;
To do that in 2000 you would have to use dynamic SQL to construct the TOP
query because TOP doesn't otherwise allow a parameter for the number of
rows.
One alternative might be to insert the first result into a table variable
(use SET ROWCOUNT) and then UNION it with the second result. That would make
me slightly uneasy however, because the effect of ORDER BY in an INSERT
SELECT statement is buggy or at least poorly defined under some conditions.
Failing that I think I would opt for the dynamic query solution or combine
the result sets in the calling code rather than in the proc.
--
David Portas
SQL Server MVP
--|||>> In SQL Server 2005 the following is possible:
Is this a documented construct? To allow ORDER BY in the first SELECT seems
like an oversight, left unchecked in the parser.
--
Anith

Saturday, February 25, 2012

Application is closed during second synchronization

My Merge Replication was working correctly till New Year.
The initial synchronization is always synchronous (I must have a
database in order to start my application) and the rest of them are
asynchronous. This scenarios was working perfectly.
Now, without making any changes, initial replication (copy of the whole
database) is correctly done, but subsequent replication calls fail, and
fail without giving any error! I've got a catch block where I display a
messagebox with the thrown exception but this code is never reached. An
aplication is completely closed without any error message.
What can be happening? It's really strange and very urgent. I promise
you this code was perfecty working before Christmas.
Ah! I've also tried making a synchronous replication second time, but
same thing occurs.I've deleted the local database, created again the
publication on the server.........
I would really appreciate any help on this. Thanks very much.
Can you successfully run the merge agent from SSMS? If not, is there any
message sent?
Cheers,
Paul Ibison SQL Server MVP, www.replicationanswers.com
(recommended sql server 2000 replication book:
http://www.nwsu.com/0974973602p.html)
|||I've now checked another thing: when I've already got a local database,
second, third, fourth and subsequent synchronizations are correctly
done, and they ar ein asynchronous mode.
The problems is starting the application for the first time, with no
database. Database is correctly downloaded first time, but second time,
my application exits without any error message.
Sorry for my poor SQL Server knowledge, but how do I run the Merge
Agent from Management Studio?
Really strange.......thanks for your help.
|||To start the merge agent in SQL Server 2000, open Enterprise Manager,
Replication Monitor, Expand the publication and on the RHS you'll see the
related agents. Right-clicking on it will allow you to start the agent. In
SSMS (SQL Server 2005) the process is similar, but Replication Monitor is a
separate application that is started by right-clicking the replication
folder.
Also, I proobably need a little more clarification about some of your
descriptions. You mention starting the application when you don't have a
local database. Does your application create a local database and then
create the publication, subscription and then initialize the subscription?
Also, you're using asychronous and synchronous processing - are you
referring to MSMQ, Service Broker or some such mechanism?
Cheers,
Paul Ibison SQL Server MVP, www.replicationanswers.com
(recommended sql server 2000 replication book:
http://www.nwsu.com/0974973602p.html)
|||I've been able to start the Merge Agent from SQL Server 2005 Management
Studio. Agent runs correctly.
Some clarifications:
I use always Merge Replication.
My application initially checks if there is a local database
(downloaded before maybe); if there is, the synchronization is
asynchronous because we have data to play with.
If there is no database, I make a synchronous call with Synchronize()
method and wait. Then, I again have got data to play with. Next calls
will also be asynchronous.
This is the merge replication code I'm using. Really simple:
private void CheckReplicationStatus(object sender, EventArgs e)
{
if (true)
{
try
{
ConfigureReplicationManager();
if (replicationManager !=3D null &&
systemCanReplicate)
{
replicationManager.HostName =3D userId;
// Check if the database file already exists
if
(!System.IO.File.Exists(Constants.DatabaseFilePath ))
{
// Add a new subscripton and create the
local database file
replicationManager.AddSubscription(AddOption.Creat eDatabase);
// La replicaci=F3n inicial es
necesariamente s=EDncrona ya que no existe la BD en local
replicationManager.Synchronize();
replicationManager.Dispose();
}
else
{
// Replicaci=F3n as=EDncrona
IAsyncResult ar =3D
replicationManager.BeginSynchronize(new
AsyncCallback(SyncCompletedCallback), replicationManager);
}
}
else // No ha sido capaz de leer los ficheros de
configuraci=F3n y no ha podido configurar la replicaci=F3n
{
// La idea es ver si la BD existe en el
dispositivo --> Se le deja continuar ejecutando la aplicaci=F3n
// pero se cancela la replicaci=F3n. Pero no hay
manera ya que el path de la BD est=E1 tambi=E9n en los ficheros de
configuraci=F3n
GeneralBehaviour.ShowErrorMessage(Properties.Resou rces.MasterForm_CannotRea=
dConfigurationFiles);
Application.Exit();
}
}
catch (Exception ex)
{
MessageBox.Show(ex.Message.ToUpper());
replicationManager.Dispose();
GeneralBehaviour.ShowErrorMessage(Properties.Resou rces.MasterForm_InitialSy=
nchronizationFailed);
// TODO: BORRAR LA BD YA QUE NO ES UNA BD OPERATIVA
Application.Exit();
}
}
}
/// <summary>
/// Evento que recoge los resultados de la sincronizaci=F3n
as=EDncrona
/// </summary>
/// <param name=3D"ar"></param>
public void SyncCompletedCallback(IAsyncResult ar)
{
try
{
SqlCeReplication repl =3D
(SqlCeReplication)ar.AsyncState;
replicationManager =3D (SqlCeReplication)ar.AsyncState;
replicationManager.EndSynchronize(ar);
}
catch (SqlCeException exc)
{
// Fallo en la sincronizaci=F3n as=EDncrona --> La
aplicaci=F3n sigue corriendo ya que tenemos BD en local
replicationManager.CancelSynchronize();
}
finally
{
replicationManager.Dispose();
}
}
This is all what I have Paul. Don't know what to do yet! It was working
and I'm spending my second day after a solution for this.
What do you think? Seems SQL Server's fault to me but cannot explain
why only fails second synchronization after first synchronization in
which I download all database.
Thanks for your time. Regards.
|||Hi again Paul,
I've tried to debug but I loose debugger when executing Synchronize()
method for the second time. I'm suffering this problem with the
debugger. It tells me:
"The remote connection to the device has been lost. Please verify the
device connection and restart debugging".
I saw a solution for this error on the internet and although I don't
know if it's related, I installed "Virtual Machine Network Driver for
Microsoft Device Emulator".
But debugger continues failing.
I don't know what else could I do. What frustrating is this situation!
Thanks.
|||If the merge agent can be successfully run in the case of the Synchronous
setup, then it seems to point to an application issue. Sorry, but
unfortunately I'm probably not the best to help in terms of debugging the C#
code (and debugging the debugger itself), so hopefully someone else can
continue the thread. If not, I'd recommend posting this in the C# newsgroup.
Cheers,
Paul Ibison SQL Server MVP, www.replicationanswers.com
(recommended sql server 2000 replication book:
http://www.nwsu.com/0974973602p.html)
|||Starting the application without database and debugging, first
synchronization is correctly done. Second one crashes again my
debugger.
Starting the application with the database downloaded in the first try,
first synchronization is again correct. Second crashes again my
debugger.
Thanks Paul for your interest. Don't know exactly how but I suddenly
received just before having lunch this error from the application:
"A call to SQL Server Reconciler failed. Try to resynchronize.; The
Subscriber's schema version information is inconsistent with the
Publisher's schema version information. It is likely that the Publisher
has been restored from a backup whose schema change version is
different from the Subscriber. Rerun the Snapshot agent and
reinitialize the subscriptions. The Publisher and Subscriber schema
guids and version are:
'FFE575BF-5368-41BE-A451-10723451634B',272,'892E72E7-962F-437A-9228-F757FED7ECB9',272
respectively.}"
I've never seen that error before but I understand deleting and
generating again the publication will solve it.
Thanks for your time.
|||Your schema versions do not match. If you reinitialize, it will clean this
up.
Mike
Mentor
Solid Quality Learning
http://www.solidqualitylearning.com
"Lonifasiko" <mloichate@.gmail.com> wrote in message
news:1136285094.858729.123150@.g49g2000cwa.googlegr oups.com...
I've been able to start the Merge Agent from SQL Server 2005 Management
Studio. Agent runs correctly.
Some clarifications:
I use always Merge Replication.
My application initially checks if there is a local database
(downloaded before maybe); if there is, the synchronization is
asynchronous because we have data to play with.
If there is no database, I make a synchronous call with Synchronize()
method and wait. Then, I again have got data to play with. Next calls
will also be asynchronous.
This is the merge replication code I'm using. Really simple:
private void CheckReplicationStatus(object sender, EventArgs e)
{
if (true)
{
try
{
ConfigureReplicationManager();
if (replicationManager != null &&
systemCanReplicate)
{
replicationManager.HostName = userId;
// Check if the database file already exists
if
(!System.IO.File.Exists(Constants.DatabaseFilePath ))
{
// Add a new subscripton and create the
local database file
replicationManager.AddSubscription(AddOption.Creat eDatabase);
// La replicacin inicial es
necesariamente sncrona ya que no existe la BD en local
replicationManager.Synchronize();
replicationManager.Dispose();
}
else
{
// Replicacin asncrona
IAsyncResult ar =
replicationManager.BeginSynchronize(new
AsyncCallback(SyncCompletedCallback), replicationManager);
}
}
else // No ha sido capaz de leer los ficheros de
configuracin y no ha podido configurar la replicacin
{
// La idea es ver si la BD existe en el
dispositivo --> Se le deja continuar ejecutando la aplicacin
// pero se cancela la replicacin. Pero no hay
manera ya que el path de la BD est tambin en los ficheros de
configuracin
GeneralBehaviour.ShowErrorMessage(Properties.Resou rces.MasterForm_CannotReadConfigurationFiles);
Application.Exit();
}
}
catch (Exception ex)
{
MessageBox.Show(ex.Message.ToUpper());
replicationManager.Dispose();
GeneralBehaviour.ShowErrorMessage(Properties.Resou rces.MasterForm_InitialSynchronizationFailed);
// TODO: BORRAR LA BD YA QUE NO ES UNA BD OPERATIVA
Application.Exit();
}
}
}
/// <summary>
/// Evento que recoge los resultados de la sincronizacin
asncrona
/// </summary>
/// <param name="ar"></param>
public void SyncCompletedCallback(IAsyncResult ar)
{
try
{
SqlCeReplication repl =
(SqlCeReplication)ar.AsyncState;
replicationManager = (SqlCeReplication)ar.AsyncState;
replicationManager.EndSynchronize(ar);
}
catch (SqlCeException exc)
{
// Fallo en la sincronizacin asncrona --> La
aplicacin sigue corriendo ya que tenemos BD en local
replicationManager.CancelSynchronize();
}
finally
{
replicationManager.Dispose();
}
}
This is all what I have Paul. Don't know what to do yet! It was working
and I'm spending my second day after a solution for this.
What do you think? Seems SQL Server's fault to me but cannot explain
why only fails second synchronization after first synchronization in
which I download all database.
Thanks for your time. Regards.

Sunday, February 19, 2012

Appending one datatable to another ?

Is the merge method, what will work in this case ? I have two datatables with the exact same structure. How can I append the rows from table 2 onto the bottom of table 1 ? Is looping through the rows collection the only way ?

You can use UNION ALL to join two tables all records with same structrure( watch for the identity issue). Like

Select col1, col2 From table1

UNION ALL

Select col1, col2 From table2

|||

DataTable dt1 = new DataTable();
DataTable dt2 = new DataTable();

dt1.Merge(dt2);

This will append dt2 to dt1

Append to Self-Join Table

I have 5 Self-Join Tables with the same structure
Table1
|--> SubjID
|--> ParentID
|--> SubjText
I want to merge my 5 tables in one table with the same structure without
lose my Tree which have many levels not only one, I need help plz?
On Sun, 6 Nov 2005 17:29:49 +0200, Islamegy wrote:

>I have 5 Self-Join Tables with the same structure
>Table1
>|--> SubjID
>|--> ParentID
>|--> SubjText
>I want to merge my 5 tables in one table with the same structure without
>lose my Tree which have many levels not only one, I need help plz?
>
Hi Islamegy,
I'm sorry, but I fail to understand your problem. Maybe it helps if you
follow up with a post that includes:
- Structure of your tables, posted as CREATE TABLE statements (including
all constraints and properties, but excluding irrelevant columns);
- Some rows of sample data to illustrate the situation (posted as INSERT
statements);
- Expected output.
Check out www.aspfaq.com/5006 too.
Best, Hugo
(Remove _NO_ and _SPAM_ to get my e-mail address)

Sunday, February 12, 2012

API for controlling replication?

Rather than having merge replication performed on a schedule, I need to
programmatically invoke it. Is this possible, and where can I find
documentation about how to do it?
David
That depends on what you are trying to accomplish.
Some people use Windows Synchronization Manager which can be run on users
laptops. It is a little difficult to deploy and doesn't really support SQL
Authentication (it does, but the user will be prompted to enter the password
each time, which makes it impractical). It has limited scheduling.
Then there is the replication activeX controls, which is great, however you
will have to code your own scheduler here. Another problem with it and WSM
is that you can't set many of the properties on the agents.
WSM and ActiveX controls do support Interactive Conflict resolution.
Finally you can use ado to run sp_startjob, which may be your best option as
it is feature rich..
Hilary Cotter
Looking for a SQL Server replication book?
http://www.nwsu.com/0974973602.html
Looking for a FAQ on Indexing Services/SQL FTS
http://www.indexserverfaq.com
"David" <David@.discussions.microsoft.com> wrote in message
news:4E8C6EAB-D8E2-4A30-A393-49D9E8786AAE@.microsoft.com...
> Rather than having merge replication performed on a schedule, I need to
> programmatically invoke it. Is this possible, and where can I find
> documentation about how to do it?
> David
>