开发者

VS2008 T4 Subsonic Error on DBs with many tables System.Runtime.Remoting.RemotingException

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.


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


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.


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜