Perforce P4 .NET API 返回 Perforce 密码 (P4PASSWD) 无效
我正在编写一个 VS C# 应用程序,使用 p4api.net 访问 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 密码 (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
但这并没有解决问题。我很感激你的帮助。
I'm writing a VS C# app using the p4api.net to access a P4 server. The P4V app accesses the depository fine with a given user/password. Using p4api.net API, the code executed the Connect()
and Login()
methods without exception using server/user/password strings passed in from a form:
rep.Connection.Connect(options);
rep.Connection.Login(password, options);
Below is the actual code:
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);
}
However during another call to access the P4 "//depot" root directory, the API call _repository.GetDepotDirs() would return "Perforce Password (P4PASSWD) invalid or unset" exception. Please see code below:
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));
I read somewhere that I need to set the environmental variable P4TICKETS so I did that in a DOS prompt:
p4 set P4TICKETS=C:\Documents and Settings\my_user_name
but this didn't resolve the problem. I'd appreciate your help.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
在安全级别 3 下,直接向 Connect 提供密码是行不通的。所以我捕获了随后的异常,然后调用Login。此时,您可以在 Ticket 下保存 Login 返回的 Credential.Ticket,以供将来调用 Connect 选项中的字段。
我不确定为什么后续命令调用对您来说失败,除非您的票证以某种方式过期,或者您实际上已与服务器断开连接。您始终可以在执行后续命令之前再次调用Connect。
At security level 3, giving the password directly to Connect doesn't work. So I catch the subsequent exception and then call Login. At that point you can save the Credential.Ticket returned by Login for future calls to Connect, under the Ticket field in the options.
I'm not sure why the subsequent command calls are failing for you, unless your ticket somehow expires, or you've actually disconnected from the server. You can always call Connect again before subsequent commands.