본문 바로가기

▣ DB ▣/◈ MS-SQL ◈

Session 상태를 유지하기 위한 설정



일반적으로 세션을 유지하기 위해서는


viewstate, cookie, session state service를 이용한다.


하지만 이런 부분은 서버를 재시작하건, IIS 재시작시 Session이 사라지는 문제가 발생한다.


이를 방지하기 위해 속도와 IO 부담은 조금 있지만, '


MSSQL 을 이용한 세션 유지를 해보도록 한다.


음... 기억을 더듬으며 기록중이라. ㅠ.ㅠ


몇가지 문제는 있겠지만,...


일단.. 기억용으로다가 ㅎㅎㅎ





1. web.config 설정 변경 : Mode 변경 

해당 정보는  : https://msdn.microsoft.com/ko-kr/library/ms178586(v=VS.100).aspx   참조


<configuration>  

    <system.web>  

            <sessionState mode="SQLServer"   

sqlConnectionString="data source=ServerHost; User ID=SessionUserID; Password=SessionUserPassword" timeout="3600" />  

    </system.web>  

</configuration>  





2. 세션 MS-SQL DB 구축 :  ASPState DB 생성


- MS-SQL 이 설치된 서버에서 아래 CMD 실행 후 입력 : 아래 밑줄 부분 본인 서버설정에 맞게 설정


C:\Windows\Microsoft.NET\Framework64\v4.0.30319>aspnet_regsql -S localhost -U SA아이디 -P SA패스워드 -ssadd -sstype p






< aspnet_regsql 파라미터 >

 

Parameter

Description

-S [Server Name] Sql Server name or IP address, where sessions will be stored

-E Windows authentication is used to access SQL Server

-U [User Name] User name, if SQL authentication is used

-P [Password] Password, if SQL authentication is used

-D [Database Name] Database name. This parameter is used if parameter -sstype is equal to "c", which means that custom database is used as session storage.

-ssadd Abbreviation of "Session State Add". This option adds session state database.

-ssremove This parameter removes existing session state database.

-sqlexportonly [Script File Name or Full Path]

 If this parameter is used, program will not execute any SQL, but just create T-SQL script which can be executed later on server(s). This is useful in shared hosting scenario.

Type of session state storage. There are three possible values:

-sstype [t|p|c] t, means temporary storage. Tables are created in temdb database. In this case session is lost if SQL Server restarts,

 p, represents persistent storage. Session state tables are created in AspState database,

 c, custom storage. In this case, you specify database name where sessions will be stored. Database name is set using -D parameter.

 

 

< ASPStateTempSessions 테이블, ASPStateTempApplications 테이블 내용 >







3. 쿼리 인스톨


쿼리 인스톨은 일반적으로 .NetFramwork 폴더에 있다.


저같은 경우는 C:\Windows\Microsoft.NET\Framework64\v4.0.30319 안에 시퀄문을 이용할겁니다.

해당 폴더에 보면


몇가지 .sql 로 끝나는 파일들이 있을텐데


그중 InstallSqlState.sql은 임시 DB에 인스톨, InstallPersistSqlState.sql 은 ASPState DB에 인스톨 할 파일들이다.


본인 설정에 맞게 사용하면 되는데, 저는  MS-SQL 서버에 등록했음으로 InstallPersistSqlState.sql 인스톨 할것입니다.


인스톨이레야. 쿼리분석기에 등록하시면 되는 간단한 방법이니 설명에서 제외.. ^^




잠이와서 간단하게 정리 후 차후 다시 정리하기로 하겠음 ㅠ.ㅠ.