SQL - .NET - SqlParameters - AddWithValue - 有没有在未指定参数类型的任何负面的性能影响? [英] SQL - .NET - SqlParameters - AddWithValue - Are there any negative performance implications when Param Type is not specified?

查看:241
本文介绍了SQL - .NET - SqlParameters - AddWithValue - 有没有在未指定参数类型的任何负面的性能影响?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

<一个href="http://msdn.microsoft.com/en-us/library/system.data.sqlclient.sqlparametercollection.addwithvalue.aspx">http://msdn.microsoft.com/en-us/library/system.data.sqlclient.sqlparametercollection.addwithvalue.aspx

我已经习惯了使用add()函数将SQL参数,一个SqlCommand。这使我指定的SqlParameter的类型,但它需要另一条线路设置的值。

I'm used to adding sql parameters to a sqlCommand using the add() function. This allows me to specify the type of the sqlParameter, but it requires another line to set the value.

这是很好的使用AddWithValue功能,但它跳过了指定的参数类型的步骤。

It's nice to use the AddWithValue function, but it skips the "specify the parameter type" step.

我猜这将导致参数发送过载单引号('')中的字符串,但我不知道。

I'm guessing this causes the parameters to be sent over as strings contained within single quotes (''), but I'm not sure.

这是这样的,做这个事业的存储过程显著性能下降?

Is this the case, and does this cause significantly slower performance of the stored procedures?

注:据我所知,这是很好的,通过指定的数据类型PARAMS验证对事物的.NET端用户数据 - 我只关心AddWithValue的反射型架空无论是在.NET和SQL一面。

Note: I understand that it is nice to validate user data on the .NET side of things by specifying the data type for params -- I'm only concerned about reflection-type overhead of AddWithValue either on the .NET or SQL side.

推荐答案

该类型推演发生的客户端。在的SqlParameter ,它基本上有一点switch语句,以确定哪些SQL类型您指定的值相对应。因此,有什么被发送到SQL Server的没有什么区别,但有一个非常小的开销,以确定哪些SQL类型的.NET类型相对应。在事物的宏伟计划,性能价格还不显示为接下来真正的数据库调用花费的时间昙花一现。

The type deduction happens client-side. Inside SqlParameter, it basically has a bit switch statement to determine what SQL type the value you specify corresponds to. So there's no difference in what is sent to SQL Server, but there is a very small overhead to determine what SQL type your .NET type corresponds to. In the grand scheme of things, the performance cost wouldn't even show up as a blip next to the time spent actually in the database call.

您仍然可以做到这一点在同一行,同时指定SQL类型:

You can still do it in one line while specifying the SQL type:

cmd.Parameters.Add("@something", SqlDbType.NVarChar).Value = someString;

这篇关于SQL - .NET - SqlParameters - AddWithValue - 有没有在未指定参数类型的任何负面的性能影响?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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