简体   繁体   English

p4.net 无法连接 Perforce

[英]p4.net cannot connect Perforce

I am using p4.net API to generate some reports from the metadata.我正在使用 p4.net API 从元数据中生成一些报告。

In one of the reports, I need to generate then number of the changes lines for each changeset report.在其中一份报告中,我需要为每个变更集报告生成变更行数。

As a reporting tool, I am using MS SQL Reporting services 2008, and I have written a custom dll that uses p4.net API to calculate the number of changed lines.作为报告工具,我使用的是 MS SQL Reporting services 2008,并且我编写了一个自定义 dll,它使用 p4.net API 来计算更改的行数。 it works on the local without any problem.它在本地工作没有任何问题。 However, when I run the code on the server, it calculates let's say first %20 part then starts throwing Unable to connect to the Perforce Server.但是,当我在服务器上运行代码时,它会计算假设第一个 %20 部分,然后开始抛出无法连接到 Perforce 服务器。 Unable to connect to Perforce!无法连接到 Perforce! exception.例外。

I try same credentials on the local, it works.. I use commandline with same credentials on the server, it works.我在本地尝试相同的凭据,它可以工作。我在服务器上使用具有相同凭据的命令行,它可以工作。

Could anyone help me with that please, if encountered before?如果以前遇到过,有人可以帮我吗?

Here is the code I use.这是我使用的代码。 If needed如果需要的话

 public static class PerforceLib
{

    public static P4Connection p4conn = null;

    private static void  CheckConn()
    {
        try
        {
            if (p4conn == null)
            {

                p4conn = new P4Connection();
                p4conn.Port = "address";
                p4conn.User = "user";
                p4conn.Password = "pwd*";
                p4conn.Connect();
                p4conn.Login("pwd");
            }
            else if (p4conn != null)
            { 
                if(!p4conn.IsValidConnection(true, false))
                {
                    Log("Check CONN : Connection is not valid, reconnecting");
                    p4conn.Login("pwd*");
                }
            }

        }
        catch (Exception ex )
        {
            Log(ex.Message);
        }

    }



    public static int DiffByChangeSetNumber(string ChangeSetNumber)
    {
        try
        {
                CheckConn();
                P4Record set =   p4conn.Run("describe", "-s",ChangeSetNumber)[0];
                string[] files = set.ArrayFields["depotFile"].ToArray<string>();
                string[] revs = set.ArrayFields["rev"].ToArray<string>();
                string[] actions = set.ArrayFields["action"].ToArray<string>();


                int totalChanges = 0;
                List<P4File> lstFiles = new List<P4File>();


                for (int i = 0; i < files.Count(); i++)
                {
                    if (actions[i].ToString() == "edit")
                        lstFiles.Add(new P4File() { DepotFile = files[i].ToString(), Revision = revs[i].ToString(), Action = actions[i].ToString() });
                }



                foreach (var item in lstFiles)
                {
                    if (item.Revision != "1")
                    {
                        string firstfile = string.Format("{0}#{1}", item.DepotFile, (int.Parse(item.Revision) - 1).ToString());
                        string secondfile = string.Format("{0}#{1}", item.DepotFile, item.Revision);
                        P4UnParsedRecordSet rec = p4conn.RunUnParsed("diff2", "-ds", firstfile, secondfile);
                        if (rec.Messages.Count() > 1)
                        {
                            totalChanges = PerforceUtil.GetDiffResults(rec.Messages[1].ToString(), item.DepotFile);
                        }
                    }
                }
                GC.SuppressFinalize(lstFiles);
                Log(string.Format("{0} / {1}", ChangeSetNumber,totalChanges.ToString() + Environment.NewLine));
                return totalChanges;
            }
            catch (Exception ex)
            {
                Log(ex.Message + Environment.NewLine);
                return -1;
            }
    }


}

your help will be appreciated您的帮助将不胜感激

Many thanks非常感谢

I have solved this issue.我已经解决了这个问题。 we identified that the code is circling through the ephemeral port range in around two minutes.我们发现代码在大约两分钟内在临时端口范围内循环。 once it reaches the maximum ephemeral port, it was trying to use same port again.一旦达到最大临时端口,它就会再次尝试使用相同的端口。 Due to each perforce command creates a new socket, available ports were running out after it processed about 1000 changesets.由于每个 perforce 命令都会创建一个新套接字,因此在处理了大约 1000 个变更集后,可用端口就用完了。 I have set the ReservedPorts value of HKLM\SYSTEM\CurrentControlSet\Services\Tcpip\Parameters default(1433,143) that gave me larger range of ephemeral port.我已经设置了 HKLM\SYSTEM\CurrentControlSet\Services\Tcpip\Parameters default(1433,143) 的 ReservedPorts 值,这给了我更大范围的临时端口。

and also implemented singleton pattern for P4Conn which helped as I dont close the connection.并且还为 P4Conn 实现了 singleton 模式,这有助于我不关闭连接。 I only check the validity of the connection, and login if the connection is not valid.我只检查连接的有效性,如果连接无效则登录。

Please let me know if any of you guys needs any help regarding this如果你们中的任何人需要任何帮助,请告诉我

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM