使用 p4.net API 连接到 perforce 服务器时出现异常

本文关键字:服务器 异常 perforce p4 net API 连接 使用 | 更新日期: 2023-09-27 18:33:55

我正在尝试使用以下代码连接到perforce服务器。我得到的对象引用未设置为对象异常的实例。

String conStr = "perforce2.ges.abc.com:1666";
String user = "John_Smith";
String password = "abc@1234";
String ws_client = @"E:'Perforce'Automation'Technical Books";
ServerAddress adr = new ServerAddress(conStr);
Server serv = new Server(adr);
P4Server ser = new P4Server(conStr, user, password, ws_client);
Connection con = new Connection(serv);
Options opconnect = new Options();
opconnect.Add("-p", "");
con.SetClient(ws_client);
con.Connect(null);
con.Login(password);

在康。连接(空);行我正在得到对象引用未设置异常。我在这里缺少的任何东西。

使用 p4.net API 连接到 perforce 服务器时出现异常

The issue got resolved. I have used below code
// define the server, repository and connection
                Server server = new Server(new ServerAddress(uri));
                Repository rep = new Repository(server);
                Connection con = rep.Connection;

                // use the connection varaibles for this connection
                con.UserName = user;
                con.Client = new Client();
                con.Client.Name = ws_client;
                Options opconnect = new Options();
                //opconnect.Add("-p", "");
                opconnect.Add("-p", password);

                // connect to the server
                con.Connect(opconnect);
                //con.Connect(null);
                con.Login(password);