首批通过分布式安全可靠测评,为关键业务系统打造
连接字符串
更新时间:2026-04-10 15:38:08
OceanBase Connector/NET 支持连接 OceanBase Oracle 模式和 MySQL 模式,连接方式如下:
- MySQL 模式:连接方式与 MySqlConnector 相同,使用 MySQL 标准连接字符串格式及参数。
- Oracle 模式:使用 Oracle 兼容的 API,连接字符串格式与 Oracle ODP.NET 类似。
MySQL 模式
连接 OceanBase MySQL 模式时,使用与 MySqlConnector 相同的连接字符串格式及参数,例如:
Server=host;Port=port;Database=database_name;Uid=username@tenant_name#cluster_name;Pwd=password;
说明
经 ODP 连接时,用户标识通常为三段式:用户名@租户名#集群名(对应 MySQL 模式下的 Uid)。云上部分场景也支持一段式等简写,请以实际环境为准。请将 tenant_name、cluster_name 替换为实际租户名与集群名。
Oracle 模式
基本格式
Data Source=host:port;User Id=username@tenant_name#cluster_name;Password=password;Database=schema_name;
说明
Data Source 当前仅支持 host 或 host:port,不支持在其后追加 /servicename;服务名(若需要)请通过连接串中的其他参数单独指定。
连接串中的 User Id 经 ODP 连接时一般为三段式:用户名@租户名#集群名(英文可写作 Username@TenantName#ClusterName)。云上部分场景也支持一段式等简写,请以实际环境为准。请将示例中的 username、tenant_name、cluster_name 替换为实际值。
主要参数
| 参数 | 说明 |
|---|---|
| Data Source | 数据源地址,仅支持 host 或 host:port,不支持 host:port/servicename。host 为 OBServer 或 ODP 的 IP 或主机名,port 通常为 2881(直连)或 2883(通过 ODP)。服务名(若需要)请通过其他连接参数单独指定,勿写入 Data Source。 |
| User Id | 用户标识。经 ODP 连接时一般为三段式:用户名@租户名#集群名,与连接串中的 User Id 一致。云上部分场景支持一段式等简写。 |
| Password | 数据库密码。 |
| Database | 必填。Oracle 模式下必须设置为 schema 名,否则 Open 会抛出 ArgumentException。 |
| UseLobLocatorV2 | 控制是否开启 LOB Locator 功能,默认为 true。 |
说明
本页是连接参数主文档。接口能力总览请参考 常用接口概览。驱动基于 MySqlConnector 开发,连接参数与 MySqlConnector 保持一致。部分参数默认值有调整:ConnectionReset 默认 false;SslMode 默认 None。
完整参数清单(按类型)
Connection
| 参数名(常用) | 类型 | 默认值 | 说明 |
|---|---|---|---|
| Server / Host / Data Source | string | "" |
服务器地址。支持多主机逗号分隔。 |
| Port | uint | 3306 |
端口号。 |
| User ID / UserID / Username / Uid | string | "" |
用户标识。多租户场景下经 ODP 时一般为三段式:用户名@租户名#集群名;云上部分场景支持一段式等简写。 |
| Password / Pwd | string | "" |
密码。 |
| Database / Initial Catalog | string | "" |
初始数据库(schema),Oracle 模式必填。 |
| Load Balance / LoadBalance | enum | RoundRobin |
多主机负载均衡策略。 |
| Connection Protocol / Protocol | enum | Socket |
连接协议。 |
| Pipe Name / PipeName | string | "MYSQL" |
命名管道名称,仅 NamedPipe 协议有效。 |
| Connection Timeout / Connect Timeout | uint | 15 |
连接超时(秒)。 |
| Interactive Session / Interactive | bool | false |
是否开启交互式会话。 |
| Keep Alive / Keepalive | uint | 0 |
TCP Keepalive 空闲时间(秒),0 表示系统默认。 |
| Server Redirection Mode | enum | Disabled |
是否启用服务端重定向。 |
| Server RSA Public Key File | string | "" |
服务端 RSA 公钥路径。 |
| Server SPN | string | "" |
服务端 SPN。 |
TLS
| 参数名(常用) | 类型 | 默认值 | 说明 |
|---|---|---|---|
| SSL Mode / SslMode | enum | None |
SSL 模式。 |
| Certificate File | string | "" |
客户端证书文件(.pfx)。 |
| Certificate Password | string | "" |
证书密码。 |
| Certificate Store Location | enum | None |
证书存储位置。 |
| Certificate Thumbprint | string | "" |
证书指纹。 |
| SSL Cert / SslCert | string | "" |
客户端 PEM 证书路径。 |
| SSL Key / SslKey | string | "" |
客户端 PEM 私钥路径。 |
| SSL CA / SslCa | string | "" |
CA 证书路径。 |
| TLS Version / TlsVersion | string | "" |
允许的 TLS 版本。 |
| TLS Cipher Suites | string | "" |
允许的加密套件。 |
Pooling
| 参数名(常用) | 类型 | 默认值 | 说明 |
|---|---|---|---|
| Pooling | bool | true |
是否启用连接池。 |
| Connection Lifetime / ConnectionLifeTime | uint | 0 |
连接最大存活时间(秒)。 |
| Connection Reset / ConnectionReset | bool | false |
从池取出连接时是否重置连接状态。 |
| Connection Idle Timeout / ConnectionIdleTimeout | uint | 180 |
连接池空闲超时(秒)。 |
| Minimum Pool Size / Min Pool Size | uint | 0 |
最小连接数。 |
| Maximum Pool Size / Max Pool Size | uint | 100 |
最大连接数。 |
| DNS Check Interval / DnsCheckInterval | uint | 0 |
DNS 变更检查间隔(秒)。 |
OceanBase
| 参数名(常用) | 类型 | 默认值 | 说明 |
|---|---|---|---|
| Use LOB Locator V2 / UseLobLocatorV2 | bool | true |
是否启用 OceanBase LOB Locator V2。 |
Other
| 参数名(常用) | 类型 | 默认值 | 说明 |
|---|---|---|---|
| Allow Load Local Infile | bool | false |
是否允许 LOAD DATA LOCAL。 |
| Allow Public Key Retrieval | bool | false |
是否允许从服务端拉取 RSA 公钥。 |
| Allow User Variables | bool | false |
是否允许 SQL 中使用用户变量。 |
| Allow Zero DateTime | bool | false |
是否允许零值日期。 |
| Application Name | string | "" |
应用名(连接属性)。 |
| Auto Enlist / AutoEnlist | bool | true |
是否自动登记到 TransactionScope。 |
| Cancellation Timeout | int | 2 |
命令取消等待超时(秒)。 |
| Convert Zero DateTime | bool | false |
无效日期是否转换为 DateTime.MinValue。 |
| DateTime Kind | enum | Unspecified |
反序列化 DateTimeKind。 |
| Default Command Timeout / Command Timeout | uint | 30 |
命令默认超时(秒)。 |
| Force Synchronous | bool | false |
是否强制异步 API 同步执行。 |
| GUID Format / GuidFormat | enum | Default |
Guid 映射格式。 |
| Ignore Command Transaction | bool | false |
是否忽略命令事务一致性检查。 |
| Ignore Prepare | bool | false |
是否忽略 Prepare 调用。 |
| No Backslash Escapes | bool | false |
是否禁用反斜杠转义。 |
| Persist Security Info | bool | false |
连接后是否保留敏感信息。 |
| Pipelining | bool | true |
是否启用管道化。 |
| Treat Tiny As Boolean | bool | true |
TINYINT(1) 是否按 bool 处理。 |
| Use Affected Rows | bool | false |
是否返回受影响行数。 |
| Use Compression / Compress | bool | false |
是否压缩网络传输。 |
| Use XA Transactions | bool | true |
TransactionScope 是否使用 XA。 |
| Character Set / CharSet | string | utf8mb4 |
字符集参数,保留兼容。 |