2013-10-27 56 views
1

設置的密碼在服務器中失敗。當調用SetPassword時,我收到錯誤:「異常已被調用的目標拋出。」

Exception.message: Exception has been thrown by the target of an invocation at System.DirectoryServices.DirectoryEntry.Invoke(String methodName, Object[] args)

那麼,爲什麼將這個呼叫工作從本地(開發者)的機器,但是從服務器不 工作?

 `  DirectoryEntry entry = new DirectoryEntry(..); 
      entry.AuthenticationType = AuthenticationTypes.Secure; 
      DirectorySearcher search = new DirectorySearcher(entry); 
      search.Filter = "(&(sAMAccountName=" + userName_ + "))"; 
      DirectoryEntry userEntry = search.FindAll()[0].GetDirectoryEntry(); 
      userEntry.Invoke("SetPassword", new object[] {[email protected]#" 
      userEntry.CommitChanges();` 

編輯:的InnerException是{ 「RPC服務器不可用(從HRESULT異常:0x800706BA)。」}

+1

什麼是InnerException? – SLaks

+0

如果沒有內部異常,TargetInvocationExceptions通常很沒用。這可能與您的調用有關,因爲它是TargetInvocationException。 –

+0

http://blogs.msdn.com/b/alejacma/archive/2008/04/29/changepassword-method-may-fail-with-targetinvocationexception-net.aspx –

回答

0

是否在同一帳戶下的應用運行在兩種環境?如果沒有,那麼根據你的問題,這可能是一個權限問題

+0

什麼樣的權限問題?如果有權限問題,它是如何在本地機器上工作的? –

+0

@EmreYardımcı只有當程序以管理員身份運行時,它才能調用'SetPassword',如果您執行'以管理員身份運行'以啓動程序,那麼它會起作用嗎?我會把[程序的清單](http://stackoverflow.com/questions/2818179/how-to-force-my-net-app-to-run-as-administrator-on-windows-7)文件' '所以它會爲你做這個請求。 –

+0

我真的嘗試了,不起作用Scott .. –

相關問題