Showing posts with label correctly. Show all posts
Showing posts with label correctly. Show all posts

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.

Friday, February 24, 2012

Appending Stored Procedure

I need to make sure I'm doing this correctly can you help me out guys please?? This is an Appending Stored procedure it should move values from the EmployeeGamingLicense table when the status is turned into TERMINATED to the GCEmployeeTerms table. Heres what I have so far, having problems with the rest of the script getting errors

CREATE PROCEDURE [insert_GCEmployeeTerms_1]
(@.TM_#_1 [int],
@.FirstName_2 [nvarchar](50),
@.LastName_3 [nvarchar](50),
@.SocialSecurityNumber_4 [int],
@.DateHired_5 [datetime],
@.Status_6 [nvarchar](50),
@.TerminationDate_7 [datetime],
@.Title_8 [nvarchar](50),
@.DepartmentName_9 [nvarchar](50),
@.TermReason_10 [ntext],
@.VoluntaryInvoluntary_11 [nvarchar](50))

AS INSERT INTO [CommissionEmployee_Exclusionsdb].[dbo].[GCEmployeeTerms]
( [TM #],
[FirstName],
[LastName],
[SocialSecurityNumber],
[DateHired],
[Status],
[TerminationDate],
[Title],
[DepartmentName],
[TermReason],
[VoluntaryInvoluntary])

SELECT
( @.TM_#,
@.FirstName,
@.LastName,
@.SocialSecurityNumber,
@.DateHired,
@.Status,
@.TerminationDate,
@.Title,
@.DepartmentName,
@.TermReason,
@.VoluntaryInvoluntary)
FROM EmployeeGamingLicense
WHERE STATUS = 'TERMINATED'
GOMethinks thou wants not both tables and variables in yon SELECT list. There be dragons in that mix!

-PatP|||Thank You pat for that very old English/shakesperan/King Arthur answer..lol. Let me see if I interpreted that correctly...Your saying that my select list is incorrect, refering of both tables...I need to go look it up..sorry this is my first append stored procedure.|||If you stop and think about it, you are passing a whole flock (that would be a really technical term, eh?) of parameters to the procedure. This would be a good thing if you wanted to insert those parameters one time. You are also using a table with a where clause, which would be a good thing if you wanted to insert columns from that table for every row that qualified. However, doing both means that you want to insert one copy of the parameters that you are passing for every row that qualifies... Which is probably NOT what you intended!

You probably want to either use the table with column names, or the parameters without the table, but only one or the other!

-PatP|||I'm just being nosy now, but did you ever get this one sorted out to your satisfaction?

-PatP|||Sniff Sniff Sniff ...No :(

I just want to insert data from one table to another automatically through stored procedures. I can make part of the procedure (that Inserts), need to tell it to pull from another table...I dont know, keep getting errors its like a puzzle I can only get part of it but not all (Banging head against wall)|||a whole flock of parameters

Pat. I thought it was a bevy of parameters. Hmm. May need to add it to the lists...

http://encyclopedia.thefreedictionary.com/List%20of%20collective%20nouns%20by%20collective%2 0term%20A-K|||ok so your saying its just a bunch of parameters..a horde of parameters|||Sniff Sniff Sniff ...No :(Now, now M'Dear! You musn't get too upset. Might I suggest trying something like:CREATE PROCEDURE [insert_GCEmployeeTerms_1]
AS

INSERT INTO [CommissionEmployee_Exclusionsdb].[dbo].[GCEmployeeTerms] (
[TM #], [FirstName], [LastName]
, [SocialSecurityNumber], [DateHired], [Status]
, [TerminationDate], [Title], [DepartmentName]
, [TermReason], [VoluntaryInvoluntary]
) SELECT
a.TM_#, a.FirstName, a.LastName
, a.SocialSecurityNumber, a.DateHired, a.Status
, a.TerminationDate, a.Title, a.DepartmentName
, a.TermReason, a.VoluntaryInvoluntary)
FROM EmployeeGamingLicense AS a
WHERE a.STATUS = 'TERMINATED'

RETURN
GO-PatP|||I did what you said pat I got some Errors but what you put up gave me a great start I was not Referring to the Table.Fields that will do the inserting for me Fields in that Table are not exactly the same..(the column names) OK I GET IT A LIGHT HAS GONE OFF AND I TOTALLY GET IT NOW..Now I see why SQL was like WHAT THE HELL ARE YOU TALKING ABOUT..OMG I Die a Happy Woman now...Thank you so much Pat Your Truly a SQL GOD..I totally Get it now. :)

THANK YOU|||and Mccowley was correct I see his point now|||Now that you grok (http://searchsmallbizit.techtarget.com/sDefinition/0,,sid44_gci212216,00.html) how this works, you'll need to think a bit about how to limit the carnage. You won't always want to turn that procedure loose to copy every terminated employee row, or you'll end up with a gazillion copies of each row in GCEmployeeTerms (one for every time the procedure is run while that terminated row is present), which probably isn't what you want!

-PatP|||Ok...what happens is our dept gets a list of terminated employees, so when we get this list we go to the [GamingCommissiondb].[dbo].[EmployeeGamingLicense] which is the active table look up the employee and change their status to 'TERMINATED'. Now there can be as much as 20-30 terminations. The Stored Procedure will then take those employees that have been changed to Terminated and APPEND (Insert) them into the TERMINATION.tbl. One of the purposes of doing this is if the employee comes back as a rehire we can check to see if there was any negative action taken against their gaming license. Does that make sense??|||Oh heavens yes, but unless you delete the row from the active table when this happens, that row will be copied every time the procedure runs (at least as it is written right now). The only criteria that you are using to select rows is if they are flagged as terminated... You might want to be a wee bit more selective than that, maybe throwing in a test on the termination date or something wild and crazy like that!

-PatP|||I understand what your saying, I dont want my users to delete a record in error so I didnt want to delet the record from the active table through the stored procedure. I have a view that shows only the terminated employees from the active table that I look at everyone 2 weeks, just a QC thing. also both the tables have the TM# as a primary key, the first time I tried to execute the stored procedure I got "Pk constraint error duplicates"..something like that, so once I found out what records had already been appended to the TERMINATION table and which ones had not been the SP executed successfully. Does that make sense?|||Yep, that it does. You could also use a WHERE NOT EXISTS clause to test for the presence of the TM# while you were doing the INSERT operation. This might be simpler.

-PatP|||Yes your absolutely right, I'll alter the procedure then thank you again for your help Pat I sure do appreciate it :)