具有许多表的数据库上的 VS2008 T4 Subsonic 错误 System.Runtime.Remoting.RemotingException

发布于 2024-08-22 14:17:19 字数 921 浏览 3 评论 0原文

在一项咨询任务中,他们使用 Subsonic 3.x(最新),它使用 T4 代码模板引擎(而不是像 2.x 那样的 CodeSmith)。

当我们在拥有约 1000 个表的 DBMS 上运行它时,我们会遇到错误生成Structs.cs 文件。 T4/Subsonic 在较小的 DB 上生成良好......

运行转换代码时抛出异常。该过程无法继续。引发以下异常:

System.Runtime.Remoting.RemotingException:对象 '/f9ce56f8_409c_4465_b81c_5272c8d764dc/dbet1oh1u2djvp2ildubn9nb_25.rem' 已断开连接或服务器上不存在。 在 Microsoft.VisualStudio.TextTemplate.TransformationRunner.get_Errors() 在 Microsoft.VisualStudio.TextTemplate.Engine.CompileAndRunCode(字符串 生成器代码、ITextTemplateEngineHost 主机、 TemplateProcessingSession 会话) C:\Users\BlahBlahUserName\Documents\Visual Studio 2008\EdsTry\EdSub\ActiveRecord\Structs.tt

这导致了两个问题

  1. 有没有人见过这个并知道 T4 爆炸时的任何解决方法 大文件?

  2. 一旦我解决了这个问题,我可以修改亚音速以使其产生更少的声音吗? 文件(例如 1,000 个类文件而不是 1 个大型类文件)

如果我们在主项目中包含 Subsonic 生成工具,Vstudio 会被它生成的大型类文件阻塞,因此我们在单独的项目中执行此操作并引用生成的 DLL,但肯定必须有一种从亚音速与 1 生成数百个类文件的方法 文件中包含数百个类。

At a consulting assignment they are using Subsonic 3.x (latest) which uses the T4 Code Templating Engine (rather than CodeSmith like 2.x did)

When we run it on our DBMS that has ~ 1 thousand tables we run into an error generating the Structs.cs file. T4/Subsonic generates fine on smaller DBs....

An Exception was thrown while running the transformation code. The process cannot continue. The following Exception was thrown:

System.Runtime.Remoting.RemotingException: Object
'/f9ce56f8_409c_4465_b81c_5272c8d764dc/dbet1oh1u2djvp2ildubn9nb_25.rem'
has been disconnected or does not exist at the server.
at Microsoft.VisualStudio.TextTemplating.TransformationRunner.get_Errors()
at Microsoft.VisualStudio.TextTemplating.Engine.CompileAndRunCode(String
generatorCode, ITextTemplatingEngineHost host,
TemplateProcessingSession session)
C:\Users\BlahBlahUserName\Documents\Visual Studio
2008\EdsTry\EdSub\ActiveRecord\Structs.tt

This leads to two questions

  1. has anyone seen this and know any workarounds when T4 blows up on
    large files?

  2. And once I solve that can I modify subsonic so it generates less
    files (say 1,000 class files rather than 1 large class file)

Vstudio chokes on the large class files it generates if we include the Subsonic generation stiuff in our main project so we do it in separate project and reference the resulting DLL but surely there must be a way to generate several hundred class files from subsonic vs. 1
file with several hundred classes in it.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

流年里的时光 2024-08-29 14:17:19

您的问题是数据库连接超时,您最好的办法可能是使用本地数据库服务器而不是远程数据库服务器,这样您就不会一直等待数据。

另外,如果您查看 TT 文件,您会注意到它获取所有表的列表,循环遍历这些表,然后循环遍历字段,TT 文件是一个从模板创建类的文件,而不是创建文件并保存他们在某个地方。

但是如果你的数据库太大,有超过1000个表,我认为你最好从数据库设计开始,也许将表分成一组数据库,并有多个dal,即产品数据库,人员数据库,等等这样你就可以让它变小
如果这有意义的话,仍然可以使用它们

your problem is your DB connection timeout, your best best would prob be to work of a local DB server rather than remote so your not waiting for the data alll the time.

also if you look at the TT file you will notice that it gets a list of all tables, loops through them tables and then loops through the fields, the TT file is a file to create a class from template, not to create files and save them somewhere.

but if your database is so massive that you have more than 1000 tables i think you would be better starting at DB design, and maybe splitting the tables into a group of database, and having multiple dals, I.E a product db, a people DB, etc this way you will keep it small
and will still be able to use them all if this makes sense

ˇ宁静的妩媚 2024-08-29 14:17:19

我也遇到了同样的问题,发现这个错误是由于连接超时引起的。

这就是我连接到数据库以检索所有实体/视图/过程/等的方式:

ServerConnection conn = new ServerConnection(serverName, serverLogin, serverPwd);
conn.ConnectTimeout = 0;
conn.StatementTimeout = 0;
Server server = new Server(conn);
Database database = new Database(server, databaseName);
database.Refresh();

// ...

关键时刻是设置这两个参数:

conn.ConnectTimeout = 0;
conn.StatementTimeout = 0;

设置这些参数后,我的生成器运行良好。

希望它对你有用。

I had the same problem and found that this error caused because of connection timeout.

This is how I connect to a database for retrieving of all entities/views/procedures/etc.:

ServerConnection conn = new ServerConnection(serverName, serverLogin, serverPwd);
conn.ConnectTimeout = 0;
conn.StatementTimeout = 0;
Server server = new Server(conn);
Database database = new Database(server, databaseName);
database.Refresh();

// ...

The key moment is to set these two arguments:

conn.ConnectTimeout = 0;
conn.StatementTimeout = 0;

After setting these my generator works well.

Hope it will work for you.

岁月打碎记忆 2024-08-29 14:17:19

如果您的软件不需要全部 1000 个表,那么您可以将黑名单“ExcludeTables”转换为白名单“IncludeTables”,并在 *.tt 文件中查找/替换所有“!ExcludeTables”为“IncludeTables”。另外,我更改了 SQLServer.ttinclude 中的 LoadTables() 以在执行任何其他调用之前检查我的白名单并添加表:

while(rdr.Read()){
            Table tbl=new Table();
            tbl.Name=rdr["TABLE_NAME"].ToString();
            // check table whitelist
            if (IncludeTables.Contains(tbl.Name)
   {
    tbl.Schema=rdr["TABLE_SCHEMA"].ToString();
    tbl.Columns=LoadColumns(tbl);
    tbl.PrimaryKey=GetPK(tbl.Name);
    tbl.CleanName=CleanUp(tbl.Name);
    tbl.ClassName=Inflector.MakeSingular(tbl.CleanName);
    tbl.QueryableName=Inflector.MakePlural(tbl.ClassName);

    //set the PK for the columns
    var pkColumn=tbl.Columns.SingleOrDefault(x=>x.Name.ToLower().Trim()==tbl.PrimaryKey.ToLower().Trim());
    if(pkColumn!=null)
     pkColumn.IsPK=true;

    tbl.FKTables=LoadFKTables(tbl.Name);
    result.Add(tbl);
   }
        }

我对 SQLServer.ttinclude 中的存储过程的 GetSPs() 执行了相同的操作:

// Check SP whitelist too
if(spType=="PROCEDURE" && IncludeSPs.Contains(sp.Name) &! sp.Name.StartsWith("sp_")){

         sp.CleanName=CleanUp(sp.Name);

            sp.Parameters=GetSPParams(sp.Name);
            result.Add(sp);        
        }

现在所有 *.tt 都执行没有远程处理异常。

If your software does not require all 1000 tables, then you could turn the black list "ExcludeTables" into a whitelist "IncludeTables" and find/replace all "!ExcludeTables" with "IncludeTables" in the *.tt files. Also, I changed the LoadTables() in SQLServer.ttinclude to check my whitelist before it does any other calls and adds the table:

while(rdr.Read()){
            Table tbl=new Table();
            tbl.Name=rdr["TABLE_NAME"].ToString();
            // check table whitelist
            if (IncludeTables.Contains(tbl.Name)
   {
    tbl.Schema=rdr["TABLE_SCHEMA"].ToString();
    tbl.Columns=LoadColumns(tbl);
    tbl.PrimaryKey=GetPK(tbl.Name);
    tbl.CleanName=CleanUp(tbl.Name);
    tbl.ClassName=Inflector.MakeSingular(tbl.CleanName);
    tbl.QueryableName=Inflector.MakePlural(tbl.ClassName);

    //set the PK for the columns
    var pkColumn=tbl.Columns.SingleOrDefault(x=>x.Name.ToLower().Trim()==tbl.PrimaryKey.ToLower().Trim());
    if(pkColumn!=null)
     pkColumn.IsPK=true;

    tbl.FKTables=LoadFKTables(tbl.Name);
    result.Add(tbl);
   }
        }

I did the same for the Stored Procedures' GetSPs() in SQLServer.ttinclude:

// Check SP whitelist too
if(spType=="PROCEDURE" && IncludeSPs.Contains(sp.Name) &! sp.Name.StartsWith("sp_")){

         sp.CleanName=CleanUp(sp.Name);

            sp.Parameters=GetSPParams(sp.Name);
            result.Add(sp);        
        }

Now all *.tt execute without the Remoting Exception.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文