Jump to content

P4API.NET Connecting to Server

  • Please log in to reply
No replies to this topic

#1 Buffy



  • Members
  • Pip
  • 1 posts

Posted 12 May 2012 - 10:44 PM

Using code that is basically identical to the gui example distributed with the p4api.net library, I am consistently running into the exception, "Your session has expired, please login again." from both the call to Repository.Connection.Connect(options) (both with and without the password specified as an option) as well as in calling Repository.Connection.Login(password,options,username). I have seen references to this being the normal way to detect whether the user is logged in (i.e. an exception when calling Connect()), so I have tried catching this error, but get the same exception when trying to then call Login().

	string p4ServerPort= "";
	string p4UserName = "jane";
	string p4Password = "foo";
	string p4Error = "";
	// define the server, repository and connection
	Server p4server = new Server(new ServerAddress(p4ServerPort));
	Repository p4repository = new Repository(p4server);
	Credential p4cred = null;
	Client p4client = new Client();
	p4repository.Connection.Client = p4client;

	p4repository.Connection.UserName = p4UserName;
	Options p4options = new Options();
	p4options["Password"] = p4Password;

		if (p4repository.Connection.Connect(p4options))		// if not logged in here, will get a P4Exception and will try to login in the following catch
			; // Connected
			p4cred = p4repository.Connection.Login(p4Password, p4options, p4UserName);	// never executed because we always get an exception from the call to Connect()
			; // not Connected
	catch (P4Exception ex)
		if (ex.Message.Contains("login again"))
			p4Error = "Perforce Connection Connect error Not logged in: " + ex.Message; // just drop through to the next try block where we try to login
			p4Error = "Perforce Connection Connect error: " + ex.Message);
		p4repository.Connection.ErrorList.Clear();	// clear the error for the connection to ensure this is not contaminating the following Login call

		p4options.Clear();	// same exception with or without the Password option set
		p4cred = p4repository.Connection.Login(p4Password, p4options, p4UserName);	// This is currently always producing a "Your session has expired, please login again." exception
	catch (P4Exception ex)
		p4Error = "Perforce Connection Login error: " + ex.Message);

Stepping through the library, I can see that when execution gets to calling the login command on line 471 of Connection.cs, that all of the parameters needed (host, username, password) are set correctly, but the code below it in the P4 library produces the "Your session has expired..." exception.

I am using the 4/27/2012 release of p4api.net and am building it myself in order to be able to trace while debugging, but I get identical results when using the pre-built binaries.

The one twist in my configuration is that I do *not* have the P4PASSWD environment variable set, as I have more than one installation I'm connecting to and I want my program to deal with this without setting the environment variables.

Any comments or suggestions on what might be going wrong would be greatly appreciated.

0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users