/// <summary>
/// Get the local Datetime for last succesful synchronization
/// If no Synchronization has happened, will return DateTime.MinValue
/// </summary>
/// <param name="connection">An open connection to the local database</param>
/// <returns>The date and time for the last succesful sync</returns>
public DateTime GetLastSuccessfulSyncTime(SqlCeConnection connection)
{
if (!System.IO.File.Exists(connection.Database))
return DateTime.MinValue;
if (connection.State != System.Data.ConnectionState.Open)
{
connection.Open();
}
var props = GetPropertiesFromSettings();
using (SqlCeCommand cmd = connection.CreateCommand())
{
cmd.Connection = connection;
cmd.CommandText = "SELECT table_name FROM information_schema.tables WHERE TABLE_NAME = @table";
cmd.Parameters.Add("@table", SqlDbType.NVarChar, 4000);
cmd.Parameters["@table"].Value = "__sysMergeSubscriptions";
object obj = cmd.ExecuteScalar();
if (obj == null)
return DateTime.MinValue;
cmd.Parameters.Clear();
cmd.CommandText = "SELECT LastSuccessfulSync FROM __sysMergeSubscriptions " +
"WHERE [email protected] AND [email protected] AND [email protected]";
cmd.Parameters.Add("@publisher", SqlDbType.NVarChar, 4000);
cmd.Parameters["@publisher"].Value = props.Publisher;
cmd.Parameters.Add("@database", SqlDbType.NVarChar, 4000);
cmd.Parameters["@database"].Value = props.PublisherDatabase;
cmd.Parameters.Add("@publication", SqlDbType.NVarChar, 4000);
cmd.Parameters["@publication"].Value = props.Publication;
obj = cmd.ExecuteScalar();
if (obj == null)
return DateTime.MinValue;
else
return ((DateTime)obj);
}
}
パーフェクト!あなたの助けてくれてありがとう。 – hydev