2013-10-03 55 views
0

我试图使用下面的代码连接到perforce服务器。我得到的对象引用未设置为对象异常的实例。使用p4.net api连接到perforce服务器时出现异常

String conStr = "perforce2.ges.abc.com:1666"; 
String user = "John_Smith"; 
String password = "[email protected]"; 
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); 

在con.Connect(null)中;行我得到对象引用没有设置异常。我在这里失踪的任何东西。

+0

为什么不将选项传递给'.Connect'调用? –

+0

我曾尝试将选项传递给.connect调用,但我得到pServer null异常。 –

+0

您可以发布一个完整的调用堆栈(包括p4.net'.Connect'调用中的部分吗? –

回答

0
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); 
相关问题