Powered by Blogger.

Saturday, March 1, 2014

Implement SQL Server authentication in asp.net




To implement SQL Server authentication in asp.net, you have to change in web.config as well as in SQL server.

First go to C:\Windows\Microsoft.NET\Framework64\v4.0.30319 folder and execute InstallPersistSqlState.sql in the SQL Server. Just to let you know that it will create the ASPState database and the required stored procedures. Please check if you have .net 2.0 then check the corresponding folder.

Also if you do not want to create the default ASPState database then you can modify the script InstallPersistSqlState.sql and run that.

In the next step we have to modify the we.config for this. The main work is to change the session state mode, and the connection string.

If you are using windows authentication mode in SQL Server then you have to change web.config as below:
<sessionState  mode="SQLServer" sqlConnectionString="Data Source=BSAHOO3SQLEXPRESS;Integrated Security=SSPI;"
        cookieless="false"
        timeout="60"
/>
If you are using SQL Server authentication mode then you have to change the web.config as below:

<sessionState  mode="SQLServer" sqlConnectionString="Data Source=BSAHOO3SQLEXPRESS; User ID=your user id;Password=your password;"
           cookieless="false"
           timeout="120"
        />
If you are not using the default authentication and you are using in a custom database then you have to change the web.config as below:
<sessionState  mode="SQLServer" allowCustomSqlDatabase="true" sqlConnectionString="Data
Source=BSAHOO3SQLEXPRESS;database=customdbname;User ID=youruserid;Password=yourpassword;"
           cookieless="false"
           timeout="120"
        />



0 comments

Post a Comment