1
ALTER PROCEDURE dbo.aspnet_Membership_UpdateLastLoginAndActivityDates --更新最近登陆和活跃时间
2
@ApplicationName NVARCHAR(256),
3
@UserName NVARCHAR(256),
4
@TimeZoneAdjustment INT
5
AS
6
BEGIN
7
DECLARE @UserId UNIQUEIDENTIFIER
8
SELECT @UserId = NULL
9
SELECT @UserId = u.UserId
10
FROM dbo.aspnet_Membership m, dbo.aspnet_Users u, dbo.aspnet_Applications a
11
WHERE LoweredUserName = LOWER(@UserName) AND
12
u.ApplicationId = a.ApplicationId AND
13
LOWER(@ApplicationName) = a.LoweredApplicationName AND
14
u.UserId = m.UserId
15
---查询符合条件的用户ID(就是用户名=@UserName的)
16
17
IF (@UserId IS NULL) --如果不存在,返回
18
BEGIN
19
RETURN
20
END
21![](/Images/OutliningIndicators/None.gif)
22
DECLARE @TranStarted BIT
23
SET @TranStarted = 0
24![](/Images/OutliningIndicators/None.gif)
25
IF( @@TRANCOUNT = 0 ) --如果当前活动事务为0,开始事务,设置事务参数为1
26
BEGIN
27
BEGIN TRANSACTION
28
SET @TranStarted = 1
29
END
30
ELSE
31
SET @TranStarted = 0
32![](/Images/OutliningIndicators/None.gif)
33
DECLARE @DateTimeNowUTC DATETIME --声明并获取当前时间
34
EXEC dbo.aspnet_GetUtcDate @TimeZoneAdjustment, @DateTimeNowUTC OUTPUT
35![](/Images/OutliningIndicators/None.gif)
36
UPDATE dbo.aspnet_Membership
37
SET LastLoginDate = @DateTimeNowUTC
38
WHERE UserId = @UserId ---更新此用户的最近登陆时间
39
40
IF( @@ERROR <> 0 ) --如果有错误,回滚
41
GOTO Cleanup
42![](/Images/OutliningIndicators/None.gif)
43
UPDATE dbo.aspnet_Users
44
SET LastActivityDate = @DateTimeNowUTC
45
WHERE @UserId = UserId ----更新此用户的最近活跃时间
46![](/Images/OutliningIndicators/None.gif)
47
IF( @@ERROR <> 0 ) --如果有错误,回滚
48
GOTO Cleanup
49![](/Images/OutliningIndicators/None.gif)
50
IF( @TranStarted = 1 )
51
BEGIN
52
SET @TranStarted = 0
53
COMMIT TRANSACTION
54
END
55![](/Images/OutliningIndicators/None.gif)
56
RETURN
57![](/Images/OutliningIndicators/None.gif)
58
Cleanup:
59![](/Images/OutliningIndicators/None.gif)
60
IF( @TranStarted = 1 )
61
BEGIN
62
SET @TranStarted = 0
63
ROLLBACK TRANSACTION
64
END
65![](/Images/OutliningIndicators/None.gif)
66
RETURN -1
67![](/Images/OutliningIndicators/None.gif)
68
END
![](/Images/OutliningIndicators/None.gif)
2
![](/Images/OutliningIndicators/None.gif)
3
![](/Images/OutliningIndicators/None.gif)
4
![](/Images/OutliningIndicators/None.gif)
5
![](/Images/OutliningIndicators/None.gif)
6
![](/Images/OutliningIndicators/None.gif)
7
![](/Images/OutliningIndicators/None.gif)
8
![](/Images/OutliningIndicators/None.gif)
9
![](/Images/OutliningIndicators/None.gif)
10
![](/Images/OutliningIndicators/None.gif)
11
![](/Images/OutliningIndicators/None.gif)
12
![](/Images/OutliningIndicators/None.gif)
13
![](/Images/OutliningIndicators/None.gif)
14
![](/Images/OutliningIndicators/None.gif)
15
![](/Images/OutliningIndicators/None.gif)
16
![](/Images/OutliningIndicators/None.gif)
17
![](/Images/OutliningIndicators/None.gif)
18
![](/Images/OutliningIndicators/None.gif)
19
![](/Images/OutliningIndicators/None.gif)
20
![](/Images/OutliningIndicators/None.gif)
21
![](/Images/OutliningIndicators/None.gif)
22
![](/Images/OutliningIndicators/None.gif)
23
![](/Images/OutliningIndicators/None.gif)
24
![](/Images/OutliningIndicators/None.gif)
25
![](/Images/OutliningIndicators/None.gif)
26
![](/Images/OutliningIndicators/None.gif)
27
![](/Images/OutliningIndicators/None.gif)
28
![](/Images/OutliningIndicators/None.gif)
29
![](/Images/OutliningIndicators/None.gif)
30
![](/Images/OutliningIndicators/None.gif)
31
![](/Images/OutliningIndicators/None.gif)
32
![](/Images/OutliningIndicators/None.gif)
33
![](/Images/OutliningIndicators/None.gif)
34
![](/Images/OutliningIndicators/None.gif)
35
![](/Images/OutliningIndicators/None.gif)
36
![](/Images/OutliningIndicators/None.gif)
37
![](/Images/OutliningIndicators/None.gif)
38
![](/Images/OutliningIndicators/None.gif)
39
![](/Images/OutliningIndicators/None.gif)
40
![](/Images/OutliningIndicators/None.gif)
41
![](/Images/OutliningIndicators/None.gif)
42
![](/Images/OutliningIndicators/None.gif)
43
![](/Images/OutliningIndicators/None.gif)
44
![](/Images/OutliningIndicators/None.gif)
45
![](/Images/OutliningIndicators/None.gif)
46
![](/Images/OutliningIndicators/None.gif)
47
![](/Images/OutliningIndicators/None.gif)
48
![](/Images/OutliningIndicators/None.gif)
49
![](/Images/OutliningIndicators/None.gif)
50
![](/Images/OutliningIndicators/None.gif)
51
![](/Images/OutliningIndicators/None.gif)
52
![](/Images/OutliningIndicators/None.gif)
53
![](/Images/OutliningIndicators/None.gif)
54
![](/Images/OutliningIndicators/None.gif)
55
![](/Images/OutliningIndicators/None.gif)
56
![](/Images/OutliningIndicators/None.gif)
57
![](/Images/OutliningIndicators/None.gif)
58
![](/Images/OutliningIndicators/None.gif)
59
![](/Images/OutliningIndicators/None.gif)
60
![](/Images/OutliningIndicators/None.gif)
61
![](/Images/OutliningIndicators/None.gif)
62
![](/Images/OutliningIndicators/None.gif)
63
![](/Images/OutliningIndicators/None.gif)
64
![](/Images/OutliningIndicators/None.gif)
65
![](/Images/OutliningIndicators/None.gif)
66
![](/Images/OutliningIndicators/None.gif)
67
![](/Images/OutliningIndicators/None.gif)
68
![](/Images/OutliningIndicators/None.gif)