0

I am trying to connect to the perforce server using below code. 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); line I am getting Object reference not set exception. Anything i m missing here.

  • Why aren't you passing the options to the `.Connect` call? – Matt Smith Oct 03 '13 at 13:12
  • I have tried passing options to the .connect call but I am getting the pServer null exception. – Sandeep Bhosale Oct 03 '13 at 14:07
  • Can you post a full callstack (including the part inside the p4.net `.Connect` call? – Matt Smith Oct 03 '13 at 14:10
  • After passing Options to .connect call I am getting below trace.at Perforce.P4.P4Server.RunCommand(String cmd, UInt32 cmdId, Boolean tagged, String[] args, Int32 argc) in c:\tmp\30745225\P4.NET\r13.2\p4api.net\p4api.net\P4Server.cs:line 1173 at Perforce.P4.Connection.Connect(Options options) in c:\tmp\30745225\P4.NET\r13.2\p4api.net\p4api.net\Connection.cs:line 233 at Perforce.Program.Main(String[] args) in C:\Documents and Settings\sandeep_bhosale\Desktop\C #\New Folder\Perforce\Perforce\Program.cs:line 111 Here line no 111 is con.Connect(opconnect); – Sandeep Bhosale Oct 03 '13 at 14:20
  • You can edit the question and add the additional call stack info there. – Matt Smith Oct 03 '13 at 14:21
  • After passing Options to .connect call I am getting below trace.at Perforce.P4.P4Server.RunCommand(String cmd, UInt32 cmdId, Boolean tagged, String[] args, Int32 argc) in c:\tmp\30745225\P4.NET\r13.2\p4api.net\p4api.net\P4Server.cs:line 1173 at Perforce.P4.Connection.Connect(Options options) in c:\tmp\30745225\P4.NET\r13.2\p4api.net\p4api.net\Connection.cs:line 233 at Perforce.Program.Main(String[] args) in C:\Documents and Settings\sandeep_bhosale\Desktop\C #\New Folder\Perforce\Perforce\Program.cs:line 111 Here line no 111 is con.Connect(opconnect); – Sandeep Bhosale Oct 03 '13 at 14:24

1 Answers1

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