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.

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