Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 5975463
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T21:05:19+00:00 2026-05-22T21:05:19+00:00

How could I add some items to the tempdb anytime SQL Server starts up?

  • 0

How could I add some items to the tempdb anytime SQL Server starts up?

I’m no expert at this, but our ASP SessionState is stored in the DB and for some reason the tempdb items used for the session state get dropped anytime the server restarts. Not only do I need to recreate the items, but I also have to recreate the User mappings to tempdb. I have a script that does it, but I can’t figure out how to run it on SQL startup

-- Use TempDB
use tempdb
go

-- Create Temp tables if they don't exist
IF NOT EXISTS(
    SELECT 1 FROM INFORMATION_SCHEMA.TABLES
    WHERE TABLE_TYPE='BASE TABLE'
    AND TABLE_NAME = 'ASPStateTempSessions')
BEGIN
    EXECUTE [ASPState].[dbo].[CreateTempTables] 
END

-- If ASPSessionState user isn't mapped to temp db, map it
IF IS_MEMBER('ASPSessionState') IS NULL
    create user ASPSessionState from login ASPSessionState

-- Give ASPSessionState user read/write permissions to tempdb
exec sp_addrolemember db_datareader, ASPSessionState 
go
exec sp_addrolemember db_datawriter , ASPSessionState 
go
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-22T21:05:20+00:00Added an answer on May 22, 2026 at 9:05 pm

    Um, if you’ve used the standard settings to enable ASP.Net session state in tempdb, the system should have generated a stored proc (ASPState_Startup) as follows in the master database. This stored proc is configured to run automatically on SQL Server startup:

    USE master
    GO
    
    DECLARE @sstype nvarchar(128)
    SET @sstype = N'sstype_temp'
    
    IF UPPER(@sstype) = 'SSTYPE_TEMP' BEGIN
        DECLARE @cmd nchar(4000)
    
        SET @cmd = N'
            /* Create the startup procedure */
            CREATE PROCEDURE dbo.ASPState_Startup 
            AS
                EXECUTE ASPState.dbo.CreateTempTables
    
                RETURN 0'
        EXEC(@cmd)
        EXECUTE sp_procoption @ProcName='dbo.ASPState_Startup', @OptionName='startup', @OptionValue='true'
    END    
    

    So, the temp tables should be being recreated anyway, unless something has been altered since installing.

    If additional permissions are required, I’d look to extending the existing CreateTempTables procedure in ASPState.


    If this isn’t working correctly, you might try using the aspnet_regsql command (found under %Windir%\Microsoft.Net\Framework\<framework version – to remove then re-add session state support to the server. You’d want to use -ssremove then -ssadd, but I’d suggest passing /? first to see all of the applicable options.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

If I wanted to badly enough, could I add additional LINQ constructs to LINQ-to-SQL
I have a sorting/grouping issue that I'm hoping somebody could add some insight on.
I need to add some validations before the user navigates away via an ASP.NET
If you could add anything to Cocoa, what would it be? Are there any
Im wondering how i could add a success or fail message to return at
how we could add a special class for labels and errors for a zend-form-element
I'm wondering how you could add flir on the captions of a lightbox. I
When answering another question I started to wonder how I could Add new properties
How could I add to a plot an OHLCSeriesCollection and a TimeSeriesCollection , in
How could I add the values of a matrix int[,] diagonally from bottomleft, to

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.