25 MB lightweight cross-platform database client for 100+ databases, including MySQL, PostgreSQL, SQLite, Redis, MongoDB, DuckDB, SQL Server, and Dameng. Built-in AI, MCP Server, CLI, desktop and Docker. | 轻量级跨平台数据库管理工具,支持 MySQL、PostgreSQL、SQLite、Redis、MongoDB、达梦等 100+ 数据库,提供桌面端、Docker、CLI、内置 AI 助手和 MCP。
TypeScript aicliclickhousedatabasedatabase-clientdatabase-managementdockerguimcpmongodbmysqlpostgresqlredisrustsql-serversqlitetaurivue
fix(sqlserver): honor encrypt=false for instances without SSL
guoxdxdxd769628528837
diff --git a/agents/drivers/sqlserver-legacy/src/main/java/com/dbx/agent/sqlserverlegacy/SqlServerLegacyAgent.java b/agents/drivers/sqlserver-legacy/src/main/java/com/dbx/agent/sqlserverlegacy/SqlServerLegacyAgent.javaindex 37c4a6e005..bbea6ee66c 100644--- a/agents/drivers/sqlserver-legacy/src/main/java/com/dbx/agent/sqlserverlegacy/SqlServerLegacyAgent.java+++ b/agents/drivers/sqlserver-legacy/src/main/java/com/dbx/agent/sqlserverlegacy/SqlServerLegacyAgent.java@@ -769,12 +769,73 @@ public final class SqlServerLegacyAgent extends ConfiguredJdbcAgent {static String legacyTlsUrl(ConnectParams params) {Map<String, String> properties = baseConnectionProperties(params);- properties.put("encrypt", "true");+ // ENCRYPT is stripped from baseConnectionProperties; resolve it explicitly.+ // Default remains true for TLS 1.0 legacy servers; honor encrypt=false /+ // sqlserverEncryption=disabled for instances (or proxies) without SSL.+ String encrypt = requestedEncrypt(params);+ properties.put("encrypt", encrypt);properties.put("trustServerCertificate", "true");- properties.put("sslProtocol", requestedTlsProtocol(params));+ if (!"false".equalsIgnoreCase(encrypt)) {+ properties.put("sslProtocol", requestedTlsProtocol(params));+ }return appendProperties(baseJdbcUrl(params), properties);}+ /**+ * Reads encrypt / sqlserverEncryption from url_params or connection_string.+ * Defaults to true so existing TLS 1.0 encrypted endpoints keep working.+ */+ private static String requestedEncrypt(ConnectParams params) {+ String value = firstProperty(params.getUrl_params(), new String[]{"encrypt", "sqlserverEncryption"}, true);+ if (value == null) {+ value = firstProperty(params.getConnection_string(), new String[]{"encrypt", "sqlserverEncryption"}, false);+ }+ if (value == null) {+ return "true";+ }+ String normalized = value.trim().toLowerCase(Locale.ROOT);+ if (normalized.startsWith("{") && normalized.endsWith("}")) {+ normalized = normalized.substring(1, normalized.length() - 1).replace("}}", "}").toLowerCase(Locale.ROOT);+ }+ if (normalized.equals("disabled") || normalized.equals("disable") || normalized.equals("false")+ || normalized.equals("0") || normalized.equals("off") || normalized.equals("no")) {+ return "false";+ }+ if (normalized.equals("true") || normalized.equals("1") || normalized.equals("yes")+ || normalized.equals("on") || normalized.equals("required")) {+ return "true";+ }+ // strict (TDS 8.0) is not supported by this legacy driver path; other unrecognized+ // values are rejected instead of silently downgraded to the encrypted default.+ throw new IllegalArgumentException(+ "Unsupported SQL Server encrypt value '" + value.trim() + "'; use true, false or strict");+ }++ /** Returns the last matching property value for any of the given keys. */+ private static String firstProperty(String properties, String[] keys, boolean urlParams) {+ if (properties == null) {+ return null;+ }+ String found = null;+ for (String property : connectionPropertyParts(properties, urlParams)) {+ String part = property.trim();+ while (part.startsWith("?")) {+ part = part.substring(1).trim();+ }+ int separator = part.indexOf('=');+ if (separator <= 0) {+ continue;+ }+ String key = part.substring(0, separator).trim();+ for (String candidate : keys) {+ if (candidate.equalsIgnoreCase(key)) {+ found = part.substring(separator + 1).trim();+ }+ }+ }+ return found;+ }+private static String requestedTlsProtocol(ConnectParams params) {// Keep the legacy default for existing SQL Server 2000 connections, but// allow an explicit modern protocol when this driver is used on 2019/2022.diff --git a/agents/drivers/sqlserver-legacy/src/test/java/com/dbx/agent/sqlserverlegacy/SqlServerLegacyAgentTest.java b/agents/drivers/sqlserver-legacy/src/test/java/com/dbx/agent/sqlserverlegacy/SqlServerLegacyAgentTest.javaindex 3b19d37258..ac0cd8d3b3 100644--- a/agents/drivers/sqlserver-legacy/src/test/java/com/dbx/agent/sqlserverlegacy/SqlServerLegacyAgentTest.java+++ b/agents/drivers/sqlserver-legacy/src/test/java/com/dbx/agent/sqlserverlegacy/SqlServerLegacyAgentTest.java@@ -592,7 +592,7 @@ class SqlServerLegacyAgentTest {}@Test- void legacyTlsUrlHonorsExplicitProtocolAndRetainsEncryption() {+ void legacyTlsUrlHonorsDisabledEncryptionAndSkipsSslProtocol() {ConnectParams params = new ConnectParams("db.example.com",14330,@@ -605,11 +605,31 @@ class SqlServerLegacyAgentTest {);Assertions.assertEquals(- "jdbc:sqlserver://db.example.com:14330;databaseName=appdb;applicationName=dbx;encrypt=true;trustServerCertificate=true;sslProtocol=TLSv1.2",+ "jdbc:sqlserver://db.example.com:14330;databaseName=appdb;applicationName=dbx;encrypt=false;trustServerCertificate=true",SqlServerLegacyAgent.legacyTlsUrl(params));}+ @Test+ void legacyTlsUrlRejectsUnsupportedEncryptValueInsteadOfSilentDefault() {+ ConnectParams params = new ConnectParams(+ "db.example.com",+ 14330,+ "appdb",+ "sa",+ "secret",+ "applicationName=dbx;encrypt=strict",+ "",+ false+ );++ IllegalArgumentException error = Assertions.assertThrows(+ IllegalArgumentException.class,+ () -> SqlServerLegacyAgent.legacyTlsUrl(params)+ );+ Assertions.assertTrue(error.getMessage().contains("Unsupported SQL Server encrypt value 'strict'"));+ }+@Testvoid legacyTlsUrlKeepsNamedInstanceWithoutPort() {ConnectParams params = new ConnectParams(@@ -682,7 +702,7 @@ class SqlServerLegacyAgentTest {);Assertions.assertEquals(- "jdbc:sqlserver://db.example.com:1433;databaseName=custom;applicationName=dbx;encrypt=true;trustServerCertificate=true;sslProtocol=TLSv1.2",+ "jdbc:sqlserver://db.example.com:1433;databaseName=custom;applicationName=dbx;encrypt=false;trustServerCertificate=true",SqlServerLegacyAgent.legacyTlsUrl(params));}diff --git a/crates/dbx-core/src/connection/mod.rs b/crates/dbx-core/src/connection/mod.rsindex fcd2d239d7..288a48c50d 100644--- a/crates/dbx-core/src/connection/mod.rs+++ b/crates/dbx-core/src/connection/mod.rs@@ -2004,6 +2004,7 @@ impl AppState {&config.username,&config.password,config.database.as_deref(),+ config.url_params.as_deref(),connect_timeout,).await?;@@ -2044,6 +2045,7 @@ impl AppState {&config.username,&config.password,config.database.as_deref(),+ config.url_params.as_deref(),connect_timeout,).await?;diff --git a/crates/dbx-core/tests/live_sqlserver_long_varchar.rs b/crates/dbx-core/tests/live_sqlserver_long_varchar.rsindex ec0477e30d..c7febb487b 100644--- a/crates/dbx-core/tests/live_sqlserver_long_varchar.rs+++ b/crates/dbx-core/tests/live_sqlserver_long_varchar.rs@@ -16,6 +16,7 @@ async fn live_sqlserver_long_varchar_results_are_complete_and_use_sql_type_names&user,&password,Some(&database),+ None,Duration::from_secs(15),).awaitdiff --git a/crates/dbx-core/tests/live_sqlserver_manual_transactions.rs b/crates/dbx-core/tests/live_sqlserver_manual_transactions.rsindex 3a8255374e..316698475a 100644--- a/crates/dbx-core/tests/live_sqlserver_manual_transactions.rs+++ b/crates/dbx-core/tests/live_sqlserver_manual_transactions.rs@@ -36,6 +36,7 @@ async fn setup() -> (AppState, ConnectionConfig, sqlserver::SqlServerClient, tem&user,&password,Some(&database),+ None,Duration::from_secs(10),).awaitdiff --git a/crates/dbx-core/tests/live_sqlserver_xe_probe.rs b/crates/dbx-core/tests/live_sqlserver_xe_probe.rsindex 97b54c7e3a..5f406c6813 100644--- a/crates/dbx-core/tests/live_sqlserver_xe_probe.rs+++ b/crates/dbx-core/tests/live_sqlserver_xe_probe.rs@@ -45,6 +45,7 @@ async fn sqlserver_extended_events_probe_captures_rpc_and_batch_events() {&user,&password,Some(&database),+ None,Duration::from_secs(15),).await@@ -145,6 +146,7 @@ async fn sqlserver_extended_events_probe_captures_rpc_and_batch_events() {&user,&password,Some(&database),+ None,Duration::from_secs(15),).await?;diff --git a/crates/dbx-core/tests/sqlserver_batch_results.rs b/crates/dbx-core/tests/sqlserver_batch_results.rsindex a6bb4a9b0a..bd09824572 100644--- a/crates/dbx-core/tests/sqlserver_batch_results.rs+++ b/crates/dbx-core/tests/sqlserver_batch_results.rs@@ -9,9 +9,18 @@ async fn connect_sqlserver() -> sqlserver::SqlServerClient {let user = std::env::var("DBX_TEST_SQLSERVER_USER").unwrap_or_else(|_| "sa".to_string());let password = std::env::var("DBX_TEST_SQLSERVER_PASSWORD").expect("DBX_TEST_SQLSERVER_PASSWORD");let database = std::env::var("DBX_TEST_SQLSERVER_DATABASE").unwrap_or_else(|_| "master".to_string());- sqlserver::connect_with_port_explicit(&host, port, true, &user, &password, Some(&database), Duration::from_secs(15))- .await- .expect("connect to SQL Server")+ sqlserver::connect_with_port_explicit(+ &host,+ port,+ true,+ &user,+ &password,+ Some(&database),+ None,+ Duration::from_secs(15),+ )+ .await+ .expect("connect to SQL Server")}#[tokio::test]diff --git a/crates/dbx-core/tests/sqlserver_server_messages.rs b/crates/dbx-core/tests/sqlserver_server_messages.rsindex 4e2908bee0..697acf03a0 100644--- a/crates/dbx-core/tests/sqlserver_server_messages.rs+++ b/crates/dbx-core/tests/sqlserver_server_messages.rs@@ -7,9 +7,18 @@ async fn connect_sqlserver() -> sqlserver::SqlServerClient {let user = std::env::var("DBX_TEST_SQLSERVER_USER").unwrap_or_else(|_| "sa".to_string());let password = std::env::var("DBX_TEST_SQLSERVER_PASSWORD").expect("DBX_TEST_SQLSERVER_PASSWORD");let database = std::env::var("DBX_TEST_SQLSERVER_DATABASE").unwrap_or_else(|_| "master".to_string());- sqlserver::connect_with_port_explicit(&host, port, true, &user, &password, Some(&database), Duration::from_secs(15))- .await- .expect("connect to SQL Server")+ sqlserver::connect_with_port_explicit(+ &host,+ port,+ true,+ &user,+ &password,+ Some(&database),+ None,+ Duration::from_secs(15),+ )+ .await+ .expect("connect to SQL Server")}#[tokio::test]diff --git a/crates/dbx-core/tests/support/sqlserver_live_observer.rs b/crates/dbx-core/tests/support/sqlserver_live_observer.rsindex a344531f15..66f9380938 100644--- a/crates/dbx-core/tests/support/sqlserver_live_observer.rs+++ b/crates/dbx-core/tests/support/sqlserver_live_observer.rs@@ -22,12 +22,22 @@ pub async fn connect_with_port_explicit(user: &str,password: &str,database: Option<&str>,+ url_params: Option<&str>,timeout: Duration,) -> Result<SqlServerClient, String> {if !sql_server_2000() {- return native::connect_with_port_explicit(host, port, port_explicit, user, password, database, timeout)- .await- .map(|client| SqlServerClient::Native(Box::new(client)));+ return native::connect_with_port_explicit(+ host,+ port,+ port_explicit,+ user,+ password,+ database,+ url_params,+ timeout,+ )+ .await+ .map(|client| SqlServerClient::Native(Box::new(client)));}let mut client = AgentDriverClient::spawn(AgentLaunchSpec::java_jar(std::env::var("DBX_TEST_SQLSERVER_JAVA").expect("Java 21 executable"),diff --git a/crates/dbx-driver-sqlserver/src/sqlserver.rs b/crates/dbx-driver-sqlserver/src/sqlserver.rsindex cc75e2dbd3..659b0edcaa 100644--- a/crates/dbx-driver-sqlserver/src/sqlserver.rs+++ b/crates/dbx-driver-sqlserver/src/sqlserver.rs@@ -325,12 +325,17 @@ pub async fn connect(user: &str,pass: &str,database: Option<&str>,- _url_params: Option<&str>,+ url_params: Option<&str>,timeout: Duration,) -> Result<SqlServerClient, String> {- connect_with_port_explicit(host, port, false, user, pass, database, timeout).await+ connect_with_port_explicit(host, port, false, user, pass, database, url_params, timeout).await}+/// Connect with an explicit port flag and optional JDBC-style URL params.+///+/// When `encrypt=false` / `sqlserverEncryption=disabled` is present, skip the+/// `EncryptionLevel::Required` attempt so non-TLS servers are not blocked for a+/// full connect timeout before the Off/NotSupported fallbacks run.pub async fn connect_with_port_explicit(host: &str,port: u16,@@ -338,8 +343,16 @@ pub async fn connect_with_port_explicit(user: &str,pass: &str,database: Option<&str>,+ url_params: Option<&str>,timeout: Duration,) -> Result<SqlServerClient, String> {+ if sqlserver_native_encryption_disabled(url_params) {+ let skipped = "encryption was disabled by encrypt=false / sqlserverEncryption=disabled".to_string();+ return try_connect_legacy_sqlserver_encryption(host, port, port_explicit, user, pass, database, timeout)+ .await+ .map_err(|fallback_errors| sqlserver_connect_failure_message(&skipped, &fallback_errors));+ }+match try_connect(host, port, port_explicit, user, pass, database, tiberius::EncryptionLevel::Required, timeout).await{diff --git a/crates/dbx-driver-sqlserver/tests/live_sqlserver_2000_native.rs b/crates/dbx-driver-sqlserver/tests/live_sqlserver_2000_native.rsindex f2df5671e6..134b32f03b 100644--- a/crates/dbx-driver-sqlserver/tests/live_sqlserver_2000_native.rs+++ b/crates/dbx-driver-sqlserver/tests/live_sqlserver_2000_native.rs@@ -17,6 +17,7 @@ async fn native_sqlserver_2000_connects_and_checks_manual_transaction_state() {"sa",&password,Some("dbx_manual_test"),+ None,Duration::from_secs(10),)).catch_unwind()@@ -61,6 +62,7 @@ async fn native_sqlserver_2000_rpc_handles_long_unicode_binary_and_nulls() {"sa",&password,Some("dbx_manual_test"),+ None,Duration::from_secs(10),).awaitdiff --git a/crates/dbx-drivers/tests/live_sqlserver_issue_9984_real.rs b/crates/dbx-drivers/tests/live_sqlserver_issue_9984_real.rsindex ce96e67f04..35acaa619a 100644--- a/crates/dbx-drivers/tests/live_sqlserver_issue_9984_real.rs+++ b/crates/dbx-drivers/tests/live_sqlserver_issue_9984_real.rs@@ -19,6 +19,7 @@ async fn live_sqlserver_issue_9984_real_round_trip() {&user,&password,Some(&database),+ None,Duration::from_secs(15),).await