Class MsAccessDataHelper
General helpers for work Microsoft Access.
Inheritance
Namespace: Kros.Data.MsAccess
Assembly: Kros.Utils.MsAccess.dll
Syntax
public static class MsAccessDataHelper
Fields
AceProviderBase
Identification of Microsoft Access ACE provider: Microsoft.ACE.OLEDB.
Declaration
public const string AceProviderBase = "Microsoft.ACE.OLEDB"
Field Value
| Type | Description |
|---|---|
| System.String |
ClientId
Identification of Microsoft Access classes (used for example in MsAccessIdGeneratorFactory, MsAccessBulkActionFactory).
Declaration
public const string ClientId = "System.Data.OleDb"
Field Value
| Type | Description |
|---|---|
| System.String |
JetProviderBase
Identification of Microsoft Access JET provider: Microsoft.Jet.OLEDB.
Declaration
public const string JetProviderBase = "Microsoft.Jet.OLEDB"
Field Value
| Type | Description |
|---|---|
| System.String |
Properties
MsAccessAceProvider
Returns string for installed Microsoft Access ACE provider (for example Microsoft.ACE.OLEDB.12.0). If ACE provider is not installed, empty string is returned.
Declaration
public static string MsAccessAceProvider { get; }
Property Value
| Type | Description |
|---|---|
| System.String |
Remarks
Provider is loaded from the system only once and the value is cached. So when no provider is found, this state is returned for any subsequent reads of the property.
MsAccessJetProvider
Returns string for installed Microsoft Access ACE provider (for example Microsoft.Jet.OLEDB.4.0). If JET provider is not installed, empty string is returned.
Declaration
public static string MsAccessJetProvider { get; }
Property Value
| Type | Description |
|---|---|
| System.String |
Remarks
Provider is loaded from the system only once and the value is cached. So when no provider is found, this state is returned for any subsequent reads of the property.
MsAccessProvider
Returns installed provider for Microsoft Access. ACE provider is preferred over JET provider (if both are available). If none provider is installed, empty string is returned.
Declaration
public static string MsAccessProvider { get; }
Property Value
| Type | Description |
|---|---|
| System.String |
Methods
CreateConnectionString(String, ProviderType)
Creates a connection string to the database databasePath with provider type
provider.
Declaration
public static string CreateConnectionString(string databasePath, ProviderType provider)
Parameters
| Type | Name | Description |
|---|---|---|
| System.String | databasePath | Path to the database. |
| ProviderType | provider | Provider type, which will be usedProvider string is used for the current, installed provider, so there is no need to care about provider version. |
Returns
| Type | Description |
|---|---|
| System.String | Returns connection string to specified database. For example
|
CreateEmptyDatabase(String, ProviderType)
Creates an empty Microsoft Access database at location path. Database type
(.accdb, .mdb) is specified with provider.
Declaration
public static void CreateEmptyDatabase(string path, ProviderType provider)
Parameters
| Type | Name | Description |
|---|---|---|
| System.String | path | Path, where the database will be created. The path must be full, must contain also file name. |
| ProviderType | provider | Microsoft Access database type. |
Remarks
If the file path already exists, it will be overwritten.
Based on the value of provider is created specified database type (.accdb, or older
.mdb). But nothing is done with the file extension, so the file name will be created as
path. So it is possible to create a file with .mdb extension, which actually will be
database type .accdb. So the caller must provide correct file name.
GetProviderString(ProviderType)
For specified provider type provider returns string of the provider for use in connection string.
If there is no provider available, empty string is returned.
Declaration
public static string GetProviderString(ProviderType provider)
Parameters
| Type | Name | Description |
|---|---|---|
| ProviderType | provider | Provider type. |
Returns
| Type | Description | ||||
|---|---|---|---|---|---|
| System.String | Method just returns the values of other properties:
|
GetProviderType(IDbConnection)
Returns Microsoft Access provider type used in connection connection.
Declaration
public static ProviderType GetProviderType(IDbConnection connection)
Parameters
| Type | Name | Description |
|---|---|---|
| System.Data.IDbConnection | connection | Database connection. |
Returns
| Type | Description |
|---|---|
| ProviderType | Provider type. |
GetProviderType(String)
Returns Microsoft Access provider type used in connection string connectionString.
Declaration
public static ProviderType GetProviderType(string connectionString)
Parameters
| Type | Name | Description |
|---|---|---|
| System.String | connectionString | Connection string. |
Returns
| Type | Description |
|---|---|
| ProviderType | Provider type. |
HasProvider(ProviderType)
Returns is specified Microsoft Access provider provider is available.
Declaration
public static bool HasProvider(ProviderType provider)
Parameters
| Type | Name | Description |
|---|---|---|
| ProviderType | provider | Checked provider type. |
Returns
| Type | Description |
|---|---|
| System.Boolean | true if provider is available, otherwise false. |
IsExclusiveMsAccessConnection(IDbConnection)
Checks if connection connection is an exclusive connection to the database.
Declaration
public static bool IsExclusiveMsAccessConnection(IDbConnection connection)
Parameters
| Type | Name | Description |
|---|---|---|
| System.Data.IDbConnection | connection | The connection. |
Returns
| Type | Description |
|---|---|
| System.Boolean | true if connection is exclusive, otherwise false. |
IsExclusiveMsAccessConnection(String)
Checks if connection connectionString is an exclusive connection to the database.
Declaration
public static bool IsExclusiveMsAccessConnection(string connectionString)
Parameters
| Type | Name | Description |
|---|---|---|
| System.String | connectionString | The connection string. |
Returns
| Type | Description |
|---|---|
| System.Boolean | true if connection is exclusive, otherwise false. |
IsMsAccessAceProvider(String)
Checks if ACE provider is used in connectionString.
Declaration
public static bool IsMsAccessAceProvider(string connectionString)
Parameters
| Type | Name | Description |
|---|---|---|
| System.String | connectionString | Connection string. |
Returns
| Type | Description |
|---|---|
| System.Boolean | true if ACE provider is used, otherwise false. |
IsMsAccessConnection(IDbConnection)
Checks if database connection connection is Microsoft Access.
Declaration
public static bool IsMsAccessConnection(IDbConnection connection)
Parameters
| Type | Name | Description |
|---|---|---|
| System.Data.IDbConnection | connection | Tested connection. |
Returns
| Type | Description |
|---|---|
| System.Boolean | true if connection is to Microsoft Access database, otherwise false. |
IsMsAccessConnection(String)
Checks if database connection connectionString is Microsoft Access.
Declaration
public static bool IsMsAccessConnection(string connectionString)
Parameters
| Type | Name | Description |
|---|---|---|
| System.String | connectionString | Tested connection string. |
Returns
| Type | Description |
|---|---|
| System.Boolean | true if connection is to Microsoft Access database, otherwise false. |
IsMsAccessJetProvider(String)
Checks if JET provider is used in connectionString.
Declaration
public static bool IsMsAccessJetProvider(string connectionString)
Parameters
| Type | Name | Description |
|---|---|---|
| System.String | connectionString | Connection string. |
Returns
| Type | Description |
|---|---|
| System.Boolean | true if JET provider is used, otherwise false. |