2014-09-28 104 views
0

在我的應用程序中,我正在將數據讀取到數據庫,然後我想要啓動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"); 
} 

回答

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] 

我給予它

DefaultAppPool

見截圖供大家參考: http://postimg.org/image/yqcf3vya1/

結果成功。我使用我的sa或管理員帳戶通過SQL Server Management Studio登錄到我的數據庫來執行GRANT EXECUTE。請嘗試讓我知道結果。謝謝

+0

我寫道:CREATE USER [IIS APPPOOL \ DefaultAppPool] FOR LOGIN [IIS APPPOOL \ DefaultAppPool];'我有錯誤:*用戶,組或角色'IIS APPPOOL \ DefaultAppPool'已存在於當前數據庫中* – Monic 2014-09-28 09:19:09

+0

然後只需運行 就可以在xp_cmdshell TO [IIS APPPOOL \ DefaultAppPool]上執行GRANT EXECUTE; 結果是什麼? – Hatjhie 2014-09-28 09:29:05

+0

對不起,我用我的問題撤銷而不是授予。錯誤如上,有問題。 – Monic 2014-09-28 09:32:26

相關問題