"is sqlconnection / sqlcommand thread safe?" Code Answer

4

am i interpreting this correctly in thinking it means that ms does not guarantee that sqlcommand works in a multi threaded scenario?

it works fine in a multi-threaded scenario as long as you use it correctly.

if several threads try to use the same sqlcommand, what do you think will happen? how could it possibly work?

but if different threads using different connections issue different commands to the same database, there is no problem.

the notes about thread safety on msdn are really broken and badly worded, and must be written by someone who didn't know what thread safety is.

what they're trying to say with that message (which is tacked onto 99.9% of the classes and functions documented on msdn) is that "any static method of this type can be safely called concurrently by multiple threads. any instance members on the same instance is not guaranteed to be safe if invoked concurrently by multiple threads, but accessing the same member on different objects is perfectly fine."

By user12397901 on May 6 2022

Answers related to “is sqlconnection / sqlcommand thread safe?”

Only authorized users can answer the Search term. Please sign in first, or register a free account.