3

I am using a SQL Server for ASP.Net session state. However, I am only able to retrieve the connection string at runtime and for that reason cannot store it in the web.config file. Usually it would be in:

<sessionState 
            mode="SQLServer"
            sqlConnectionString="data source=127.0.0.1;user id=<username>;password=<strongpassword>"
            cookieless="false" 
            timeout="20" 
    />

How can I set that connection string at runtime? (i.e. after the web app spins up.)

2 Answers 2

1

Have you looked at doing it in the Application_Start event in Global.asax? This seems like the logical place to set something like that.

From MSDN's documentation:

Called when the first resource (such as a page) in an ASP.NET application is requested. The Application_Start method is called only one time during the life cycle of an application. You can use this method to perform startup tasks such as loading data into the cache and initializing static values.

You should set only static data during application start. Do not set any instance data because it will be available only to the first instance of the HttpApplication class that is created.

Sign up to request clarification or add additional context in comments.

1 Comment

Thanks Abe - I knew where to set it I just don't know what to set. I agree that Application_Start is probably the best place to set it just need to know what to override.
1

I would think you can set that string somewhere within System.Web.SessionState, hopefully that will help you get to the right place. Sorry I can't give a better answer, I'm still trying to figure it out myself. If I do, I'll let you know. GL

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.