0

I am facing the problem that I need multiple ASPState databases for different ASP.NET projects on the same db server, beacuse I really want to share the Session State db for those projects.

After doing some research (e.g. here and here), I created the first database using following command:

aspnet_regsql.exe -E -S "fooserver" -ssadd -sstype "c" -d "FooProject.Sessions"

In the <system.web> section of my web.config, I have following entry:

<sessionState mode="SQLServer" allowCustomSqlDatabase="true" sqlConnectionString="data source=fooserver;integrated security=True;database=FooProject.Sessions" cookieless="false" timeout="60" />

But when I try to Access the Session property of my controller context, I get an NullReferenceException (Session is null).

When I set the allowCustomSqlDatabase attribute of the configuration entry to false, everything works fine.

What did I do wrong? It seems like no one else has this problem Thank you in advance!

PS: Just tell me if I need to provide more information.

ˈvɔlə
  • 9,204
  • 10
  • 63
  • 89
  • 1
    Did you really name your database with a `.` in it? – Aaron Bertrand Oct 24 '18 at 11:04
  • @AaronBertrand Yes, triple checked the name. Every database on the server has at least one dot in its name. – ˈvɔlə Oct 24 '18 at 11:16
  • Well this is not recommended because many tools and libraries won't know to use square brackets around the name. You could try that (`database=[FooProject.Sessions]`), but I also recommend trying this technique against a database that *does not* use bad naming conventions. – Aaron Bertrand Oct 24 '18 at 11:20
  • @AaronBertrand I tried enclosing the database name with square brackets, but without success. – ˈvɔlə Oct 24 '18 at 11:29
  • I didn't have high confidence that would work. I still think you should try a simpler *and legal* database name, like `FooProject_Sessions`. – Aaron Bertrand Oct 24 '18 at 11:30
  • @AaronBertrand I tried the name `CustomName` (without any special characters). I still receive the same error: `System.Web.Mvc.Controller.Session.get returned null.` Thank you very much for your help! – ˈvɔlə Oct 24 '18 at 11:33

0 Answers0