Managing State / Configuring a SQL Server State Store pt. 2
Visitors to VTC.com will be able to view all introductory videos for each training course.
Free Trial Members will gain access to first three chapters for each training course.
Full Access Members have full access to VTC.com’s entire library of video tutorials.
Learn More
Subtitles of the Movie
Welcome to Part 2 of configuring a SQL server state store and I want to show you something here that I just realized just as I was ending Part 1 and I want to leave this in because these are the kind of things that can absolutely drive you nuts and that is typos in these commands and as it turns out, there's a typo in this command. I notice right as I was ending the previous video and actually the typo came in here. The typo is right here. This should be an underscore, not a hyphen and the reason I'm leaving this in and I want to warn you about this kind of stuff is because I actually found this typo on Microsoft's website. As I was compiling this information and I copied this from Microsoft's website, this typo was there and I kept trying to run it and trying to run it and then I went to a different source and actually found on a forum out there where there was a typo on Microsoft's website. Now, what interesting is it has since been corrected but when you're typing these commands, understand it's going to be very, very important that obviously you get everything right so what I want to show you here is if I try to execute this way it's going to throw an error. It's going to tell me I don't recognize this so what I'll do is hit F3 and then I will go back and turn that into an underscore right here. It's ASP.NET underscore Reg SQL, OK? Then we'll come back and we're going to continue this process of setting up our SQL server and I will hit Enter now and you will notice it's adding the session state and this thing will kind of click and hum for just a few minutes and notice it says it has now completed the process. If you remember back in Part 1 of this couple of videos on configuring SQL server state store, I went out and looked in the Management Studio. So let's go back to the Management Studio now. So open your Management Studio however it works for you on your machine. Just connect to my default there. You will now notice under databases that along with Pubs I have a new database called ASP State. And I want to show you a couple of things in here and show you how cool this is that Microsoft has taken care of this for us. OK? First of all you'll notice if I expand the tables I have two tables here, a temp application, temp sessions. Then under programmability, if I look at store procedures, if you are familiar with store procedures you'll find this interesting. If not, don't worry about it. Notice there are a number of store procedures here that are being called automatically to read and write this information. You can go out there and look at some of this stuff and hack around and figure out some other cool things that you can do to call these things and read them yourself. So anyway, I will now close down the Management Studio. So we've set up our SQL server that's out there to store this information and so now what we need to do is tell our website to connect to that SQL server and write and read session information or session ids and so forth from there. So what I will do is in the Web.config file in my web application I will open that up and I'll get in the System.web section and I will add session state key and notice an XML nomenclature. This is a tag that opens and closes itself. There is no nested tag here. There's no begin tag and end tag signified by the/at the end. So we're going to add a session state tag. We're going to set the mode equal to SQL server. You will most likely see one already there and instead of SQL server right here, it will say in proc most likely but you want to make sure that Mode says SQL server. Then you want to set the SQL connection string equal to data source equal your server. Now, make sure again if you're using SQL Express, that you put the name of your server. In my instance it's Win 7. Put the backslash and then type SQL Express in all caps. If you're not using SQL Express, just put the name of your SQL server or the IP address of the SQL server, whatever. Integrated security equals true. They are the things you can set here but this is not a class on SQL connection strings so you can go chase some of that stuff on the side. The SQL command timeout, we're going to leave that at 30 and what that's going to do is now we have set up and automated the process. All of our session state information will be read and written to that particular SQL server. Now, if we set up another server in a web farm and we copy the same web app to the server, you want to make sure that the Web.config file on each one of the servers in our web farm for this particular application has this setting in the Web.config file. So it's pointing to that particular server in the farm to the same SQL data source. If you go back to the first video where I talked about the SQL server state store business, I think the title of that was using a SQL server session state store. You'll see that diagram, the animation again explains how this works. So in Part 2 what I've gone through is show you how to configure your SQL server state store. This is really cool stuff. This is ultimately the way you want to manage your session state information because this is ultimately scalable and it's the safest way to store this data and to use it.
Tutorial Information
| Course: | Microsoft ASP.NET 3.5 |
| Author: | Mark Long |
| SKU: | 34102 |
| ISBN: | 1-93633412-7 |
| Release Date: | 2010-03-24 |
| Duration: | 6 hrs / 69 lessons |
| Work Files: |
Yes |
| Captions: | Available on CD and Online University |
| Compatibility: |
Vista/XP/2000, OS X, Linux QuickTime 7, Flash 8 |
VTC Sign up & Benefits
- Unlimited Access
- 98,729 Video Tutorials (23,265 free)
- Video Available as Flash or QuickTime
- Over 1026 Courses
- $30 for One Month Access
- Multi-User Discounts Available
United States 