Exemplo n.º 1
0
        /// <summary>
        /// Create an instance and get the current version of Esent.
        /// </summary>
        /// <returns>The current version of Esent.</returns>
        private uint GetVersionFromEsent()
        {
#if MANAGEDESENT_ON_WSA
            // JetGetVersion isn't available in new Windows user interface, so we'll pretend it's always Win8:
            return(8250 << 8);
#else
            // Create a unique name so that multiple threads can call this simultaneously.
            // This can happen if there are multiple AppDomains.
            string       instanceName = string.Format(CultureInfo.InvariantCulture, "GettingEsentVersion{0}", LibraryHelpers.GetCurrentManagedThreadId());
            JET_INSTANCE instance     = JET_INSTANCE.Nil;
            RuntimeHelpers.PrepareConstrainedRegions();
            try
            {
                this.JetCreateInstance(out instance, instanceName);
                this.JetSetSystemParameter(instance, JET_SESID.Nil, JET_param.Recovery, new IntPtr(0), "off");
                this.JetSetSystemParameter(instance, JET_SESID.Nil, JET_param.NoInformationEvent, new IntPtr(1), null);
                this.JetSetSystemParameter(instance, JET_SESID.Nil, JET_param.MaxTemporaryTables, new IntPtr(0), null);
                this.JetSetSystemParameter(instance, JET_SESID.Nil, JET_param.MaxCursors, new IntPtr(16), null);
                this.JetSetSystemParameter(instance, JET_SESID.Nil, JET_param.MaxOpenTables, new IntPtr(16), null);
                this.JetSetSystemParameter(instance, JET_SESID.Nil, JET_param.MaxVerPages, new IntPtr(4), null);
                this.JetSetSystemParameter(instance, JET_SESID.Nil, JET_param.MaxSessions, new IntPtr(1), null);
                this.JetInit(ref instance);

                JET_SESID sesid;
                this.JetBeginSession(instance, out sesid, string.Empty, string.Empty);
                try
                {
                    uint version;
                    this.JetGetVersion(sesid, out version);
                    return(version);
                }
                finally
                {
                    this.JetEndSession(sesid, EndSessionGrbit.None);
                }
            }
            finally
            {
                if (JET_INSTANCE.Nil != instance)
                {
                    this.JetTerm(instance);
                }
            }
#endif
        }