2012-01-06 100 views
1

我正在使用p4api.net編寫VS C#應用程序來訪問P4服務器。 P4V應用程序通過給定的用戶/密碼訪問存款處罰款。使用p4api.net API,代碼執行的connect()&登錄()使用從表單中傳遞的服務器/用戶/密碼字符串無一例外方法:Perforce P4 .NET API返回Perforce密碼(P4PASSWD)無效

rep.Connection.Connect(options); 
    rep.Connection.Login(password, options); 

下面是實際的代碼:

String conStr = mServerConnection.Text; 
String user = mUserText.Text; 
String password = mPaswordTxt.Text; 
try 
{ 
    Server server = new Server(new ServerAddress(conStr)); 
    rep = new Repository(server); 
    rep.Connection.UserName = user; 
    Options options = new Options(); 
    Options["Password"] = password; 
    rep.Connection.Client = new Client(); 
    rep.Connection.Connect(options); 
    rep.Connection.Login(password, options); 
} 
catch (Exception ex) 
{ 
    rep = null; 
    MessageBox.Show(ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); 
} 

但是在另一次調用訪問P4「// depot」根目錄時,API調用_repository.GetDepotDirs()將返回「Perforce Password(P4PASSWD)無效或未設置」異常。請看下面的代碼:

public bool Expand() 
{ 
    if (String.IsNullOrEmpty(depotPath)) 
    return false; 
    // if we have the depot path, get a list of the subdirectories from the depot 
    if (!String.IsNullOrEmpty(depotPath)) 
    { 
    IList<string> subdirs = _repository.GetDepotDirs(null, String.Format("{0}/*", depotPath)); 

我讀的地方,我需要讓我這樣做,在DOS提示符下設置環境變量P4TICKETS:

p4 set P4TICKETS=C:\Documents and Settings\my_user_name 

但這並沒有解決問題。我會很感激你的幫助。謝謝。

回答

2

在安全級別3,直接給密碼連接不起作用。因此,我趕上了後來的例外,然後致電登錄。在這一點上,你可以在選項保存Credential.Ticket通過登錄爲未來的呼叫連接返回,下票務場。

我不知道爲什麼後續的命令調用失敗了,除非您的故障單以某種方式過期,或者您實際上斷開了與服務器的連接。在隨後的命令之前,您可以隨時撥打連接

+1

謝謝你的幫助。我刪除了「選項[」密碼「] =密碼;」我可以登錄到P4存儲庫。 – Kevin 2012-01-13 00:49:52