bug in DAAB ?

Topics: Data Access Application Block
Mar 28, 2007 at 6:40 PM

when creating parameter through the command (CreateParameter) you can't access the parameter from
while when using db.AddInParameter(cmd, "pName", DbType.String) you can't access the parameter using
cmd.Parameters("pName").Value (only by index is working).

any patch to this state?

in addition - a question, if I have only one database object which assign all prarameters values and I access it from different threads (sending the database object to each thread) - will it mess my parameters values?

Mar 28, 2007 at 7:17 PM
It is not a bug.

If you try to access the parameter directly from the command object, you have to remember to use the parameter token. For SQL Server, you need to add the "@" symbol:


would be


I recommend using the Database Method as it shelters you from database specifics, giving you more portable code if you want or need to target other databases.

You should be fine adding parameters using 1 database object with multiple threads. A Database Instance isn't really holding any state other than the parameter cache and in 3.0 any active transaction connections ( which uses appropriate locking for threading concerns ). Other than the parameter token which is static, you are passing in the only information it needs to add parameters to a command.




David Hayden
Microsoft MVP C#
Mar 28, 2007 at 7:54 PM
OK, thanks.

just to make sure - one instance of database object is being refered from different threads to the same command (created in each thread), only the parameters values are different from thread to thread, is OK, yes?