同步后删除行,但不将这些删除传递给服务器 [英] Deleting rows after sync, but not passing those deletes to the server

查看:107
本文介绍了同步后删除行,但不将这些删除传递给服务器的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一种情况,我在移动设备上收集信息(SQLCE 3.5),然后通过同步服务将数据上传到SQL2005服务器。


我想要能够删除设备上传后捕获的一些数据,但在此之后我不希望在下次同步时将删除发送到服务器。


I尝试通过覆盖SqlCeClientSyncAdapter的SetTableSentAnchor方法然后在调用接受更改之前在表上运行删除来实现此目的...

 public override void SetTableSentAnchor(string tableName,SyncAnchor anchor){

if(!this.preventRecursion){

try {

//电话下面的AcceptChanges将导致递归
//重新进入此方法。此变量用于在需要时跟踪
//重新进入和回退到基本功能。

this.preventRecursion = true;

//我们是否需要对所选表做任何特别的事情?

string [] transientTableNames = null;
switch(tableName){

case" tablename1":
case" tablename2":
transientTableNames = new string [] {tableName};
休息;

默认值:
break;

}

if(transientTableNames == null){

//不需要清除发送的表。
base.SetTableSentAnchor(tableName,anchor);

}
else {

//现在应该清除已经发送的表,
//可能还有其他已计算的表... 。

使用(SqlCeCommand command = new SqlCeCommand()){

command.CommandType = CommandType.Text;
command.Connection = this.Connection as SqlCeConnection;

foreach(transientTableNames中的字符串transientTableName){
command.CommandText = string.Format(@" delete from [{0}]",transientTableName);
command.ExecuteNonQuery();
}

base.AcceptChanges(tableName);

}

}

}
catch {

throw;

}
finally {

//我们已经完成,任何进一步的调用都不会导致
//通过递归重新进入...

this.preventRecursion = false;

}

}
else {

//这是由上面的AcceptChanges调用导致的重新输入,
//所以简单地将它传递回基本功能...

base.SetTableSentAnchor(tableName,anchor);

}

}

 


this然而,似乎并不总是有用。


任何人都可以推荐另一种方法来实现这一目标吗?我需要删除数据,否则它将继续在设备上继续增长。


谢谢。

解决方案

< blockquote>您是否尝试拦截GetChanges()中的更改数据集,然后循环访问数据集并删除已删除的行以便不上传?


I have a situation whereby I am collecting information on a mobile device (SQLCE 3.5) and then uploading that data to an SQL2005 server via synchronisation services.

I want to be able to delete some of the data captured on the device once it has been uploaded, but after this I do not want the deletion to be sent to the server on the next synchronisation.

I have attempted to acheive this by overriding the SetTableSentAnchor method of the SqlCeClientSyncAdapter and then running a delete on the table before the accept changes is called as follows...

public override void SetTableSentAnchor(string tableName, SyncAnchor anchor) {

	if (!this.preventRecursion) {

		try {

			// The call below to AcceptChanges will result in a recursive
			// re-entry to this method. This variable is used to track that
			// re-entry and fallback to base functionality when required.

			this.preventRecursion = true;

			// Do we need to do anything special with the selected table?

			string[] transientTableNames = null;
			switch (tableName) {

				case "tablename1":
				case "tablename2":
					transientTableNames = new string[] { tableName };
					break;

				default:
					break;

			}

			if (transientTableNames == null) {

				// The table that was sent does not need to be cleared.
				base.SetTableSentAnchor(tableName, anchor);

			}
			else {

				// The table that has been sent should now be cleared,
				// possibly along with other retlated tables...

				using (SqlCeCommand command = new SqlCeCommand()) {

					command.CommandType = CommandType.Text;
					command.Connection = this.Connection as SqlCeConnection;

					foreach (string transientTableName in transientTableNames) {
						command.CommandText = string.Format(@"delete from [{0}]", transientTableName);
						command.ExecuteNonQuery();
					}

					base.AcceptChanges(tableName);

				}

			}

		}
		catch {

			throw;

		}
		finally {

			// We have finished, any further call will not be caused
			// by recursive re-entry...

			this.preventRecursion = false;

		}

	}
	else {

		// This is a re-entry caused by the call to AcceptChanges above,
		// so simply pass it back to the base functionality...

		base.SetTableSentAnchor(tableName, anchor);

	}

}

 

this however does not always seem to work.

Can anybody recommend another way to acheive this? I need to delete the data as otherwise it will simply continue to grow on the device.

Thanks.

解决方案

have you tried intercepting the change dataset in GetChanges(), then loop thru the dataset and remove the deleted rows so they dont get uploaded?


这篇关于同步后删除行,但不将这些删除传递给服务器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆