Nonstop Database, HiRDB Version 9 UAP Development Guide
ADO.NET2.0 can now create instances of other classes, such as Command and Parameter, by using the DbProviderFactory instance. You can create an instance specific to a provider based on the provided information by creating a DbProviderFactory instance with a character string indicating the specified provider's namespace (referred to hereafter as the provider name). You can register a provider name in a configuration file for later acquisition. This enables you to create provider-independent codes and select a desired provider during execution.
You create a DbProviderFactory instance by calling the GetFactory method of the DbProviderFactories class. When you install .NET Framework version 2.0 or 3.0, you can specify the following four types of provider names with this method:
You can specify provider names in the GetFactory method if you add provider information to the DbProviderFactories element of the system.data section in the machine.config file that is installed when you install .NET Framework version 2.0 or 3.0.
For HiRDB.NET Data Provider, the invariant value to be specified is Hitachi.HiRDB.
The following shows an example that adds information about HiRDB.NET Data Provider.
<system.data> <DbProviderFactories> : : : <add name="HiRDB Data Provider" invariant="Hitachi.HiRDB" description=".NET Framework Data Provider for HiRDB" type="Hitachi.HiRDB.HiRDBProviderFactory, pddndp20, Version=X.X.X.X, Culture=neutral, PublicKeyToken=YYYYYYYYYYYYYYYY" /> </DbProviderFactories> </system.data> |
You can register provider names in a configuration file for later acquisition when you create a DbProviderFactory instance. For details about the configuration file, see the documentation of .NET Framework.
For HiRDB.NET Data Provider, the provider name (value) to be specified is Hitachi.HiRDB. Note that a configuration file is not required if you specify a provider name directly in the argument of the GetFactory method of the DbProviderFactories class.
The following shows an example of a configuration file. The key name (provider) can be any character string.
<?xml version="1.0" encoding="utf-8" ?> <configuration> <appSettings> <add key="provider" value="Hitachi.HiRDB" /> ...HiRDB.NET Provider </appSettings> </configuration> |
This example specifies the provider name (Hitachi.HiRDB) directly in the argument of the GetFactory of the DbProviderFactories class and then creates a DbProviderFactory instance. The following shows sample coding:
DbProviderFactory dataFactory = DbProviderFactories.GetFactory("Hitachi.HiRDB"); |
This example acquires the value of the key name (provider) from the configuration file and then creates a DbProviderFactory instance by specifying that value in the argument of the GetFactory method of the DbProviderFactories class. The following shows sample coding:
DbProviderFactory dataFactory = DbProviderFactories.GetFactory(ConfigurationManager.AppSettings["provider"]); |
By acquiring the provider name and connection character string that depend on the provider from the configuration file, you can use different providers without having to change the program.
The following shows sample coding for using a configuration file:
All Rights Reserved. Copyright (C) 2011, Hitachi, Ltd.