Try restarting the app or recycling the applicaton pool after pointing to the new database. There may be some startup code that has to run.
Somewhere the Application object has to be loaded with an object with a key of "pageSecurity", and startup is the most likely place for that to happen. Since it's not happening, the code in Main.master.cs (the code file for the main ASP.NET master page, which is sort of like a layout template) is blowing up.