2012-01-06 106 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