2013-10-03 72 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); 
相關問題