运行调用另一个数据库上的存储过程的触发器
我们希望在一个数据库 (A) 上运行一个触发器,该触发器调用另一个数据库 (B) 上的存储过程。
CREATE TRIGGER trg_A ON TableA FOR INSERT AS BEGIN EXEC DatabaseB.dbo.stp_B END
我们希望在 DatabaseA 上以 LoginA 和 UserA 的身份执行此操作。我们还在 DatabaseB 上有 LoginB 和 UserB。
我们怎样才能做到这一点?
目前我们收到此错误消息
The server principal "..." is not able to access the database "DatabaseB" under the current security context.
我们已尝试 WITH EXECUTE AS 'UserB'
,但没有成功。
We would like to run a trigger on one database (A) that calls a stored procedure on another database (B).
CREATE TRIGGER trg_A ON TableA FOR INSERT AS BEGIN EXEC DatabaseB.dbo.stp_B END
We would like to do this as LoginA with UserA on DatabaseA. We also have LoginB with UserB on DatabaseB.
How can we accomplish this?
Currently we get this error message
The server principal "..." is not able to access the database "DatabaseB" under the current security context.
We have tried WITH EXECUTE AS 'UserB'
, without luck.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
有趣的问题。你这个书呆子狙击了我。我测试了很多不同的场景。
这些失败:
我可以让触发器工作的唯一方法是在 DatabaseB 中为 LoginA 创建一个用户,并授予执行 DatabaseB 存储过程的权限。
Interesting question. You nerd-sniped me. I tested a bunch of different scenarios.
These failed:
The only way I could get the trigger to work was to create a user in DatabaseB for LoginA and grant permissions to execute the DatabaseB stored procedure.