Leaked source code of windows server 2003
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

986 lines
30 KiB

  1. /* First uninstall - this section is exactly the same as uninstall.sql */
  2. USE master
  3. GO
  4. /* Drop the database containing our sprocs */
  5. IF DB_ID('ASPState') IS NOT NULL BEGIN
  6. DROP DATABASE ASPState
  7. END
  8. GO
  9. /* Drop the obsolete startup enabler */
  10. DECLARE @PROCID int
  11. SET @PROCID = OBJECT_ID('EnableASPStateStartup')
  12. IF @PROCID IS NOT NULL AND OBJECTPROPERTY(@PROCID, 'IsProcedure') = 1 BEGIN
  13. DROP PROCEDURE EnableASPStateStartup
  14. END
  15. GO
  16. /* Drop the obsolete startup disabler */
  17. DECLARE @PROCID int
  18. SET @PROCID = OBJECT_ID('DisableASPStateStartup')
  19. IF @PROCID IS NOT NULL AND OBJECTPROPERTY(@PROCID, 'IsProcedure') = 1 BEGIN
  20. DROP PROCEDURE DisableASPStateStartup
  21. END
  22. GO
  23. /* Drop the ASPState_DeleteExpiredSessions_Job */
  24. DECLARE @JobID BINARY(16)
  25. SELECT @JobID = job_id
  26. FROM msdb.dbo.sysjobs
  27. WHERE (name = N'ASPState_Job_DeleteExpiredSessions')
  28. IF (@JobID IS NOT NULL)
  29. BEGIN
  30. -- Check if the job is a multi-server job
  31. IF (EXISTS (SELECT *
  32. FROM msdb.dbo.sysjobservers
  33. WHERE (job_id = @JobID) AND (server_id <> 0)))
  34. BEGIN
  35. -- There is, so abort the script
  36. RAISERROR (N'Unable to import job ''ASPState_Job_DeleteExpiredSessions'' since there is already a multi-server job with this name.', 16, 1)
  37. END
  38. ELSE
  39. -- Delete the [local] job
  40. EXECUTE msdb.dbo.sp_delete_job @job_name = N'ASPState_Job_DeleteExpiredSessions'
  41. END
  42. /* Create and populate the ASPState database */
  43. CREATE DATABASE ASPState
  44. GO
  45. USE ASPState
  46. GO
  47. /* Check to make sure the USE worked. The CREATE DATABASE may have failed. */
  48. IF DB_NAME()<>'ASPState' BEGIN
  49. RAISERROR('Error creating state database',20,1) -- Sev 20 will terminate the connection
  50. END
  51. SET QUOTED_IDENTIFIER OFF
  52. GO
  53. SET ANSI_NULLS ON
  54. GO
  55. CREATE PROCEDURE DropTempTables
  56. AS
  57. IF OBJECT_ID('ASPState..ASPStateTempSessions','U') IS NOT NULL BEGIN
  58. DROP TABLE ASPState..ASPStateTempSessions
  59. END
  60. IF OBJECT_ID('ASPState..ASPStateTempApplications','U') IS NOT NULL BEGIN
  61. DROP TABLE ASPState..ASPStateTempApplications
  62. END
  63. RETURN 0
  64. GO
  65. CREATE PROCEDURE GetMajorVersion
  66. @@ver int output
  67. AS
  68. /* Find out the version */
  69. IF OBJECT_ID('tempdb..#AspstateVer') IS NOT NULL BEGIN
  70. DROP TABLE #AspstateVer
  71. END
  72. CREATE TABLE #AspstateVer
  73. (
  74. c1 INT,
  75. c2 CHAR(100),
  76. c3 CHAR(100),
  77. version CHAR(100)
  78. )
  79. INSERT INTO #AspstateVer
  80. EXEC master..xp_msver ProductVersion
  81. DECLARE @version CHAR(100)
  82. DECLARE @dot INT
  83. SELECT @version = version FROM #AspstateVer
  84. SELECT @dot = CHARINDEX('.', @version)
  85. SELECT @@ver = CONVERT(INT, SUBSTRING(@version, 1, @dot-1))
  86. GO
  87. /* Find out the version */
  88. DECLARE @ver INT
  89. EXEC GetMajorVersion @@ver=@ver OUTPUT
  90. DECLARE @cmd CHAR(8000)
  91. IF (@ver >= 8)
  92. SET @cmd = '
  93. CREATE PROCEDURE CreateTempTables
  94. AS
  95. CREATE TABLE ASPState..ASPStateTempSessions (
  96. SessionId CHAR(32) NOT NULL PRIMARY KEY,
  97. Created DATETIME NOT NULL DEFAULT GETUTCDATE(),
  98. Expires DATETIME NOT NULL,
  99. LockDate DATETIME NOT NULL,
  100. LockDateLocal DATETIME NOT NULL,
  101. LockCookie INT NOT NULL,
  102. Timeout INT NOT NULL,
  103. Locked BIT NOT NULL,
  104. SessionItemShort VARBINARY(7000) NULL,
  105. SessionItemLong IMAGE NULL,
  106. )
  107. CREATE TABLE ASPState..ASPStateTempApplications (
  108. AppId INT NOT NULL IDENTITY PRIMARY KEY,
  109. AppName CHAR(280) NOT NULL,
  110. )
  111. CREATE NONCLUSTERED INDEX Index_AppName ON ASPState..ASPStateTempApplications(AppName)
  112. RETURN 0'
  113. ELSE
  114. SET @cmd = '
  115. CREATE PROCEDURE CreateTempTables
  116. AS
  117. CREATE TABLE ASPState..ASPStateTempSessions (
  118. SessionId CHAR(32) NOT NULL PRIMARY KEY,
  119. Created DATETIME NOT NULL DEFAULT GETDATE(),
  120. Expires DATETIME NOT NULL,
  121. LockDate DATETIME NOT NULL,
  122. LockCookie INT NOT NULL,
  123. Timeout INT NOT NULL,
  124. Locked BIT NOT NULL,
  125. SessionItemShort VARBINARY(7000) NULL,
  126. SessionItemLong IMAGE NULL,
  127. )
  128. CREATE TABLE ASPState..ASPStateTempApplications (
  129. AppId INT NOT NULL IDENTITY PRIMARY KEY,
  130. AppName CHAR(280) NOT NULL,
  131. )
  132. CREATE NONCLUSTERED INDEX Index_AppName ON ASPState..ASPStateTempApplications(AppName)
  133. RETURN 0'
  134. EXEC (@cmd)
  135. GO
  136. CREATE PROCEDURE ResetData
  137. AS
  138. EXECUTE DropTempTables
  139. EXECUTE CreateTempTables
  140. RETURN 0
  141. GO
  142. EXECUTE sp_addtype tSessionId, 'CHAR(32)', 'NOT NULL'
  143. GO
  144. EXECUTE sp_addtype tAppName, 'VARCHAR(280)', 'NOT NULL'
  145. GO
  146. EXECUTE sp_addtype tSessionItemShort, 'VARBINARY(7000)'
  147. GO
  148. EXECUTE sp_addtype tSessionItemLong, 'IMAGE'
  149. GO
  150. EXECUTE sp_addtype tTextPtr, 'VARBINARY(16)'
  151. GO
  152. CREATE PROCEDURE TempGetAppID
  153. @appName tAppName,
  154. @appId INT OUTPUT
  155. AS
  156. SELECT @appId = AppId
  157. FROM ASPState..ASPStateTempApplications
  158. WHERE AppName = @appName
  159. IF @appId IS NULL BEGIN
  160. INSERT ASPState..ASPStateTempApplications
  161. (AppName)
  162. VALUES
  163. (@appName)
  164. SELECT @appId = AppId
  165. FROM ASPState..ASPStateTempApplications
  166. WHERE AppName = @appName
  167. END
  168. RETURN 0
  169. GO
  170. /* Find out the version */
  171. DECLARE @ver INT
  172. EXEC GetMajorVersion @@ver=@ver OUTPUT
  173. DECLARE @cmd CHAR(8000)
  174. IF (@ver >= 8)
  175. SET @cmd = '
  176. CREATE PROCEDURE TempGetStateItem
  177. @id tSessionId,
  178. @itemShort tSessionItemShort OUTPUT,
  179. @locked BIT OUTPUT,
  180. @lockDate DATETIME OUTPUT,
  181. @lockCookie INT OUTPUT
  182. AS
  183. DECLARE @textptr AS tTextPtr
  184. DECLARE @length AS INT
  185. DECLARE @now as DATETIME
  186. SET @now = GETUTCDATE()
  187. UPDATE ASPState..ASPStateTempSessions
  188. SET Expires = DATEADD(n, Timeout, @now),
  189. @locked = Locked,
  190. @lockDate = LockDateLocal,
  191. @lockCookie = LockCookie,
  192. @itemShort = CASE @locked
  193. WHEN 0 THEN SessionItemShort
  194. ELSE NULL
  195. END,
  196. @textptr = CASE @locked
  197. WHEN 0 THEN TEXTPTR(SessionItemLong)
  198. ELSE NULL
  199. END,
  200. @length = CASE @locked
  201. WHEN 0 THEN DATALENGTH(SessionItemLong)
  202. ELSE NULL
  203. END
  204. WHERE SessionId = @id
  205. IF @length IS NOT NULL BEGIN
  206. READTEXT ASPState..ASPStateTempSessions.SessionItemLong @textptr 0 @length
  207. END
  208. RETURN 0'
  209. ELSE
  210. SET @cmd = '
  211. CREATE PROCEDURE TempGetStateItem
  212. @id tSessionId,
  213. @itemShort tSessionItemShort OUTPUT,
  214. @locked BIT OUTPUT,
  215. @lockDate DATETIME OUTPUT,
  216. @lockCookie INT OUTPUT
  217. AS
  218. DECLARE @textptr AS tTextPtr
  219. DECLARE @length AS INT
  220. DECLARE @now as DATETIME
  221. SET @now = GETDATE()
  222. UPDATE ASPState..ASPStateTempSessions
  223. SET Expires = DATEADD(n, Timeout, @now),
  224. @locked = Locked,
  225. @lockDate = LockDate,
  226. @lockCookie = LockCookie,
  227. @itemShort = CASE @locked
  228. WHEN 0 THEN SessionItemShort
  229. ELSE NULL
  230. END,
  231. @textptr = CASE @locked
  232. WHEN 0 THEN TEXTPTR(SessionItemLong)
  233. ELSE NULL
  234. END,
  235. @length = CASE @locked
  236. WHEN 0 THEN DATALENGTH(SessionItemLong)
  237. ELSE NULL
  238. END
  239. WHERE SessionId = @id
  240. IF @length IS NOT NULL BEGIN
  241. READTEXT ASPState..ASPStateTempSessions.SessionItemLong @textptr 0 @length
  242. END
  243. RETURN 0'
  244. EXEC (@cmd)
  245. GO
  246. DECLARE @ver INT
  247. EXEC GetMajorVersion @@ver=@ver OUTPUT
  248. DECLARE @cmd CHAR(8000)
  249. IF (@ver >= 8)
  250. SET @cmd = '
  251. CREATE PROCEDURE TempGetStateItem2
  252. @id tSessionId,
  253. @itemShort tSessionItemShort OUTPUT,
  254. @locked BIT OUTPUT,
  255. @lockAge INT OUTPUT,
  256. @lockCookie INT OUTPUT
  257. AS
  258. DECLARE @textptr AS tTextPtr
  259. DECLARE @length AS INT
  260. DECLARE @now as DATETIME
  261. SET @now = GETUTCDATE()
  262. UPDATE ASPState..ASPStateTempSessions
  263. SET Expires = DATEADD(n, Timeout, @now),
  264. @locked = Locked,
  265. @lockAge = DATEDIFF(second, LockDate, @now),
  266. @lockCookie = LockCookie,
  267. @itemShort = CASE @locked
  268. WHEN 0 THEN SessionItemShort
  269. ELSE NULL
  270. END,
  271. @textptr = CASE @locked
  272. WHEN 0 THEN TEXTPTR(SessionItemLong)
  273. ELSE NULL
  274. END,
  275. @length = CASE @locked
  276. WHEN 0 THEN DATALENGTH(SessionItemLong)
  277. ELSE NULL
  278. END
  279. WHERE SessionId = @id
  280. IF @length IS NOT NULL BEGIN
  281. READTEXT ASPState..ASPStateTempSessions.SessionItemLong @textptr 0 @length
  282. END
  283. RETURN 0'
  284. EXEC (@cmd)
  285. GO
  286. DECLARE @ver INT
  287. EXEC GetMajorVersion @@ver=@ver OUTPUT
  288. DECLARE @cmd CHAR(8000)
  289. IF (@ver >= 8)
  290. SET @cmd = '
  291. CREATE PROCEDURE TempGetStateItemExclusive
  292. @id tSessionId,
  293. @itemShort tSessionItemShort OUTPUT,
  294. @locked BIT OUTPUT,
  295. @lockDate DATETIME OUTPUT,
  296. @lockCookie INT OUTPUT
  297. AS
  298. DECLARE @textptr AS tTextPtr
  299. DECLARE @length AS INT
  300. DECLARE @now as DATETIME
  301. DECLARE @nowLocal as DATETIME
  302. SET @now = GETUTCDATE()
  303. SET @nowLocal = GETDATE()
  304. UPDATE ASPState..ASPStateTempSessions
  305. SET Expires = DATEADD(n, Timeout, @now),
  306. LockDate = CASE Locked
  307. WHEN 0 THEN @now
  308. ELSE LockDate
  309. END,
  310. @lockDate = LockDateLocal = CASE Locked
  311. WHEN 0 THEN @nowLocal
  312. ELSE LockDateLocal
  313. END,
  314. @lockCookie = LockCookie = CASE Locked
  315. WHEN 0 THEN LockCookie + 1
  316. ELSE LockCookie
  317. END,
  318. @itemShort = CASE Locked
  319. WHEN 0 THEN SessionItemShort
  320. ELSE NULL
  321. END,
  322. @textptr = CASE Locked
  323. WHEN 0 THEN TEXTPTR(SessionItemLong)
  324. ELSE NULL
  325. END,
  326. @length = CASE Locked
  327. WHEN 0 THEN DATALENGTH(SessionItemLong)
  328. ELSE NULL
  329. END,
  330. @locked = Locked,
  331. Locked = 1
  332. WHERE SessionId = @id
  333. IF @length IS NOT NULL BEGIN
  334. READTEXT ASPState..ASPStateTempSessions.SessionItemLong @textptr 0 @length
  335. END
  336. RETURN 0'
  337. ELSE
  338. SET @cmd = '
  339. CREATE PROCEDURE TempGetStateItemExclusive
  340. @id tSessionId,
  341. @itemShort tSessionItemShort OUTPUT,
  342. @locked BIT OUTPUT,
  343. @lockDate DATETIME OUTPUT,
  344. @lockCookie INT OUTPUT
  345. AS
  346. DECLARE @textptr AS tTextPtr
  347. DECLARE @length AS INT
  348. DECLARE @now as DATETIME
  349. SET @now = GETDATE()
  350. UPDATE ASPState..ASPStateTempSessions
  351. SET Expires = DATEADD(n, Timeout, @now),
  352. @lockDate = LockDate = CASE Locked
  353. WHEN 0 THEN @now
  354. ELSE LockDate
  355. END,
  356. @lockCookie = LockCookie = CASE Locked
  357. WHEN 0 THEN LockCookie + 1
  358. ELSE LockCookie
  359. END,
  360. @itemShort = CASE Locked
  361. WHEN 0 THEN SessionItemShort
  362. ELSE NULL
  363. END,
  364. @textptr = CASE Locked
  365. WHEN 0 THEN TEXTPTR(SessionItemLong)
  366. ELSE NULL
  367. END,
  368. @length = CASE Locked
  369. WHEN 0 THEN DATALENGTH(SessionItemLong)
  370. ELSE NULL
  371. END,
  372. @locked = Locked,
  373. Locked = 1
  374. WHERE SessionId = @id
  375. IF @length IS NOT NULL BEGIN
  376. READTEXT ASPState..ASPStateTempSessions.SessionItemLong @textptr 0 @length
  377. END
  378. RETURN 0'
  379. EXEC (@cmd)
  380. GO
  381. DECLARE @ver INT
  382. EXEC GetMajorVersion @@ver=@ver OUTPUT
  383. DECLARE @cmd CHAR(8000)
  384. IF (@ver >= 8)
  385. SET @cmd = '
  386. CREATE PROCEDURE TempGetStateItemExclusive2
  387. @id tSessionId,
  388. @itemShort tSessionItemShort OUTPUT,
  389. @locked BIT OUTPUT,
  390. @lockAge INT OUTPUT,
  391. @lockCookie INT OUTPUT
  392. AS
  393. DECLARE @textptr AS tTextPtr
  394. DECLARE @length AS INT
  395. DECLARE @now as DATETIME
  396. DECLARE @nowLocal as DATETIME
  397. SET @now = GETUTCDATE()
  398. SET @nowLocal = GETDATE()
  399. UPDATE ASPState..ASPStateTempSessions
  400. SET Expires = DATEADD(n, Timeout, @now),
  401. LockDate = CASE Locked
  402. WHEN 0 THEN @now
  403. ELSE LockDate
  404. END,
  405. LockDateLocal = CASE Locked
  406. WHEN 0 THEN @nowLocal
  407. ELSE LockDateLocal
  408. END,
  409. @lockAge = CASE Locked
  410. WHEN 0 THEN 0
  411. ELSE DATEDIFF(second, LockDate, @now)
  412. END,
  413. @lockCookie = LockCookie = CASE Locked
  414. WHEN 0 THEN LockCookie + 1
  415. ELSE LockCookie
  416. END,
  417. @itemShort = CASE Locked
  418. WHEN 0 THEN SessionItemShort
  419. ELSE NULL
  420. END,
  421. @textptr = CASE Locked
  422. WHEN 0 THEN TEXTPTR(SessionItemLong)
  423. ELSE NULL
  424. END,
  425. @length = CASE Locked
  426. WHEN 0 THEN DATALENGTH(SessionItemLong)
  427. ELSE NULL
  428. END,
  429. @locked = Locked,
  430. Locked = 1
  431. WHERE SessionId = @id
  432. IF @length IS NOT NULL BEGIN
  433. READTEXT ASPState..ASPStateTempSessions.SessionItemLong @textptr 0 @length
  434. END
  435. RETURN 0'
  436. EXEC (@cmd)
  437. GO
  438. DECLARE @ver INT
  439. EXEC GetMajorVersion @@ver=@ver OUTPUT
  440. DECLARE @cmd CHAR(8000)
  441. IF (@ver >= 8)
  442. SET @cmd = '
  443. CREATE PROCEDURE TempReleaseStateItemExclusive
  444. @id tSessionId,
  445. @lockCookie INT
  446. AS
  447. UPDATE ASPState..ASPStateTempSessions
  448. SET Expires = DATEADD(n, Timeout, GETUTCDATE()),
  449. Locked = 0
  450. WHERE SessionId = @id AND LockCookie = @lockCookie
  451. RETURN 0'
  452. ELSE
  453. SET @cmd = '
  454. CREATE PROCEDURE TempReleaseStateItemExclusive
  455. @id tSessionId,
  456. @lockCookie INT
  457. AS
  458. UPDATE ASPState..ASPStateTempSessions
  459. SET Expires = DATEADD(n, Timeout, GETDATE()),
  460. Locked = 0
  461. WHERE SessionId = @id AND LockCookie = @lockCookie
  462. RETURN 0'
  463. EXEC (@cmd)
  464. GO
  465. DECLARE @ver INT
  466. EXEC GetMajorVersion @@ver=@ver OUTPUT
  467. DECLARE @cmd CHAR(8000)
  468. IF (@ver >= 8)
  469. SET @cmd = '
  470. CREATE PROCEDURE TempInsertStateItemShort
  471. @id tSessionId,
  472. @itemShort tSessionItemShort,
  473. @timeout INT
  474. AS
  475. DECLARE @now as DATETIME
  476. DECLARE @nowLocal as DATETIME
  477. SET @now = GETUTCDATE()
  478. SET @nowLocal = GETDATE()
  479. INSERT ASPState..ASPStateTempSessions
  480. (SessionId,
  481. SessionItemShort,
  482. Timeout,
  483. Expires,
  484. Locked,
  485. LockDate,
  486. LockDateLocal,
  487. LockCookie)
  488. VALUES
  489. (@id,
  490. @itemShort,
  491. @timeout,
  492. DATEADD(n, @timeout, @now),
  493. 0,
  494. @now,
  495. @nowLocal,
  496. 1)
  497. RETURN 0'
  498. ELSE
  499. SET @cmd = '
  500. CREATE PROCEDURE TempInsertStateItemShort
  501. @id tSessionId,
  502. @itemShort tSessionItemShort,
  503. @timeout INT
  504. AS
  505. DECLARE @now as DATETIME
  506. SET @now = GETDATE()
  507. INSERT ASPState..ASPStateTempSessions
  508. (SessionId,
  509. SessionItemShort,
  510. Timeout,
  511. Expires,
  512. Locked,
  513. LockDate,
  514. LockCookie)
  515. VALUES
  516. (@id,
  517. @itemShort,
  518. @timeout,
  519. DATEADD(n, @timeout, @now),
  520. 0,
  521. @now,
  522. 1)
  523. RETURN 0'
  524. EXEC (@cmd)
  525. GO
  526. DECLARE @ver INT
  527. EXEC GetMajorVersion @@ver=@ver OUTPUT
  528. DECLARE @cmd CHAR(8000)
  529. IF (@ver >= 8)
  530. SET @cmd = '
  531. CREATE PROCEDURE TempInsertStateItemLong
  532. @id tSessionId,
  533. @itemLong tSessionItemLong,
  534. @timeout INT
  535. AS
  536. DECLARE @now as DATETIME
  537. DECLARE @nowLocal as DATETIME
  538. SET @now = GETUTCDATE()
  539. SET @nowLocal = GETDATE()
  540. INSERT ASPState..ASPStateTempSessions
  541. (SessionId,
  542. SessionItemLong,
  543. Timeout,
  544. Expires,
  545. Locked,
  546. LockDate,
  547. LockDateLocal,
  548. LockCookie)
  549. VALUES
  550. (@id,
  551. @itemLong,
  552. @timeout,
  553. DATEADD(n, @timeout, @now),
  554. 0,
  555. @now,
  556. @nowLocal,
  557. 1)
  558. RETURN 0'
  559. ELSE
  560. SET @cmd = '
  561. CREATE PROCEDURE TempInsertStateItemLong
  562. @id tSessionId,
  563. @itemLong tSessionItemLong,
  564. @timeout INT
  565. AS
  566. DECLARE @now as DATETIME
  567. SET @now = GETDATE()
  568. INSERT ASPState..ASPStateTempSessions
  569. (SessionId,
  570. SessionItemLong,
  571. Timeout,
  572. Expires,
  573. Locked,
  574. LockDate,
  575. LockCookie)
  576. VALUES
  577. (@id,
  578. @itemLong,
  579. @timeout,
  580. DATEADD(n, @timeout, @now),
  581. 0,
  582. @now,
  583. 1)
  584. RETURN 0'
  585. EXEC (@cmd)
  586. GO
  587. DECLARE @ver INT
  588. EXEC GetMajorVersion @@ver=@ver OUTPUT
  589. DECLARE @cmd CHAR(8000)
  590. IF (@ver >= 8)
  591. SET @cmd = '
  592. CREATE PROCEDURE TempUpdateStateItemShort
  593. @id tSessionId,
  594. @itemShort tSessionItemShort,
  595. @timeout INT,
  596. @lockCookie INT
  597. AS
  598. UPDATE ASPState..ASPStateTempSessions
  599. SET Expires = DATEADD(n, Timeout, GETUTCDATE()),
  600. SessionItemShort = @itemShort,
  601. Timeout = @timeout,
  602. Locked = 0
  603. WHERE SessionId = @id AND LockCookie = @lockCookie
  604. RETURN 0'
  605. ELSE
  606. SET @cmd = '
  607. CREATE PROCEDURE TempUpdateStateItemShort
  608. @id tSessionId,
  609. @itemShort tSessionItemShort,
  610. @timeout INT,
  611. @lockCookie INT
  612. AS
  613. UPDATE ASPState..ASPStateTempSessions
  614. SET Expires = DATEADD(n, Timeout, GETDATE()),
  615. SessionItemShort = @itemShort,
  616. Timeout = @timeout,
  617. Locked = 0
  618. WHERE SessionId = @id AND LockCookie = @lockCookie
  619. RETURN 0'
  620. EXEC (@cmd)
  621. GO
  622. DECLARE @ver INT
  623. EXEC GetMajorVersion @@ver=@ver OUTPUT
  624. DECLARE @cmd CHAR(8000)
  625. IF (@ver >= 8)
  626. SET @cmd = '
  627. CREATE PROCEDURE TempUpdateStateItemShortNullLong
  628. @id tSessionId,
  629. @itemShort tSessionItemShort,
  630. @timeout INT,
  631. @lockCookie INT
  632. AS
  633. UPDATE ASPState..ASPStateTempSessions
  634. SET Expires = DATEADD(n, Timeout, GETUTCDATE()),
  635. SessionItemShort = @itemShort,
  636. SessionItemLong = NULL,
  637. Timeout = @timeout,
  638. Locked = 0
  639. WHERE SessionId = @id AND LockCookie = @lockCookie
  640. RETURN 0'
  641. ELSE
  642. SET @cmd = '
  643. CREATE PROCEDURE TempUpdateStateItemShortNullLong
  644. @id tSessionId,
  645. @itemShort tSessionItemShort,
  646. @timeout INT,
  647. @lockCookie INT
  648. AS
  649. UPDATE ASPState..ASPStateTempSessions
  650. SET Expires = DATEADD(n, Timeout, GETDATE()),
  651. SessionItemShort = @itemShort,
  652. SessionItemLong = NULL,
  653. Timeout = @timeout,
  654. Locked = 0
  655. WHERE SessionId = @id AND LockCookie = @lockCookie
  656. RETURN 0'
  657. EXEC (@cmd)
  658. GO
  659. DECLARE @ver INT
  660. EXEC GetMajorVersion @@ver=@ver OUTPUT
  661. DECLARE @cmd CHAR(8000)
  662. IF (@ver >= 8)
  663. SET @cmd = '
  664. CREATE PROCEDURE TempUpdateStateItemLong
  665. @id tSessionId,
  666. @itemLong tSessionItemLong,
  667. @timeout INT,
  668. @lockCookie INT
  669. AS
  670. UPDATE ASPState..ASPStateTempSessions
  671. SET Expires = DATEADD(n, Timeout, GETUTCDATE()),
  672. SessionItemLong = @itemLong,
  673. Timeout = @timeout,
  674. Locked = 0
  675. WHERE SessionId = @id AND LockCookie = @lockCookie
  676. RETURN 0'
  677. ELSE
  678. SET @cmd = '
  679. CREATE PROCEDURE TempUpdateStateItemLong
  680. @id tSessionId,
  681. @itemLong tSessionItemLong,
  682. @timeout INT,
  683. @lockCookie INT
  684. AS
  685. UPDATE ASPState..ASPStateTempSessions
  686. SET Expires = DATEADD(n, Timeout, GETDATE()),
  687. SessionItemLong = @itemLong,
  688. Timeout = @timeout,
  689. Locked = 0
  690. WHERE SessionId = @id AND LockCookie = @lockCookie
  691. RETURN 0'
  692. EXEC (@cmd)
  693. GO
  694. DECLARE @ver INT
  695. EXEC GetMajorVersion @@ver=@ver OUTPUT
  696. DECLARE @cmd CHAR(8000)
  697. IF (@ver >= 8)
  698. SET @cmd = '
  699. CREATE PROCEDURE TempUpdateStateItemLongNullShort
  700. @id tSessionId,
  701. @itemLong tSessionItemLong,
  702. @timeout INT,
  703. @lockCookie INT
  704. AS
  705. UPDATE ASPState..ASPStateTempSessions
  706. SET Expires = DATEADD(n, Timeout, GETUTCDATE()),
  707. SessionItemLong = @itemLong,
  708. SessionItemShort = NULL,
  709. Timeout = @timeout,
  710. Locked = 0
  711. WHERE SessionId = @id AND LockCookie = @lockCookie
  712. RETURN 0'
  713. ELSE
  714. SET @cmd = '
  715. CREATE PROCEDURE TempUpdateStateItemLongNullShort
  716. @id tSessionId,
  717. @itemLong tSessionItemLong,
  718. @timeout INT,
  719. @lockCookie INT
  720. AS
  721. UPDATE ASPState..ASPStateTempSessions
  722. SET Expires = DATEADD(n, Timeout, GETDATE()),
  723. SessionItemLong = @itemLong,
  724. SessionItemShort = NULL,
  725. Timeout = @timeout,
  726. Locked = 0
  727. WHERE SessionId = @id AND LockCookie = @lockCookie
  728. RETURN 0'
  729. EXEC (@cmd)
  730. GO
  731. CREATE PROCEDURE TempRemoveStateItem
  732. @id tSessionId,
  733. @lockCookie INT
  734. AS
  735. DELETE ASPState..ASPStateTempSessions
  736. WHERE SessionId = @id AND LockCookie = @lockCookie
  737. RETURN 0
  738. GO
  739. DECLARE @ver INT
  740. EXEC GetMajorVersion @@ver=@ver OUTPUT
  741. DECLARE @cmd CHAR(8000)
  742. IF (@ver >= 8)
  743. SET @cmd = '
  744. CREATE PROCEDURE TempResetTimeout
  745. @id tSessionId
  746. AS
  747. UPDATE ASPState..ASPStateTempSessions
  748. SET Expires = DATEADD(n, Timeout, GETUTCDATE())
  749. WHERE SessionId = @id
  750. RETURN 0'
  751. ELSE
  752. SET @cmd = '
  753. CREATE PROCEDURE TempResetTimeout
  754. @id tSessionId
  755. AS
  756. UPDATE ASPState..ASPStateTempSessions
  757. SET Expires = DATEADD(n, Timeout, GETDATE())
  758. WHERE SessionId = @id
  759. RETURN 0'
  760. EXEC (@cmd)
  761. GO
  762. DECLARE @ver INT
  763. EXEC GetMajorVersion @@ver=@ver OUTPUT
  764. DECLARE @cmd CHAR(8000)
  765. IF (@ver >= 8)
  766. SET @cmd = '
  767. CREATE PROCEDURE DeleteExpiredSessions
  768. AS
  769. DECLARE @now DATETIME
  770. SET @now = GETUTCDATE()
  771. DELETE ASPState..ASPStateTempSessions
  772. WHERE Expires < @now
  773. RETURN 0'
  774. ELSE
  775. SET @cmd = '
  776. CREATE PROCEDURE DeleteExpiredSessions
  777. AS
  778. DECLARE @now DATETIME
  779. SET @now = GETDATE()
  780. DELETE ASPState..ASPStateTempSessions
  781. WHERE Expires < @now
  782. RETURN 0'
  783. EXEC (@cmd)
  784. GO
  785. EXECUTE CreateTempTables
  786. GO
  787. /* Create the startup procedure */
  788. USE master
  789. GO
  790. /* Create the job to delete expired sessions */
  791. BEGIN TRANSACTION
  792. DECLARE @JobID BINARY(16)
  793. DECLARE @ReturnCode INT
  794. SELECT @ReturnCode = 0
  795. -- Add job category
  796. IF (SELECT COUNT(*) FROM msdb.dbo.syscategories WHERE name = N'[Uncategorized (Local)]') < 1
  797. EXECUTE msdb.dbo.sp_add_category @name = N'[Uncategorized (Local)]'
  798. -- Add the job
  799. EXECUTE @ReturnCode = msdb.dbo.sp_add_job
  800. @job_id = @JobID OUTPUT,
  801. @job_name = N'ASPState_Job_DeleteExpiredSessions',
  802. @owner_login_name = NULL,
  803. @description = N'Deletes expired sessions from the session state database.',
  804. @category_name = N'[Uncategorized (Local)]',
  805. @enabled = 1,
  806. @notify_level_email = 0,
  807. @notify_level_page = 0,
  808. @notify_level_netsend = 0,
  809. @notify_level_eventlog = 0,
  810. @delete_level= 0
  811. IF (@@ERROR <> 0 OR @ReturnCode <> 0) GOTO QuitWithRollback
  812. -- Add the job steps
  813. EXECUTE @ReturnCode = msdb.dbo.sp_add_jobstep
  814. @job_id = @JobID,
  815. @step_id = 1,
  816. @step_name = N'ASPState_JobStep_DeleteExpiredSessions',
  817. @command = N'EXECUTE DeleteExpiredSessions',
  818. @database_name = N'ASPState',
  819. @server = N'',
  820. @database_user_name = N'',
  821. @subsystem = N'TSQL',
  822. @cmdexec_success_code = 0,
  823. @flags = 0,
  824. @retry_attempts = 0,
  825. @retry_interval = 1,
  826. @output_file_name = N'',
  827. @on_success_step_id = 0,
  828. @on_success_action = 1,
  829. @on_fail_step_id = 0,
  830. @on_fail_action = 2
  831. IF (@@ERROR <> 0 OR @ReturnCode <> 0) GOTO QuitWithRollback
  832. EXECUTE @ReturnCode = msdb.dbo.sp_update_job @job_id = @JobID, @start_step_id = 1
  833. IF (@@ERROR <> 0 OR @ReturnCode <> 0) GOTO QuitWithRollback
  834. -- Add the job schedules
  835. EXECUTE @ReturnCode = msdb.dbo.sp_add_jobschedule
  836. @job_id = @JobID,
  837. @name = N'ASPState_JobSchedule_DeleteExpiredSessions',
  838. @enabled = 1,
  839. @freq_type = 4,
  840. @active_start_date = 20001016,
  841. @active_start_time = 0,
  842. @freq_interval = 1,
  843. @freq_subday_type = 4,
  844. @freq_subday_interval = 1,
  845. @freq_relative_interval = 0,
  846. @freq_recurrence_factor = 0,
  847. @active_end_date = 99991231,
  848. @active_end_time = 235959
  849. IF (@@ERROR <> 0 OR @ReturnCode <> 0) GOTO QuitWithRollback
  850. -- Add the Target Servers
  851. EXECUTE @ReturnCode = msdb.dbo.sp_add_jobserver @job_id = @JobID, @server_name = N'(local)'
  852. IF (@@ERROR <> 0 OR @ReturnCode <> 0) GOTO QuitWithRollback
  853. COMMIT TRANSACTION
  854. GOTO EndSave
  855. QuitWithRollback:
  856. IF (@@TRANCOUNT > 0) ROLLBACK TRANSACTION
  857. EndSave:
  858. GO