大数据库上的 SubSonic 3.0.0.3 t4 模板生成耗尽连接
当针对包含 1400 多个表的数据库运行模板时,出现以下错误。 服务器显示数百个连接。 有谁知道这是否是一般模板生成的问题,或者是这些模板的具体问题。 其他较小的数据库对我来说还可以。
运行转换:System.InvalidOperationException:超时已过期。 从池中获取连接之前超时时间已过。 发生这种情况的原因可能是所有池连接都在使用中并且已达到最大池大小。
在 System.Data.ProviderBase.DbConnectionFactory.GetConnection(DbConnection owningConnection) 在 System.Data.ProviderBase.DbConnectionClosed.OpenConnection(DbConnection 外连接,DbConnectionFactory 连接工厂) 在 System.Data.SqlClient.SqlConnection.Open() 在 c:\POS\POS.Win\Templates\SQLServer.ttinclude 中的 Microsoft.VisualStudio.TextTemplate8D8967BD3E8719BDA6DD9945992440F1.GeneeratedTextTransformation.GetCommand(String sql):第 13 行 在 c:\POS\POS.Win\Templates\SQLServer.ttinclude 中的 Microsoft.VisualStudio.TextTemplate8D8967BD3E8719BDA6DD9945992440F1.GeneeratedTextTransformation.LoadFKTables(String tableName):第 179 行 在 c:\POS\POS.Win\Templates\SQLServer.ttinclude 中的 Microsoft.VisualStudio.TextTemplate8D8967BD3E8719BDA6DD9945992440F1.GeneratedTextTransformation.LoadTables():第 131 行 在 c:\POS\POS.Win\Templates\ActiveRecord.tt 中的 Microsoft.VisualStudio.TextTemplate8D8967BD3E8719BDA6DD9945992440F1.GeneeratedTextTransformation.TransformText():第 21 行
When running the templates against a database with 1400+ tables I get the following error. The server shows hundreds of connections. Does anyone know if this is a problem with template generation in general, or with these templates specifically. Other, smaller DBs generate ok for me.
Running transformation: System.InvalidOperationException: Timeout expired. The timeout period elapsed prior to obtaining a connection from the pool. This may have occurred because all pooled connections were in use and max pool size was reached.
at System.Data.ProviderBase.DbConnectionFactory.GetConnection(DbConnection owningConnection)
at System.Data.ProviderBase.DbConnectionClosed.OpenConnection(DbConnection outerConnection, DbConnectionFactory connectionFactory)
at System.Data.SqlClient.SqlConnection.Open()
at Microsoft.VisualStudio.TextTemplating8D8967BD3E8719BDA6DD9945992440F1.GeneratedTextTransformation.GetCommand(String sql) in c:\POS\POS.Win\Templates\SQLServer.ttinclude:line 13
at Microsoft.VisualStudio.TextTemplating8D8967BD3E8719BDA6DD9945992440F1.GeneratedTextTransformation.LoadFKTables(String tableName) in c:\POS\POS.Win\Templates\SQLServer.ttinclude:line 179
at Microsoft.VisualStudio.TextTemplating8D8967BD3E8719BDA6DD9945992440F1.GeneratedTextTransformation.LoadTables() in c:\POS\POS.Win\Templates\SQLServer.ttinclude:line 131
at Microsoft.VisualStudio.TextTemplating8D8967BD3E8719BDA6DD9945992440F1.GeneratedTextTransformation.TransformText() in c:\POS\POS.Win\Templates\ActiveRecord.tt:line 21
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
我在使用 250 个表的数据库时遇到了同样的问题。 浏览 SQLServer.ttinclude,我发现了这一点:
将其更改为:
连接未关闭,并且在 100 个之后耗尽池中的连接。任何具有超过 100 个表的数据库都会遇到此问题。 我可以在不接触 SubSonic.Core 的情况下解决这个问题,这真是太棒了。
现在,如果我能花时间弄清楚 Git,我会将这个修复程序发布回 subsonic 项目。 :-D
I had this exact problem with a 250 table database. Poking around the SQLServer.ttinclude, I found this:
Changed it to this:
The connection was not getting closed and you run out of connections in the pool after 100. Any DB with more than 100 tables would hit this issue. It's pretty awesome that I could fix this without touching SubSonic.Core.
Now if I can just spend the time to figure out Git, I would post this fix back to the subsonic project. :-D
好吧,我可能建议在 1400 个表上运行 T4 可能不是最好的主意。 鉴于此 - 您可以深入研究 T4 代码(在 SQLServer.tt 中)以了解我们如何加载表(在 LoadTables 中)并根据需要修改连接。
生成了 1400 个类 - 猜测最终输出的文件大小会很有趣......
Well, I might suggest that running T4 on 1400 tables is probably not the best idea. Given that - you can spelunk the T4 code (in SQLServer.tt) to see how we load the tables (in LoadTables) and doctor the connections as required.
1400 classes generated - would be fun to guess the file size of the final output...
我在使用非常大的数据库(大量表、视图和 SP)时也遇到了同样的问题。 我将以下内容添加到 Sql Server 2005 的 web.config 连接字符串中 - Connect Timeout=60;
这似乎成功了。
您还可以深入研究 .tt 和 .ttinclude 文件并设置 cmd.CommandTimeout。
另外,这里是为特定表设置的 const:
const string TABLE_SQL=@"SELECT *
来自 INFORMATION_SCHEMA.TABLES
WHERE TABLE_TYPE='基表' 且 table_name = 'myTableA' 或 table_name = 'myTableB'
I had this same problem with a very large database (lots of tables, views, and SPs). I added the following to my web.config connection string for Sql Server 2005 - Connect Timeout=60;
This seemed to do the trick.
You can also dig throught the .tt and .ttinclude files and set the cmd.CommandTimeout too.
Also, here is the const to set for specific tables:
const string TABLE_SQL=@"SELECT *
FROM INFORMATION_SCHEMA.TABLES
WHERE TABLE_TYPE='BASE TABLE' and table_name = 'myTableA' or table_name = 'myTableB'