如何从我的应用程序在ASP.NET MVC中运行xp_cmdshell
问题描述:
在我的应用程序中,我正在将数据读取到数据库,然后我想要启动IntegrationSerivces以将数据导入多维数据集。这是我用来从SSMS启动它的命令:如何从我的应用程序在ASP.NET MVC中运行xp_cmdshell
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 ##”凭证是否存在并且包含有效信息。
而当我检查我没有证书数据库引擎 - >安全 - >证书。
我想用这样的命令:
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");
}
答
希望下面这个链接将能够帮助您。请让我知道它是否工作。
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]
我给予它
DefaultAppPool
见截图供大家参考: http://postimg.org/image/yqcf3vya1/
结果成功。我使用我的sa或管理员帐户通过SQL Server Management Studio登录到我的数据库来执行GRANT EXECUTE
。请尝试让我知道结果。谢谢
我写道:CREATE USER [IIS APPPOOL \ DefaultAppPool] FOR LOGIN [IIS APPPOOL \ DefaultAppPool];'我有错误:*用户,组或角色'IIS APPPOOL \ DefaultAppPool'已存在于当前数据库中* – Monic 2014-09-28 09:19:09
然后只需运行 就可以在xp_cmdshell TO [IIS APPPOOL \ DefaultAppPool]上执行GRANT EXECUTE; 结果是什么? – Hatjhie 2014-09-28 09:29:05
对不起,我用我的问题撤销而不是授予。错误如上,有问题。 – Monic 2014-09-28 09:32:26