且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

如何授予用户从 SQL Server 中的存储过程内部访问数据库的权限 - 获取错误:过程中不允许使用数据库语句

更新时间:2022-05-17 22:19:03

您需要将所有命令放在一个动态 SQL 中并运行它,因为当第一个包含 USE 命令的动态 SQL 被执行时,USE DATABASE 将退出.

You need to put all the command in one dynamic SQL and run it because the USE DATABASE will be out of when the first dynamic SQL containing the USE command is executed.

因此,删除除最后一个之外的所有 EXEC,并连接@sqlcmd 中的所有 SQL.运行 EXEC @sqlcmd.

So, remove all the EXEC except the last one, and concat all the SQL in @sqlcmd. Run EXEC the @sqlcmd.