ComponentOne DataObjects for .NET
Native and OLE DB Database Access
DataObjects for .NET (Enterprise Edition) > Schema Objects > Native and OLE DB Database Access

C1DataObjects supports several options for database connectivity, for example:

The options in the ConnectionTypeEnum enumeration are: OleDb, SqlServer, Oracle, MSOracle, and Custom. The corresponding classes, all derived from C1.SchemaObjects.Connection are: C1OleDbConnection, C1SqlServerConnection, C1OracleConnection, C1MSOracleConnection, and C1CustomConnection. Creating a Connection object in the Schema Designer, you can select one of the five ConnectionTypeEnum options in a combo box. In DataObjects for .NET Express, the database access type is specified in the ConnectionType or ConnectionType properties. The latter is used with stand-alone C1ExpressTable components that are not attached to a C1ExpressConnection component.

At run time, you can retrieve the native IDbConnection and IDbTransaction objects from the DbConnection and DbTransaction properties of a C1.SchemaObjects.Connection object. DbConnection contains a non-null object only while the database connection is open. DbTransaction contains a non-null object only while the database connection is open and is performing a transaction while updating the database. You can cast the values of DbConnection, DbTransaction and event arguments representing IDbCommand to the actual type of the native database access objects. For example, for a SQL Sever connection, you can cast DbConnection to SqlConnection, or RowUpdateEventArgs.UpdateCommand to SqlCommand.

A Field object in the schema has a NativeDbType property. This property is used for database update, to specify the type of command parameters containing field values that are written to the database. Sometimes it is essential to specify the type for database update more exactly than it can be inferred from the .NET type of the field (from Field.DataType). For example, DataType = String can be further specialized to be a Unicode or ASCII string. When you create a schema importing it from database structure, NativeDbType is automatically set to the actual type of the database field. In those rare cases when you need to change it, you can set the NativeDbType property to a specific native type you need, or you can use NativeDbType = Any (-1) to indicate that inferring parameter type from Field.DataType is good enough (or not needed at all, as, for example, in calculated fields). The type of the NativeDbType is Integer. It contains the numeric value corresponding to one of the values of the enumerated type describing all possible data types for the database access provider. These enumerations are:

Note that using native database access does not automatically mean your application will have better performance comparing to using OLE DB. Native providers are better optimized, avoiding unnecessary overhead imposed by OLE DB middleware. However, it depends on the relative weight this overhead has in the overall performance of your application. For a very simple application that just uses IDbReader to read database values and does not fill any data set, the performance boost can be very noticeable. But for filling a C1DataSet, the overhead from OLE DB is nearly negligible, so eliminating it will hardly matter. However, using native database access in DataObjects for .NET can be important. When you write code, you may need a native provider to improve performance or to perform operations that are not supported by the OLE DB provider for .NET (such as ref cursors in Oracle, and so on). When you do it in your code in conjunction with DataObjects for .NET, you will need DataObjects for .NET to give you native database connections, not an OLE DB connection.

See Also