1

I have a working web site that is running in IIS on Windows Server 2008 R2 and using SQL Server 2008 Express. I am trying to port the entire site to Windows Server 2022 using SQL Server 2019 Express.

I moved all the code, set up all the permissions like the original set up, but I just can not get the database connection to work. I am using the same connection string, so this is leading me to a permissions issues on the database. But with the use of localDB, I am not sure if there is an issue there.

I previously used the IIS APPPOOL\APP PoolName to access the database, so I was hoping this would continue to work. This does not appear to be the case at the moment.

The error I am getting though looks like the old way will not work:

Parser Error Message: The sqlConnectionString attribute or the connection string it refers to cannot contain the connection options 'Database', 'Initial Catalog' or 'AttachDbFileName'. In order to allow this, allowCustomSqlDatabase attribute must be set to true and the application needs to be granted unrestricted SqlClientPermission. Please check with your administrator if the application does not have this permission.

The connection string currently in use is:

Data Source=.\SQLEXPRESS;AttachDbFilename=|DataDirectory|\db_name_chgd.mdf;Integrated Security=True;MultipleActiveResultSets=True

I have not been able to find any new info on connecting to a SQL Server Express local database on the same web server. I am NOT using the localDB, but if I need to change to that sort of a config, I would like to read up on the required changes.

marc_s
  • 732,580
  • 175
  • 1,330
  • 1,459
htm11h
  • 1,739
  • 8
  • 47
  • 104
  • Try to set the `allowCustomSqlDatabase="true"`, If it still doesn't work, you can refer to the solution in this link: [https://stackoverflow.com/questions/27901376/iis-sql-server-session-state-error](https://stackoverflow.com/questions/27901376/iis-sql-server-session-state-error). – samwu May 03 '22 at 02:40
  • I tried adding that property but it did not change anything. – htm11h May 03 '22 at 14:28

1 Answers1

0

So the solution that worked for me is the following.

In the web.config file I commented out the SessionState tag....

    <!--    <sessionState allowCustomSqlDatabase="true" mode="SQLServer" sqlConnectionString="ConnectionStringMyConection" sqlCommandTimeout="30" cookieless="UseUri" timeout="20">
    </sessionState> -->

Everything worked fine after that.

htm11h
  • 1,739
  • 8
  • 47
  • 104