简体   繁体   English

存储过程中的企业库缓存参数?

[英]Enterprise library caching parameters on stored procs?

I'm trying to standardise some data access code with my colleagues.我正在尝试与我的同事标准化一些数据访问代码。 One of the aforementioned colleagues asserts that the EntLib Data Access Block trys to cache parameters on stored proc calls.上述一位同事断言 EntLib 数据访问块试图缓存存储过程调用上的参数。

I've had a look in reflector and there is some evidence that it could be caching them.我看过反射器,有一些证据表明它可能正在缓存它们。 But I don't think it does in the following situation.但我认为在以下情况下不会。

    public Dictionary<long, string> GetQueue(int maxItems)
    {
        var sq = new SqlDatabase(_connString.ConnectionString);

        var result = new Dictionary<long, string>();

        using (var cmd = (SqlCommand)sq.GetStoredProcCommand("dbo.GetQueue"))
        {
            sq.AddInParameter(cmd, "maxItems", DbType.Int32, maxItems);

            var reader =  cmd.ExecuteReader(CommandBehavior.CloseConnection);

            while (reader.Read())
            {
                long id = reader.GetInt64(reader.GetOrdinal("id"));
                string fileName = reader.GetString(reader.GetOrdinal("meta_data_filename"));

                result.Add(id, fileName);
            }
        }

        return result;
    }

Can anyone confirm or deny this?任何人都可以确认或否认这一点吗?

I'm using EntLib 4.1我正在使用 EntLib 4.1

It definetly used to, I ripped the code out and threw in in my library.它确实习惯了,我把代码撕掉并扔进了我的图书馆。

it used sp_help and parsed the output to determine the data types.它使用sp_help并解析 output 以确定数据类型。

These days, I ripped the code out, .Net is much much better about adding parameters.这些天,我撕掉了代码,.Net 在添加参数方面要好得多。

cmd.Parameters.AddWithValue("@name",somevalue)

in your example of you keep reflectoring... you will find it being done down this path GetStoredProcCommand()在你的例子中,你一直在反射......你会发现它是沿着这条路径完成的 GetStoredProcCommand()

You will get a Command object back, already populated with parameters你会得到一个命令 object 回来,已经填充了参数

The ent lib code is copyrighted, but the code is almost identical to this ent lib代码是有版权的,但是代码和这个几乎一模一样

http://code.google.com/p/dbdotnet/source/browse/trunk/ParameterCache.cshttp://code.google.com/p/dbdotnet/source/browse/trunk/ParameterCache.cs

As far as I can tell it doesn't cache the parameters.据我所知,它不会缓存参数。 Using the same instance of a Database object I called DiscoverParameters multiple times while running a trace.使用数据库 object 的同一实例,我在运行跟踪时多次调用 DiscoverParameters。 Each time I call DiscoverParameters I can see a [sys].[sp_procedure_params_100_managed] so it looks like it's making the round trip every time.每次我调用 DiscoverParameters 时,我都可以看到 [sys].[sp_procedure_params_100_managed],所以看起来它每次都在进行往返。

Here's an example of how to do it yourself that's seems like it might be alright:这是一个如何自己做的例子,看起来可能没问题:

http://davidhayden.com/blog/dave/archive/2006/11/03/CachingStoredProcedureParameters.aspx http://davidhayden.com/blog/dave/archive/2006/11/03/CachingStoredProcedureParameters.aspx

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM