OLE DB Driver¶
OLE DB (Object Linking and Embedding, Database) is an API designed by Microsoft for accessing data from a variety of sources in a uniform manner so it can be used by all Microsoft platforms. It is a set of interfaces implemented using the Component Object Model (COM).
.NET Framework is a software framework for Microsoft Windows operating systems. It includes a large library and it supports several programming languages which allows language interoperability (each language can utilize code written in other languages). The .NET library is available to all programming languages that .NET supports. A data provider in the .NET Framework serves as a bridge between an application and a data source; a data provider is used to retrieve data from a data source and to reconcile changes to that data back to the data source.
CUBRID OLE DB driver is written based on CCI API so affected by CCI configurations such as CCI_DEFAULT_AUTOCOMMIT.
- If your CUBRID OLEDB driver version is 9.1.0.p1 or later, only one installation package is needed for both Windows 32 bit and 64 bit. Our new OLEDB installer supports CUBRID DB engine 8.4.1 or later.
- If your CUBRID OLEDB Driver version is 9.1.0 or older, it may have a problem on 64 bit operating system.
Installing and Configuring OLE DB¶
CUBRID OLE DB Provider
Before you start developing applications with CUBRID, you will need the Provider driver (CUBRIDProvider.dll). You have two options to get the driver.
Installing the driver: Download the CUBRID OLE DB driver’s .exe file at the location http://ftp.cubrid.org/CUBRID_Drivers/OLEDB_Driver/ . From OLE DB driver 9.1.0.p1 version(available from CUBRID server 2008 R4.1), both of 32 bit and 64 bit driver are installed on one installation.
- There are below files in the installed directory.
- There are below files in the installed directory.
Building from source code: If you want to change CUBRID OLED DB Data Provider Installer, you can build it for yourself by compiling the source code.
OLE DB Programming¶
Using Data Link Properties Dialog Box¶
To access this dialog box in Visual Studio .NET, select Connect to Database from the Tools menu or click the Connect to Database icon in Server Explorer.
you must install Visual Studio first, click “Connect to Database”
Choose <other>,and .Net Framework Data Provider for OLE DB, Then click Continue button
Choose CUBRID OLE DB Provider, then click Data links button
Fill in the information, and click Test Connection button, if driver connect database successful, success dialog will pop up.
More information can found in msdn: https://docs.microsoft.com/en-us/previous-versions/79t8s5dk(v=vs.90)
Or you also can open this dialog box by double-clicking a universal data link (.udl) file in Windows Explorer, and in a variety of other ways, including programmatically.
First, create a text file, and modify extension to udl: 1.txt -> 1.udl. Second, double click 1.udl, dialog will pop up.
At this time, change the Provider as “CUBRID OLE DB Provider”.
Setting a character set
If you open universal data link(.udl) file on the text editor then the below string appears; “Charset=utf-8;” is the part of setting a character set.
“Provider=CUBRIDProvider;Data Source=demodb;Location=127.0.0.1;User ID=dba;Password=;Port=33000;Fetch Size=100;Charset=utf-8;”
Setting isolation level
In the below string, “Autocommit Isolation Levels=256;” is the part of setting isolation level. This feature is only supported in the driver version 9.1.0.p2 or later; if you do not specify this in the connection string, 4096 is the default value.
"Provider=CUBRIDProvider;Data Source=demodb;Location=10.34.64.104;User ID=dba;Password=;Port=30000;Fetch Size=100;Charset=utf-8;Autocommit Isolation Levels=256;"
OLE DB CUBRID Value ISOLATIONLEVEL_READUNCOMMITTED TRAN_COMMIT_CLASS_UNCOMMIT_INSTANCE 256 ISOLATIONLEVEL_READCOMMITTED TRAN_COMMIT_CLASS_COMMIT_INSTANCE 4096 ISOLATIONLEVEL_REPEATABLEREAD TRAN_REP_CLASS_REP_INSTANCE 65536 ISOLATIONLEVEL_SERIALIZABLE TRAN_SERIALIZABLE 1048576
note:: In CUBRID OLE DB, “Autocommit Isolation Levels” only acts on the isolation level of OLEDB Connection, but not for the transaction. Therefore, even if you specify the isolation level in the function OleDbConnection.BeginTransaction(), it is not applied.
Configuring Connection String¶
When you do programming with the CUBRID OLE DB Provider, you should write connection string as follows:
|Data Source||demodb||Database name|
|Location||127.0.0.1||The IP address or host name of the CUBRID broker server|
|User ID||PUBLIC||User ID|
|Port||33000||The broker port number|
|Fetch Size||100||Fetch size|
|Autocommit Isolation Levels||4096||isolation level|
A connection string using the example above is as follows:
"Provider=CUBRIDProvider;Data Source=demodb;Location=127.0.0.1;User ID=PUBLIC;Password=xxx;Port= 33000;Fetch Size=100;Charset=utf-8;Autocommit Isolation Levels=256;"
- Because a semi-colon (;) is used as a separator in URL string, it is not allowed to use a semi-colon as parts of a password (PWD) when specifying the password in connection string.
- If a string longer than defined max length is inserted (INSERT) or updated (UPDATE), the string will be truncated.
- The database connection in thread-based programming must be used independently each other.
- In autocommit mode, the transaction is not committed if all results are not fetched after running the SELECT statement. Therefore, although in autocommit mode, you should end the transaction by executing COMMIT or ROLLBACK if some error occurs during fetching for the resultset.
Multi-Threaded Programming in .NET Environment¶
Additional considerations when you do programming with the CUBRID OLE DB Provider in the Microsoft .NET environment are as follows:
If you do multi-threaded programming using ADO.NET in the management environment, you need to change the value of the ApartmentState attribute of the Thread object to a ApartmentState.STA value because the CUBRID OLE DB Provider supports the Single Threaded Apartment (STA) attribute only.
Without any changes of given values, the default value of the attribute in the Thread object returns Unknown value, causing it to malfunction during multi-threaded programming.
All OLE DB objects are the Component Object Model. Of COM threading model, the CUBRID OLE DB Provider currently supports the apartment threading model only, which is available in every multi-threaded environment as well as .NET environment.
OLE DB API¶
For more information about OLE DB API, see Micorosoft OLE DB documentation at https://docs.microsoft.com/en-us/previous-versions/windows/desktop/ms722784(v=vs.85) .
For more information about CUBRID OLE DB, see http://ftp.cubrid.org/CUBRID_Docs/Drivers/OLEDB/.