【问题标题】:Perforce P4 .NET API returns Perforce Password (P4PASSWD) invalidPerforce P4 .NET API 返回 Perforce 密码 (P4PASSWD) 无效
【发布时间】:2012-01-06 23:17:09
【问题描述】:

我正在编写一个使用 p4api.net 访问 P4 服务器的 VS C# 应用程序。 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) invalid or unset”异常。请看下面的代码:

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

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

【问题讨论】:

    标签: .net api perforce p4api.net


    【解决方案1】:

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

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

    【讨论】:

    • 感谢您的帮助。我删除了“选项 [“密码”] = 密码;”这一行我可以登录到 P4 存储库。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-02-02
    • 2015-03-11
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多