0

在我的应用程序中,我正在将数据读取到数据库,然后我想启动集成服务以将数据导入多维数据集。这是我用来从 SSMS 启动它的命令:

execute master..xp_cmdshell 'dtexec /DTS "\MSDB\B_Costs" /SERVER . /CHECKPOINTING OFF /REPORTING V'

但是如何从我的应用程序中使用它?我一开始就有这个错误:
对象'xp_cmdshell',数据库'mssqlsystemresource',模式'sys'的EXECUTE权限被拒绝。

在使用这样的命令之后:

GRANT EXECUTE ON xp_cmdshell TO [IIS APPPOOL\DefaultAppPool]

我还有一个错误:
xp_cmdshell 代理帐户信息无法检索或无效。验证“##xp_cmdshell_proxy_account##”凭据是否存在并包含有效信息。

当我检查时,我在Database Engine -> Security -> Credentials中没有凭据。

我想使用这样的命令:

EXEC sp_xp_cmdshell_proxy_account 'IIS APPPOOL\DefaultAppPool', 'password'

但我不知道我应该在“密码”中写什么。有什么建议么?

这是我的 CubeController:

public ActionResult Index()
{            
    string sql = "execute master..xp_cmdshell 'dtexec /DTS \"\\MSDB\\B_Costs\" /SERVER . /CHECKPOINTING OFF /REPORTING V'";
    try
    {
        MyEntity.Database.ExecuteSqlCommand(sql);
    }
    catch (Exception e)
    {
        string error = "There was an error: <br />" + e.Message;
        TempData["Message"] = error;
    }

    return RedirectToAction("Index","Home");
}
4

1 回答 1

0

希望下面的这个链接能够帮助到你。请让我知道它是否有效。

http://www.databasejournal.com/features/mssql/xpcmdshell-for-non-system-admin-individuals.html

After you set up a proxy account your non-sysadmin logins might still not be able to use xp_cmdshell.    If you have not granted your non-sysadmin user EXECUTE permissions on xp_cmdshell you will get this error:

Msg 229, Level 14, State 5, Procedure xp_cmdshell, Line 1
The EXECUTE permission was denied on the object 'xp_cmdshell', database 'mssqlsystemresource', schema 'sys'.
To overcome this error all you have to do is make sure the non-sysadmin user has a database user in the master database and then GRANT your non-sysadmin user the rights to execute xp_cmdshell.  In order to do that all you have to do is run the following TSL code:

USE master;
GO
CREATE USER [MyDomain\Dorothy] FOR LOGIN [MyDomain\Dorothy];
GRANT EXECUTE ON xp_cmdshell TO [MyDomain\Dorothy];

就我而言,我尝试过:

GRANT EXECUTE ON xp_cmdshell TO [IIS APPPOOL\DefaultAppPool]

我授予它

默认应用程序池

请参阅屏幕截图以供参考: http: //postimg.org/image/yqcf3vya1/

结果是成功的。我使用我的 sa 或管理员帐户通过 SQL Server Management Studio 登录到我的数据库来执行GRANT EXECUTE. 请尝试让我知道结果。谢谢

于 2014-09-28T09:11:06.437 回答