From d7e9ba96cd865b5a6942e7fb00b5490ce38a1194 Mon Sep 17 00:00:00 2001 From: Vladimir Date: Thu, 7 Sep 2023 01:00:55 +0300 Subject: [PATCH] asing provider by connection string --- .../ConnectionStringEditViewModel.cs | 20 +++++++++++++++++-- 1 file changed, 18 insertions(+), 2 deletions(-) diff --git a/src/Orc.DataAccess.Xaml/Controls/ConnectionStringBuilder/ViewModel/ConnectionStringEditViewModel.cs b/src/Orc.DataAccess.Xaml/Controls/ConnectionStringBuilder/ViewModel/ConnectionStringEditViewModel.cs index 11e57c7..8c44189 100644 --- a/src/Orc.DataAccess.Xaml/Controls/ConnectionStringBuilder/ViewModel/ConnectionStringEditViewModel.cs +++ b/src/Orc.DataAccess.Xaml/Controls/ConnectionStringBuilder/ViewModel/ConnectionStringEditViewModel.cs @@ -152,9 +152,25 @@ private void SetInitialState() } var allKnownProviders = Database.DbProvider.GetRegisteredProviders().Select(x => x.Value.Info).ToArray(); - if (allKnownProviders.Length == 1) + foreach (var provider in allKnownProviders) { - DbProvider = allKnownProviders.Single(); + var connectionString = provider.CreateConnectionString(_initialConnectionString); + if (connectionString is null) + { + continue; + } + + try + { + using var testConnection = provider.GetProvider().CreateConnection(connectionString.ToString()); + } + catch + { + continue; + } + + DbProvider = provider; + ConnectionString = connectionString; } }