Search code examples
c#asp.netperforcep4api.net

Perforce API (P4API.NET): P4Exception: Too many trys to get lock p4tickets.txt.lck


I wrote an .NET Web Application to make Perforce connection but keeps getting below error message. This issue only occurs when I publish into the server. When I run this application in the local machine, it works perfectly fine but in the server, it looks like it keeps failing when I try to login.

[P4Exception: Fatal client error; disconnecting! Operation 'client-SetPassword' failed. Too many trys to get lock C:\WINDOWS\system32\config\systemprofile\p4tickets.txt.lck. ]

Perforce.P4.P4Exception.Throw(String cmd, String[] args, P4ClientErrorList errors, P4ClientInfoMessageList details) in c:\tmp\104564385\P4.NET\r19.2\p4api.net\p4api.net\P4Exception.cs:393
Perforce.P4.P4Server.RunCommand(String cmd, UInt32 cmdId, Boolean tagged, String[] args, Int32 argc) in c:\tmp\104564385\P4.NET\r19.2\p4api.net\p4api.net\P4Server.cs:1106
Perforce.P4.P4Command.RunInt(StringList flags) in c:\tmp\104564385\P4.NET\r19.2\p4api.net\p4api.net\P4Command.cs:503
Perforce.P4.P4CommandResult..ctor(P4Command cmd, StringList flags) in c:\tmp\104564385\P4.NET\r19.2\p4api.net\p4api.net\P4CommandResult.cs:142 Perforce.P4.P4Command.Run(StringList flags) in c:\tmp\104564385\P4.NET\r19.2\p4api.net\p4api.net\P4Command.cs:373
Perforce.P4.Connection.Login(String password, Boolean allHostTicket) in c:\tmp\104564385\P4.NET\r19.2\p4api.net\p4api.net\Connection.cs:1071

Here is my partial code for connect/login

    private void Connect(Connection con)
    {
        con.UserName = username;
        if (con.Client == null)
        {
            con.Client = new Client();
            con.Client.Name = "";
        }
        con.Connect(null);
        con.Login(password);
    }

I've been also trying to use P4.Option and store password inside here and pass it to con.Connect() as a parameter instead of using con.Login() but it had the same issue (only when I published to the server.)

Can someone please help to solve this issue?


Solution

  • This looks like a permission issue on the server filesystem. By default, login tickets go in %USERPROFILE%/p4tickets. Your app is running as the System user, which doesn't have a normal Users directory, so instead it's trying to write its tickets to the system folder (which the app might not actually have permission to write to).

    Typically I'd solve this by using p4 login -p to avoid the need for a tickets file on the actual filesystem. The other potential fix would be to explicitly set the ticket file location to a path that you're sure will be writable.