private int GetApplicationID(AccessConnectionHolder holder)
        {
            if (_applicationID != 0 && holder.CreateDate < _applicationIDCacheDate)
            {
                return _applicationID;
            }

            string appName = ApplicationName;
            if (appName.Length > MaxStringLength)
            {
                appName = appName.Substring(0, MaxStringLength);
            }

            _applicationID = AccessConnectionHelper.GetApplicationID(holder.Connection, appName, true);
            _applicationIDCacheDate = DateTime.Now;

            if (_applicationID == 0)
            {
                throw new ProviderException("Failed to get ApplicationID");
            }

            return _applicationID;
        }
예제 #2
0
 /////////////////////////////////////////////////////////////////////////////
 /////////////////////////////////////////////////////////////////////////////
 private int GetAppplicationId(AccessConnectionHolder holder)
 {
     if (_ApplicationId != 0 && holder.CreateDate < _ApplicationIDCacheDate) // Already cached?
         return _ApplicationId;
     string appName = _AppName;
     if (appName.Length > 255)
         appName = appName.Substring(0, 255);
     _ApplicationId = AccessConnectionHelper.GetApplicationID(holder.Connection, appName, true);
     _ApplicationIDCacheDate = DateTime.Now;
     if (_ApplicationId != 0)
         return _ApplicationId;
     throw new ProviderException(GetExceptionText(20));
 }
        /////////////////////////////////////////////////////////////////////////////
        /////////////////////////////////////////////////////////////////////////////
        private bool DeleteProfile(AccessConnectionHolder holder, string username, int appId)
        {
            SecUtility.CheckParameter(ref username, true, true, true, 255, "username");

            int userId = AccessConnectionHelper.GetUserID(holder.Connection, appId, username, false);
            if (userId == 0)
                return false;
            OleDbCommand cmd = new OleDbCommand(@"DELETE FROM aspnet_Profile WHERE UserId = @UserId", holder.Connection);
            cmd.Parameters.Add(new OleDbParameter("@UserId", userId));
            return (cmd.ExecuteNonQuery() != 0);
        }
예제 #4
0
        /////////////////////////////////////////////////////////////////////////////
        /////////////////////////////////////////////////////////////////////////////
        internal static Exception GetBetterException(Exception e, AccessConnectionHolder holder)
        {
            try
            {
                if (!(e is OleDbException) || holder.Connection == null ||
                    holder.Connection.DataSource == null || holder.Connection.DataSource.Length < 1)
                {
                    return e;
                }
                if (!File.Exists(holder.Connection.DataSource))
                {
                    return new FileNotFoundException(String.Empty, holder.Connection.DataSource, e);
                }
            }
            finally
            {
                if (holder.Connection != null)
                    holder.Connection.Close();
            }

            FileStream s = null;
            Exception eWrite = null;
            try
            {
                s = File.OpenWrite(holder.Connection.DataSource);
            }
            catch (Exception except)
            {
                eWrite = except;
            }
            finally
            {
                if (s != null)
                    s.Close();
            }
            if (eWrite != null && (eWrite is UnauthorizedAccessException))
            {
                HttpContext context = HttpContext.Current;
                if (context != null)
                {
                    context.Response.Clear();
                    context.Response.StatusCode = 500;
                    context.Response.Write("Cannot write to DB File");
                    context.Response.End();
                }
                return new Exception("AccessFile is not writtable", eWrite);
            }
            return e;
        }