SessionState web.config SQL 2008 custom database

Posted on 2009-02-24
Last Modified: 2012-05-06
I'm trying to use SQL 2008 for sessionstate, but keep getting the Login Failed exception...
[SqlException (0x80131904): Cannot open database "bSession-sd" requested by the login. The login failed. Login failed for user '********'.]

I've setup following web.config...
                sqlConnectionString="data source=SQL01-NODE1; Initial Catalog=bSessions-sd; user id=********; password=********; Failover Partner=SQL01-NODE2;"
                cookieless="false" allowCustomSqlDatabase="true"
                timeout="20" />

If I try connecting through Studion Management, with the same credentials, I'm granted full access.
The user account on the database is db_owner

What could possibly be the issue here?
Question by:tarasbredel
    LVL 14

    Expert Comment

    Try making sure that the default database for the user account that you are connecting with is the database that the user has permission to access.

    Also how did you set up the session database did you use ASPNET_REGSQL.EXE, see the following website

    Author Comment

    Currently the user has master set as default database.
    Our ISP installed the session database using REGSQL in persisten mode.
    We only have one user for both the session database and the actualt database, is that a problem? Does it have to be a distinct user for each?
    LVL 14

    Expert Comment

    Using a distinct user for each would be better from a security point of view, but it is not essential.

    I think your problem is that your user account does not have permission to access its default database.

    When a user first connects to SQL Server it connects to its default database, and since your user is trying connect to the master database without permissions to access the master database you are getting the error.

    Try changing the user's default database to bSession-sd

    Author Comment

    Might be, though, I have no issues accessing my actual database with that user account (neither from my web app or from Studio Management).
    it is only the session database that is bugging from the app

    Accepted Solution

    It seems that the ISP had installed the session database wrong.
    He had used the -sstype p switch, created the ASPState database, and then renamed it to bSession_sd

    The problem is that you cannot use the -sstype p and -d dbname switches together. It has to be -sstype c and -d dbname together.
    But then the session database is not persistent.
    Then again that is nt a problem, since we are using mirrored SQL.

    Btw. The login has master set as default since it cannot be altered on the failover partner unless you flip the mirror first.

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    IT, Stop Being Called Into Every Meeting

    Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

    If you have heard of RFC822 date formats, they can be quite a challenge in SQL Server. RFC822 is an Internet standard format for email message headers, including all dates within those headers. The RFC822 protocols are available in detail at:   ht…
    Occasionally there is a need to clean table columns, especially if you have inherited legacy data. There are obviously many ways to accomplish that, including elaborate UPDATE queries with anywhere from one to numerous REPLACE functions (even within…
    It is a freely distributed piece of software for such tasks as photo retouching, image composition and image authoring. It works on many operating systems, in many languages.
    This video gives you a great overview about bandwidth monitoring with SNMP and WMI with our network monitoring solution PRTG Network Monitor ( If you're looking for how to monitor bandwidth using netflow or packet s…

    761 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    12 Experts available now in Live!

    Get 1:1 Help Now