Exemplo n.º 1
0
 /// <summary>
 /// Commits the changes made to the state of the database during the current save point
 /// and migrates them to the previous save point. If the outermost save point is committed
 /// then the changes made during that save point will be committed to the state of the
 /// database and the session will exit the transaction.
 /// </summary>
 /// <param name="sesid">The session to commit the transaction for.</param>
 /// <param name="grbit">Commit options.</param>
 /// <param name="durableCommit">Duration to commit lazy transaction.</param>
 /// <param name="commitId">Commit-id associated with this commit record.</param>
 public static void JetCommitTransaction2(
     JET_SESID sesid,
     CommitTransactionGrbit grbit,
     TimeSpan durableCommit,
     out JET_COMMIT_ID commitId)
 {
     Api.Check(Api.Impl.JetCommitTransaction2(sesid, grbit, durableCommit, out commitId));
 }
        /// <summary>
        /// The proxy callback function to call the user-defined managed delegate.
        /// </summary>
        /// <param name="instance">
        /// The instance.
        /// </param>
        /// <param name="commitIdSeen">
        /// The commit-id flushed.
        /// </param>
        /// <param name="grbit">
        /// Reserved currently.
        /// </param>
        /// <returns>
        /// An error code.
        /// </returns>
        private JET_err NativeDurableCommitCallback(
            IntPtr instance,
            ref NATIVE_COMMIT_ID commitIdSeen,
            uint grbit)
        {
            RuntimeHelpers.PrepareConstrainedRegions();
            try
            {
                JET_INSTANCE jetInstance = new JET_INSTANCE()
                {
                    Value = instance
                };

                if (this.instance != jetInstance)
                {
                    // We assume it's only called on one instance at a time. The only thing
                    // we really care about is serialization of the byte array.
                    //
                    // It would be nice to throw an error, but we're going back to real
                    // code, which doesn't deal with managed exceptions well.
                    return(JET_err.CallbackFailed);
                }

                JET_COMMIT_ID commitId = new JET_COMMIT_ID(commitIdSeen);

                return(this.wrappedCallback(jetInstance, commitId, (DurableCommitCallbackGrbit)grbit));
            }
            catch (Exception ex)
            {
                Trace.WriteLineIf(
                    TraceSwitch.TraceWarning, string.Format(CultureInfo.InvariantCulture, "Caught Exception {0}", ex));

                JetApi.ReportUnhandledException(ex, "Unhandled exception during NativeDurableCommitCallback");

                // This should never be executed, but the compiler doesn't know it.
                return(JET_err.CallbackFailed);
            }
        }