views:

635

answers:

2

Are the .net classes relating to DbProviderFactory thread safe?

A: 

When you say "These instances are generated once at run time, and used for the rest of the service's life", do you mean the connection object? Also, do you mean you're keeping the connection object open through out the life of your service? If your service is multi-threaded and you only have one instance of the connection (say for example a singleton or static class), you have to make sure the connection is only used by one thread at a time.

Without seeing much code, it sounds like a problem with how you treat the IDbConnection you get from the factory, instead of the factory itself.

We use the DbProviderFactory very heavily for our multithreaded applications, which connect to Oracle, FoxPro and SqlServer and I haven't seen this issue.

Good luck!

Ricardo.

Ricardo Villamil
No, I don't mean the connection object. I mean the actual DbProviderFactory object, created by calling DbProviderFactories.GetFactory(). So the factory is created once, and used from then on to create connections, commands, adapters, and parameters.
Jon Ediger
+3  A: 

from msdn: Thread Safety

Any public static (Shared in Visual Basic) members of this type are thread safe. Any instance members are not guaranteed to be thread safe.

Jon Ediger