1ALTER PROCEDURE dbo.aspnet_Profile_DeleteInactiveProfiles
2 @ApplicationName NVARCHAR(256),
3 @ProfileAuthOptions INT,
4 @InactiveSinceDate DATETIME,
5 @TimeZoneAdjustment INT
6AS
7BEGIN
8 DECLARE @ApplicationId UNIQUEIDENTIFIER
9 SELECT @ApplicationId = NULL
10 SELECT @ApplicationId = ApplicationId FROM aspnet_Applications WHERE LOWER(@ApplicationName) = LoweredApplicationName
11 ---查询应用程序ID
12 IF (@ApplicationId IS NULL)
13 BEGIN
14 SELECT 0
15 RETURN
16 END
17
18 IF (@InactiveSinceDate > CONVERT(DATETIME, '17540101', 112) AND @InactiveSinceDate < CONVERT(DATETIME, '99980101', 112))
19 --如果停滞以来的时间在系统时间内(目前是不会超过条件的时间的)
20 SELECT @InactiveSinceDate = DATEADD(n, -@TimeZoneAdjustment, @InactiveSinceDate)
21
22 DELETE
23 FROM dbo.aspnet_Profile
24 WHERE UserId IN
25 ( SELECT UserId
26 FROM dbo.aspnet_Users u
27 WHERE ApplicationId = @ApplicationId
28 AND (LastActivityDate <= @InactiveSinceDate)
29 AND (
30 (@ProfileAuthOptions = 2)
31 OR (@ProfileAuthOptions = 0 AND IsAnonymous = 1)
32 OR (@ProfileAuthOptions = 1 AND IsAnonymous = 0)
33 )
34 )
35 ---删除USERID在这一范围内的记录
36 SELECT @@ROWCOUNT
37END
2 @ApplicationName NVARCHAR(256),
3 @ProfileAuthOptions INT,
4 @InactiveSinceDate DATETIME,
5 @TimeZoneAdjustment INT
6AS
7BEGIN
8 DECLARE @ApplicationId UNIQUEIDENTIFIER
9 SELECT @ApplicationId = NULL
10 SELECT @ApplicationId = ApplicationId FROM aspnet_Applications WHERE LOWER(@ApplicationName) = LoweredApplicationName
11 ---查询应用程序ID
12 IF (@ApplicationId IS NULL)
13 BEGIN
14 SELECT 0
15 RETURN
16 END
17
18 IF (@InactiveSinceDate > CONVERT(DATETIME, '17540101', 112) AND @InactiveSinceDate < CONVERT(DATETIME, '99980101', 112))
19 --如果停滞以来的时间在系统时间内(目前是不会超过条件的时间的)
20 SELECT @InactiveSinceDate = DATEADD(n, -@TimeZoneAdjustment, @InactiveSinceDate)
21
22 DELETE
23 FROM dbo.aspnet_Profile
24 WHERE UserId IN
25 ( SELECT UserId
26 FROM dbo.aspnet_Users u
27 WHERE ApplicationId = @ApplicationId
28 AND (LastActivityDate <= @InactiveSinceDate)
29 AND (
30 (@ProfileAuthOptions = 2)
31 OR (@ProfileAuthOptions = 0 AND IsAnonymous = 1)
32 OR (@ProfileAuthOptions = 1 AND IsAnonymous = 0)
33 )
34 )
35 ---删除USERID在这一范围内的记录
36 SELECT @@ROWCOUNT
37END