This topic describes how to use the ADO.NET Data Provider for PolarDB for Oracle (PolarDB .NET) driver to connect C# applications to PolarDB for Oracle databases.
Prerequisites
- An account is created for your PolarDB cluster. For more information, see Create database accounts.
- The IP address of the host that you want to connect to the PolarDB cluster is added to the whitelist of the cluster. For more information, see Configure a whitelist for a cluster.
Background information
PolarDB .NET is a driver that allows you to use programming languages such as C#, Visual Basic, and F# to connect to PolarDB for Oracle databases. The PolarDB .NET driver is compatible with Entity Framework Core and Entity Framework 6.x. You can use PolarDB .NET in conjunction with Entity Framework to develop applications in a quick way.
The PolarDB .NET driver uses version 3.0 of the PostgreSQL protocol. The driver is compatible with .NET Framework 1.1, .NET Framework 2.0, .NET Framework 4.0, .NET Framework 4.5, and .NET Core 2.0.
In the earlier versions of the PolarDB .NET driver, most class names start with POLARDB. In the latest version of the driver, the class names start with PolarDB. Therefore, you must replace POLARDB with PolarDB in your code. The logic in the driver is not modified, so services are not affected after you upgrade your driver and update your code.
Entity Framework overview
Entity Framework is an object-relational mapping (ORM) framework that is widely adopted in the .NET platform. Entity Framework and Language-Integrated Query (LINQ) technologies provide a quick method for you to develop backend C# applications.
The PolarDB .NET driver provides the .dll files of Entity Framework 5 (EF5) and Entity Framework 6 (EF6), and the .dll files are applicable to PolarDB for Oracle. This helps you use Entity Framework.
For more information about Entity Framework, visit the official website of Entity Framework.
Install the PolarDB .NET driver
Example
The Samples directory stores the PolarDBSample.sql file and multiple sample project files. The following procedure shows how to run the sample projects.
Connection string parameters
Applications must provide connection strings to connect to databases. The connection strings include the host, username, and password parameters.
Connection strings are in the keyword1=value; keyword2=value;
format, and are not case-sensitive. You can use double quotation marks (") to enclose
the values that contain special characters, such as semicolons (;).
The current driver supports the following connection string parameters.
Parameter | Example | Description |
---|---|---|
Host | localhost |
The endpoint of the PolarDB for Oracle cluster. For more information about how to view the endpoint, see View or apply for an endpoint. |
Port | 1521 |
The port of the PolarDB for Oracle cluster. Default value: 1521. |
Database | sampledb |
The name of the database to be connected. |
Username | polaruser |
The username that is used to connect to the PolarDB for Oracle cluster. |
Password | password |
The password for the username of the PolarDB for Oracle cluster. |
Parameter | Example | Description |
---|---|---|
Pooling | true |
Specifies whether to enable the connection pool. |
Minimum Pool Size | 0 | The minimum size of the connection pool. |
Maximum Pool Size | 100 | The maximum size of the connection pool. |
Connection Idle Lifetime | 300 | The time-out period. After the time-out period expires, idle connections are closed in the pool if the number of all the connections exceeds the value of the Minimum Pool Size parameter. Unit: second. |
Connection Pruning Interval | 10 | The interval for deleting idle connections. Unit: second. |
Parameter | Description |
---|---|
application_name | The name of the application. |
search_path | The search path of the schema. |
client_encoding | The client encoding. |
timezone | The time zone of the session. |