系统规格
Microsoft SQL Server Management Studio 9.00.4035.00
Microsoft Analysis Services Client Tools 2005.090.4035.00
Microsoft Data Access Components (MDAC) 2000.085.1132.00
(xpsp.080413-0852)
Microsoft MSXML 2.6 3.0 4.0 5.0 6.0
Microsoft Internet Explorer 7.0.5730.13
Microsoft .NET Framework 2.0.50727.1433
Operating System 5.1.2600
在名为BHAVMSQL02的 SQL Server 2005 上,我有两个数据库Mattercentre_dev和CMSNET_DEV。Mattercentre_dev有一个存储过程,它从CMSNET_DEV中的表构建一个列表。存储过程看起来像这样......
USE [Mattercentre_dev]
GO
/****** Object: StoredProcedure [dbo].[UDSPRBHPRIMBUSTYPE]
Script Date:02/12/2009 10:18:10 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER OFF
GO
ALTER PROCEDURE [dbo].[UDSPRBHPRIMBUSTYPE] WITH EXECUTE AS 'Readuser' AS
DECLARE @SERVERNAME nvarchar(30)
DECLARE @DBASE nvarchar(30)
DECLARE @SQL nvarchar(2000)
SET @SERVERNAME = Convert(nvarchar,
(SELECT spData FROM dbSpecificData WHERE spLookup = 'CMSSERVER'))
SET @DBASE = Convert(nvarchar,
(SELECT spData FROM dbSpecificData WHERE spLookup = 'CMSDBNAME'))
SET @SQL =
'SELECT
null as Code
, ''(not specified)'' as Description
UNION SELECT
clnt_cat_code as Code
, clnt_cat_desc as Description
FROM '
+ @SERVERNAME + '.' + @DBASE + '.dbo.hbl_clnt_cat
WHERE
inactive = ''N''
ORDER BY Description'
PRINT @SQL
EXECUTE sp_executeSQL @SQL
@SERVERNAME == 'BHAVMSQL02'
@DBASE == 'CMSNET_DEV'
执行存储过程时出现以下错误消息...
The server principal "ReadUser" is not able to access the database "CMSNET_DEV" under the current security context.
谷歌搜索错误消息后,我进行了以下修复...
- 从 BHAVMSQL02 -> Databases -> Mattercentre_dev -> Security -> Users 中删除了用户 ReadUser
从 BHAVMSQL02 设置 ReadUser -> 安全 -> 使用以下设置登录...
通用
登录名 - readUser
密码 - xxxxxxxxxxxx
Confirm - xxxxxxxxxxxx
Default db - master
default lg - British English
Everything Else - Unset仅限服务器角色的公共集
用户映射 CMSNET_DEV - ReadUser - dbo
数据库角色成员资格 - db_owner、publicMattercentre_dev - ReadUser - dbo
数据库角色成员资格 - db_owner, public
然后我运行以下脚本...
ALTER DATABASE CMSNET_DEV SET TRUSTWORTHY ON
GO
ALTER DATABASE mattercentre_dev SET TRUSTWORTHY ON
GO
我重新运行存储过程并再次执行它,我仍然有相同的错误消息。
我在 Stack Overflow 中查找了这个问题,建议的解决方案与我自己的类似。