自动修复与“ASPStateTempSessions”相关的 tempdb 错误

发布于 2024-10-05 03:49:43 字数 862 浏览 3 评论 0原文

根据此操作方法,我已在 XP-SP3 开发盒上成功为 SQL Server 2008 Express 配置 IIS保存 ASP.NET 会话状态信息。我只是使用 SQL Server,因为否则每次重新编译时,我都会丢失令人讨厌的会话状态(必须重新登录)。但是,我面临着一个烦人的问题,因为每次重新启动 SQL 时都会出现此错误,有时还有一两个其他非常相似的朋友:

The SELECT permission was denied on the object 'ASPStateTempSessions',
database 'tempdb', schema 'dbo'.

要修复该错误,我只需打开 Management Studio 并编辑登录名/dbo 的用户映射我正在 ASPState 数据库上使用,并将 tempdb 重新添加到该用户,并具有除拒绝之外的所有权限。显然,一旦获得了正确的权限,ASP.NET 就能够自动创建它使用的表。它只是无法运行 CreateTempTables 存储过程,直到存在正确的安全性。

问题... 有没有办法不必在每次重新启动 SQL Server 时都重新执行此操作?

我现在并不真正关心在重新启动时保留临时数据,但我不想仅仅为了让我的网络应用程序在本地主机上工作而执行此手动步骤,本地主机始终使用会话状态变量。我想人们可以在服务启动时诉诸 SQL Server 中的某种存储过程来完成这台机器的任务,而不必手动执行。我会接受这样的答案作为快速解决方案。但是,我还假设有更好的推荐配置或其他配置。在操作指南或 StackOverflow 上的其他地方没有看到这个问题的答案。

As per this how-to, I've successfully configured IIS on my XP-SP3 dev box for SQL Server 2008 Express to save ASP.NET session state information. I'm just using SQL Server because otherwise on every recompile, I was losing the session state which was obnoxious (having to re-login). But, I'm facing an annoying issue in that every time I restart SQL there's this error, and sometimes one or two other very similar friends:

The SELECT permission was denied on the object 'ASPStateTempSessions',
database 'tempdb', schema 'dbo'.

To fix the error, I just open Management Studio and edit the User Mapping for the login/dbo I'm using on the ASPState db, and re-add tempdb to that user with all but deny permissions. Apparently, once the right permissions are there, ASP.NET is able to automatically create the tables it uses. It just can't run that CreateTempTables sproc until the right security is there.

THE QUESTION...
Is there a way to not have to re-do this on every restart of the SQL Server?

I don't really care right now about keeping the temp data across restarts, but I would like to not have to go through this manual step just to get my web app working on localhost, which uses session state variables throughout. I suppose one could resort to some kind of stored procedure within SQL Server to accomplish the task for this machine when the service starts, to not have to do it manually. I'd accept such an answer as a quick fix. But, I'm also assuming there's a better recommended configuration or something. Not seeing an answer to this on the how-to guide or elsewhere here on StackOverflow.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

最丧也最甜 2024-10-12 03:49:43

这两个答案似乎都有效;但对于 Microsoft 的大多数事情,一切都在设置中...

首先使用以下命令卸载 ASPState 数据库:

aspnet_regsql –ssremove –E -S 。

注意:

-E 表示您要使用集成安全连接。

-S 告知要使用什么 SQL 服务器和 SQL 实例,以及“.” (点)指定默认本地实例

然后使用以下命令重新安装:

aspnet_regsql –ssadd –sstype p –E -S 。

注意:

sstype 有三个选项,t | p| c ...第一个“t”,告诉安装程序将所有存储过程托管在 ASPState 数据库中,并将所有数据托管在 tempdb 中。第二个选项“p”告诉安装程序将数据保存到 ASPState 数据库。最后一个选项“c”允许您指定不同的“自定义”数据库来保存会话状态数据。

如果使用“-sstype p”重新安装,则只需为建立连接的用户(在大多数情况下,IIS 中的应用程序池标识)向 ASPState 数据库提供数据读取器/数据写入器。

保留数据的另一个好处是,即使在服务重新启动后,会话状态也会保留。唯一的缺点是您需要确保代理清理作业定期修剪旧会话(默认情况下每分钟执行一次)。

重要提示

如果您正在运行集群,则必须保留会话数据。您唯一的选择是使用 sstype 'p' 或 'c'。

希望这能阐明这个问题!

Both answers seem valid; but with most things Microsoft, its all in the setup...

First uninstall the ASPState database by using the command:

aspnet_regsql –ssremove –E -S .

Note:

-E is to indicate you want to use integrated security connection.

-S informs what SQL server and SQL instance to use, and the "." (dot) specifies default local instance

Then re-install using the command:

aspnet_regsql –ssadd –sstype p –E -S .

Note:

The sstype has three options, t | p | c ... the first "t", tells the installer to host all stored procedures in the ASPState database, and all data in the tempdb. The second option "p" tells the installer to persist data to the ASPState database. The last option "c" allows you to specify a different 'custom' database to persist the session state data.

If you reinstall using the "-sstype p" you then need only to supply datareader/datawriter to the ASPState database for the user that's making the connection (in most cases, the application pool's identity in IIS).

The added benefit of persisting the data is that session state is retained even after a restart of the service. The only drawback is that you need to ensure the agent cleanup job is pruning old sessions regularly (it does this by default, every minute).

Important:

If you are running a cluster, you must persist session data. You're only option is to use sstype 'p' or 'c'.

Hope this sheds light on the issue!

情绪失控 2024-10-12 03:49:43

根据记录,我确实找到了一种方法来做到这一点

问题是每次服务重新启动时都会从模型数据库重新创建临时数据库。该解决方案的要点是创建一个执行该作业的存储过程,然后使该过程在启动时运行。

源代码(归功于上面的链接)如下:

use master
go

-- remove an old version
drop proc AddAppTempDBOwner
go

-- the sp
create proc AddAppTempDBOwner as
declare @sql varchar(200)
select @sql = 'use tempdb' + char(13) + 'exec sp_addrolemember ''db_owner'', ''app'''
exec (@sql)
go

-- add it to the startup
exec sp_procoption 'AddAppTempDBOwner', 'startup', 'true'
go

For the record, I did find a way to do this.

The issue is that the tempdb is recreated from the model db each time the service restarts. The gist of the solution is to create a stored procedure that does the job, and then make that procedure run at startup.

Source code (credit to the link above) is as follows:

use master
go

-- remove an old version
drop proc AddAppTempDBOwner
go

-- the sp
create proc AddAppTempDBOwner as
declare @sql varchar(200)
select @sql = 'use tempdb' + char(13) + 'exec sp_addrolemember ''db_owner'', ''app'''
exec (@sql)
go

-- add it to the startup
exec sp_procoption 'AddAppTempDBOwner', 'startup', 'true'
go
半世晨晓 2024-10-12 03:49:43

干得好,找到了最奇怪的方法来做到这一点。

正确答案如下:

use master
go  
EXEC sp_configure 'Cross DB Ownership Chaining', '1'    
go    
RECONFIGURE    
go    
EXEC sp_dboption 'ASPState', 'db chaining', 'true'    
go

Well done for finding the strangest way possible to do this.

The correct answer is as follows:

use master
go  
EXEC sp_configure 'Cross DB Ownership Chaining', '1'    
go    
RECONFIGURE    
go    
EXEC sp_dboption 'ASPState', 'db chaining', 'true'    
go
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文