首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >p4.net无法连接Perforce

p4.net无法连接Perforce
EN

Stack Overflow用户
提问于 2011-07-11 21:01:02
回答 1查看 1.3K关注 0票数 2

我使用p4.net API从元数据生成一些报告。

在其中一个报告中,我需要为每个变更集报告生成变更行数。

作为一个报告工具,我正在使用MS SQL reporting Services2008,并且我已经编写了一个自定义dll,它使用p4.net API来计算更改的行数。它在本地运行没有任何问题。然而,当我在服务器上运行代码时,它计算出假设前%20部分,然后开始抛出Unable to connect to the Perforce server!无法连接到Perforce!异常。

我在本地服务器上尝试了相同的凭据,它可以工作。我在服务器上使用具有相同凭据的命令行,它可以工作。

如果以前遇到过,有没有人能帮我一下?

下面是我使用的代码。如果需要

代码语言:javascript
复制
 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;
            }
    }


}

您的帮助将不胜感激

非常感谢

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2011-07-22 16:53:10

我已经解决了这个问题。我们发现代码在大约两分钟内就会在短暂的端口范围内循环。一旦它达到最大临时端口,它就会再次尝试使用同一端口。由于每个perforce命令都会创建一个新套接字,因此在处理了大约1000个变更集之后,可用的端口就会耗尽。我已经设置了HKLM\SYSTEM\CurrentControlSet\Services\Tcpip\Parameters默认值(1433,143)的ReservedPorts值,这会给我提供更大范围的临时端口。

还为P4Conn实现了单例模式,这对我没有关闭连接很有帮助。我只检查连接的有效性,如果连接无效则登录。

如果你们中有谁需要帮助,请告诉我

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/6650470

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档