Are the .net classes relating to DbProviderFactory thread safe?
与DbProviderFactory线程相关的.net类是否安全?
2 个解决方案
#1
0
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.
没有看到太多的代码,这听起来像是一个问题,你如何处理从工厂获得的IDbConnection,而不是工厂本身。
We use the DbProviderFactory very heavily for our multithreaded applications, which connect to Oracle, FoxPro and SqlServer and I haven't seen this issue.
我们对我们的多线程应用程序非常重视DbProviderFactory,它连接到Oracle,FoxPro和SqlServer,我没有看到这个问题。
Good luck!
Ricardo.
#2
3
from msdn: Thread Safety
来自msdn:线程安全
Any public static (Shared in Visual Basic) members of this type are thread safe. Any instance members are not guaranteed to be thread safe.
此类型的任何公共静态(在Visual Basic中为Shared)成员都是线程安全的。任何实例成员都不保证是线程安全的。
#1
0
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.
没有看到太多的代码,这听起来像是一个问题,你如何处理从工厂获得的IDbConnection,而不是工厂本身。
We use the DbProviderFactory very heavily for our multithreaded applications, which connect to Oracle, FoxPro and SqlServer and I haven't seen this issue.
我们对我们的多线程应用程序非常重视DbProviderFactory,它连接到Oracle,FoxPro和SqlServer,我没有看到这个问题。
Good luck!
Ricardo.
#2
3
from msdn: Thread Safety
来自msdn:线程安全
Any public static (Shared in Visual Basic) members of this type are thread safe. Any instance members are not guaranteed to be thread safe.
此类型的任何公共静态(在Visual Basic中为Shared)成员都是线程安全的。任何实例成员都不保证是线程安全的。