简体   繁体   English

使用p4.net API连接到Perforce服务器时获取异常

[英]Getting exception while connecting to perforce server using p4.net api

I am trying to connect to the perforce server using below code. 我正在尝试使用以下代码连接到perforce服务器。 I am getting Object reference not set to instance of an object exception. 我正在将对象引用未设置为对象异常的实例。

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

In con.Connect(null); 在con.Connect(null);中 line I am getting Object reference not set exception. 我正在获取对象引用未设置异常的行。 Anything im missing here. 我在这里什么都没有。

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM