Skip to content

The easy-to-use open source Business Intelligence and Embedded Analytics tool that lets everyone work with data :bar_chart:

Only set SQL Server instanceName when specified (#81595)

metambende7cedfeb67d
diff --git a/modules/drivers/sqlserver/src/metabase/driver/sqlserver.clj b/modules/drivers/sqlserver/src/metabase/driver/sqlserver.clj
index 5815ee22670..5dd4d20389d 100644
--- a/modules/drivers/sqlserver/src/metabase/driver/sqlserver.clj
+++ b/modules/drivers/sqlserver/src/metabase/driver/sqlserver.clj
@@ -212,13 +212,16 @@
;; https://social.technet.microsoft.com/Forums/sqlserver/en-US/bc1373f5-cb40-479d-9770-da1221a0bc95/connecting-to-sql-server-in-a-different-domain-using-jdbc-driver?forum=sqldataaccess
:user (str (when domain (str domain "\\"))
user)
- :instanceName instance
:encrypt (boolean ssl)
;; only crazy people would want this. See https://docs.microsoft.com/en-us/sql/connect/jdbc/configuring-how-java-sql-time-values-are-sent-to-the-server?view=sql-server-ver15
:sendTimeAsDatetime false}
;; only include `port` if it is specified; leave out for dynamic port: see
;; https://github.com/metabase/metabase/issues/7597
- (merge (when port {:port port}))
+ ;; only include `instanceName` if supplied — mssql-jdbc treats an empty string as a named instance and
+ ;; initiates SQL Server Browser lookup, which breaks Microsoft Fabric / Synapse serverless endpoints
+ ;; that drop the connection whenever the property is present (#81270)
+ (merge (when port {:port port})
+ (when-not (str/blank? instance) {:instanceName instance}))
(sql-jdbc.common/handle-additional-options details, :seperator-style :semicolon)))
(def ^:private disallowed-additional-opts
diff --git a/modules/drivers/sqlserver/test/metabase/driver/sqlserver_test.clj b/modules/drivers/sqlserver/test/metabase/driver/sqlserver_test.clj
index 82ab7272ac7..2bb59e61db4 100644
--- a/modules/drivers/sqlserver/test/metabase/driver/sqlserver_test.clj
+++ b/modules/drivers/sqlserver/test/metabase/driver/sqlserver_test.clj
@@ -192,7 +192,6 @@
config/local-process-uuid)
:database "birddb"
:encrypt false
- :instanceName nil
:loginTimeout 10
:password "toucans"
:port 1433
@@ -206,7 +205,19 @@
:db "birddb"
:host "localhost"
:port 1433
- :additional-options "trustServerCertificate=false"})))))
+ :additional-options "trustServerCertificate=false"}))))
+ (testing "instanceName is omitted when no instance is supplied — mssql-jdbc treats an empty string as a named instance, which breaks Microsoft Fabric and Synapse serverless endpoints (#81270)"
+ (doseq [instance [nil "" " "]]
+ (testing (pr-str instance)
+ (is (not (contains? (sql-jdbc.conn/connection-details->spec :sqlserver
+ {:user "cam", :password "toucans", :db "birddb",
+ :host "localhost", :port 1433, :instance instance})
+ :instanceName))))))
+ (testing "instanceName is passed through when the user supplies one"
+ (is (= "MYINSTANCE"
+ (:instanceName (sql-jdbc.conn/connection-details->spec :sqlserver
+ {:user "cam", :password "toucans", :db "birddb",
+ :host "localhost", :instance "MYINSTANCE"}))))))
(deftest ^:parallel reject-details-with-dangerous-additional-options-test
(mt/test-driver :sqlserver