自定义.NET数据提供程序 [英] Custom .NET Data Providers
问题描述
时,可以使用自定义.NET数据提供程序,而不在GAC中安装它?
Is is possible to use a custom .NET data provider without installing it in the GAC?
我可以引用自定义DLL和我的配置文件中注册了吗?
Can I reference a custom DLL and register it inside my configuration file?
推荐答案
是,你可以注册一个实施<一个href="http://msdn.microsoft.com/en-us/library/system.data.common.dbproviderfactory.aspx">DbProviderFactory一流的加入按照您的配置文件部分:
Yes, you can register an implementation of the DbProviderFactory class by adding the following section in your configuration file:
<system.data>
<DbProviderFactories>
<add name="My Custom Data Provider"
invariant="MyCustomDataProvider"
description="Data Provider for My Custom Store"
type="MyNamespace.MyCustomProviderFactory, MyCustomDataProvider, Version=1.0.0.0, Culture=neutral, PublicKeyToken=" />
</DbProviderFactories>
</system.data>
在 MyCustomDataProvider
组装不必在GAC中注册的,但可以使用该应用程序作为的private装配。
The MyCustomDataProvider
assembly doesn't have to be registered in the GAC but can be deployed together with the application as a private assembly.
您可以以编程方式通过使用不变
属性指定的值指的是注册的数据提供者。例如,你可以告诉ADO.NET使用 MyNamespace.MyCustomProviderFactory
通过指定 MyCustomProvider
为的providerName
在连接字符串中:
You can refer to the registered data provider programmatically by using the value specified in the invariant
attribute. For example you could tell ADO.NET to use the MyNamespace.MyCustomProviderFactory
by specifying MyCustomProvider
as the providerName
in the connection string:
<connectionStrings>
<add name="ConnString"
providerName="MyCustomProvider"
connectionString="MyCustomConnectionString" />
</connectionStrings>
在code您可以使用带有<一个相同的提供程序名称href="http://msdn.microsoft.com/en-us/library/system.data.common.dbproviderfactories.getfactory.aspx">DbProviderFactories.GetFactory方法:
In code you can use the same provider name with the DbProviderFactories.GetFactory method:
DbProviderFactory factory = DbProviderFactories.GetFactory("MyCustomDataProvider");
其中,工厂
将成为 MyNamespace.MyCustomProviderFactory
类的一个实例。
where factory
will be an instance of the MyNamespace.MyCustomProviderFactory
class.
这篇关于自定义.NET数据提供程序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!