예제 #1
0
 internal static void ExecuteNonQueryWithNewTransaction(IDbCommand command)
 {
     for (int index = 0; index < 6; ++index)
     {
         try
         {
             if (index > 0)
             {
                 SyncTracer.Info("Retrying SyncUtil.ExecuteNonQueryWithNewTransaction, attempt {0} of {1}.", new object[2]
                 {
                     (object)index,
                     (object)5
                 });
                 SyncUtil.OpenConnection(command.Connection);
             }
             using (IDbTransaction dbTransaction = command.Connection.BeginTransaction())
             {
                 command.Transaction = dbTransaction;
                 command.ExecuteNonQuery();
                 dbTransaction.Commit();
                 break;
             }
         }
         catch (DbException ex)
         {
             if (index == 5)
             {
                 SyncTracer.Error("SyncUtil.ExecuteNonQueryWithNewTransaction failed after max retry attempts, due to exception: {0}", new object[1]
                 {
                     (object)ex.Message
                 });
                 throw;
             }
             else
             {
                 SyncTracer.Warning("SyncUtil.ExecuteNonQueryWithNewTransaction failed on attempt {0} of {1}, due to retryable exception: {2}", (object)index, (object)5, (object)ex.Message);
                 Thread.Sleep(100 * (int)Math.Pow(2.0, (double)index));
             }
         }
     }
 }
예제 #2
0
        /// <summary>
        /// Populates the schema information for the table that is specified in <see cref="P:Microsoft.Synchronization.Data.Server.SyncAdapter.TableName"/>.
        /// </summary>
        ///
        /// <returns>
        /// A <see cref="T:System.Data.DataTable"/> that contains the schema information.
        /// </returns>
        /// <param name="dataTable">The <see cref="T:System.Data.DataTable"/> to be populated with schema information.</param><param name="connection">An <see cref="T:System.Data.IDbConnection"/> object that is used to connect to the server database.</param><exception cref="T:System.ArgumentNullException"><paramref name="connection"/> is a null.</exception><exception cref="T:Microsoft.Synchronization.Data.SchemaException"><see cref="P:Microsoft.Synchronization.Data.Server.SyncAdapter.SelectIncrementalInsertsCommand"/> or <see cref="P:Microsoft.Synchronization.Data.Server.SyncAdapter.SelectIncrementalUpdatesCommand"/>  is a null, or the schema could not be retrieved.</exception>
        public DataTable FillSchema(DataTable dataTable, IDbConnection connection)
        {
            SyncExpt.CheckArgumentNull((object)connection, "connection");
            bool flag = SyncUtil.OpenConnection(connection);

            if (this.SelectIncrementalInsertsCommand == null && this.SelectIncrementalUpdatesCommand == null)
            {
                throw SyncExpt.MissingSelectStatementError(this.TableName, "ServerSyncProvider", "http://www.microsoft.com/sql/");
            }
            IDbCommand cmd = this.SelectIncrementalInsertsCommand == null ? this.SelectIncrementalUpdatesCommand : this.SelectIncrementalInsertsCommand;

            SetDummySessionParameters(cmd);
            cmd.Connection = connection;
            SyncDbAdapter syncDbAdapter = new SyncDbAdapter();

            syncDbAdapter.SelectCommand = (DbCommand)cmd;
            if (dataTable == null)
            {
                dataTable        = new DataTable();
                dataTable.Locale = CultureInfo.InvariantCulture;
            }
            syncDbAdapter.FillSchema(dataTable, SchemaType.Source);
            IDataReader dataReader = cmd.ExecuteReader(CommandBehavior.SchemaOnly | CommandBehavior.KeyInfo);

            try
            {
                DataTable schemaTable = dataReader.GetSchemaTable();
                if (schemaTable == null)
                {
                    throw SyncExpt.FillSchemaError(dataTable.TableName, "ServerSyncProvider", "http://www.microsoft.com/sql/", (Exception)null);
                }
                if (schemaTable.Columns.Contains("DataTypeName"))
                {
                    foreach (DataRow dataRow in (InternalDataCollectionBase)schemaTable.Rows)
                    {
                        string name = (string)dataRow["ColumnName"];
                        if (dataTable.Columns.Contains(name))
                        {
                            DataColumn column = dataTable.Columns[name];
                            if (column != null)
                            {
                                object obj1 = dataRow["DataTypeName"];
                                if (obj1 != null)
                                {
                                    SetDataColumnExtendedProperty(column, "DataTypeName", (object)obj1.ToString());
                                }
                                if (column.DataType.Equals(Type.GetType("System.Decimal")))
                                {
                                    object obj2 = dataRow["NumericPrecision"];
                                    if (obj2 != null)
                                    {
                                        SetDataColumnExtendedProperty(column, "NumericPrecision", obj2);
                                    }
                                    object obj3 = dataRow["NumericScale"];
                                    if (obj3 != null)
                                    {
                                        SetDataColumnExtendedProperty(column, "NumericScale", obj3);
                                    }
                                }
                                object obj4 = dataRow["ColumnSize"];
                                if (obj4 != null)
                                {
                                    if ((int.MaxValue == (int)obj4 || 1073741823 == (int)obj4) && (column.DataType.Equals(Type.GetType("System.String")) || column.DataType.Equals(Type.GetType("System.Byte[]"))))
                                    {
                                        SetDataColumnExtendedProperty(column, "ColumnLength", (object)-1);
                                    }
                                    else
                                    {
                                        SetDataColumnExtendedProperty(column, "ColumnLength", obj4);
                                    }
                                }
                            }
                        }
                    }
                }
            }
            catch (DbException ex)
            {
                throw SyncExpt.FillSchemaError(dataTable.TableName, "ServerSyncProvider", "http://www.microsoft.com/sql/", (Exception)ex);
            }
            finally
            {
                dataReader.Close();
            }
            if (flag)
            {
                connection.Close();
            }
            this.MapFromServerToClient(dataTable);
            return(dataTable);
        }