Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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.

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

like image 518
Rob Stevenson-Leggett Avatar asked Dec 07 '25 06:12

Rob Stevenson-Leggett


1 Answers

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.

These days, I ripped the code out, .Net is much much better about adding parameters.

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

in your example of you keep reflectoring ... you will find it being done down this path GetStoredProcCommand()

You will get a Command object back, already populated with parameters

The ent lib code is copyrighted, but the code is almost identical to this

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

like image 149
Chad Grant Avatar answered Dec 09 '25 17:12

Chad Grant



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!