Perforce P4 .NET API返回Perforce密码(P4PASSWD)无效

时间:2012-01-06 23:17:09

标签: .net api perforce p4api.net

我正在使用p4api.net编写一个VS C#应用程序来访问P4服务器。 P4V应用程序使用给定的用户/密码访问存托罚款。使用p4api.net API,代码执行Connect()&使用从表单传入的服务器/用户/密码字符串,无异常的Login()方法:

  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));

我在某处读到了我需要设置环境变量P4TICKETS所以我在DOS提示符中这样做了:

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

但这并没有解决问题。我很感激你的帮助。感谢。

1 个答案:

答案 0 :(得分:2)

在安全级别3,直接将密码提供给 Connect 并不起作用。所以我捕获了后续异常,然后调用 Login 。此时,您可以保存登录返回的 Credential.Ticket ,以便将来调用 Ticket 下的 Connect 选项中的字段

我不确定为什么后续的命令调用会失败,除非您的票证以某种方式到期,或者您实际上已从服务器断开连接。您可以在后续命令之前再次调用 Connect

相关问题