何苦设置命令对象参数的大小参数? [英] Why bother setting the size parameter of a command object parameter?

查看:110
本文介绍了何苦设置命令对象参数的大小参数?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我们的数据访问层使用命令对象与SQL Server进行通信。

Our data access layer uses command objects to communicate with sql server.

在大多数情况下,我已经硬codeD的字段大小(匹配在SQL Server列大小)到命令参数生成器。

In most cases I've hard-coded the field size (that matches the column size in sql server) into the command param builder.

如:

SqlParameter param = new SqlParameter("@name", NVarChar, 4000);

什么的优点(在本例4000)在此指定一个值与刚离开它作为0?这是一个痛苦的时候,你必须重新编译时,一列大小的变化。

What's the advantage to specifying a value here (4000 in this example) versus just leaving it as 0? It's a pain when you have to recompile when a column size changes.

推荐答案

实际上是非常重要的。使用不同的参数长度发出相同的请求最终成为的不同的的过程缓存查询。在时间,这将导致高速缓存污染一个过度活跃的编译事件。这个问题是如何既LINQ2SQL和EF供应商实施了重大的设计缺陷之一,例如。看到数据访问code如何影响数据库性能。另请参阅<一href="http://blogs.msdn.com/b/psssql/archive/2010/10/05/query-performance-and-plan-cache-issues-when-parameter-length-not-specified-correctly.aspx"相对=如果没有指定参数长度正确,了解相关的问题。nofollow的>查询性能和计划缓存问题

Is actually quite important. Identical requests issued with different parameter length end up as different queries in the procedure cache. In time, this leads to cache pollution an over-active compilation events. This issue is one of the major design flaws in how both Linq2SQL and the EF providers were implemented, eg. see How Data Access Code Affects Database Performance. Also see Query performance and plan cache issues when parameter length not specified correctly for a related problem.

这篇关于何苦设置命令对象参数的大小参数?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆