diff --git a/Lite/Models/ServerConnection.cs b/Lite/Models/ServerConnection.cs index b9211dec..a07c227f 100644 --- a/Lite/Models/ServerConnection.cs +++ b/Lite/Models/ServerConnection.cs @@ -70,6 +70,13 @@ public bool UseWindowsAuth /// public string? DatabaseName { get; set; } + /// + /// When true, sets ApplicationIntent=ReadOnly on the connection string. + /// Required for connecting to AG listener read-only replicas and + /// Azure SQL Business Critical / Managed Instance built-in read replicas. + /// + public bool ReadOnlyIntent { get; set; } = false; + /// /// Display-only property for showing authentication type in UI. /// @@ -153,7 +160,8 @@ private string BuildConnectionString(string? username, string? password) ConnectTimeout = 15, CommandTimeout = 60, TrustServerCertificate = TrustServerCertificate, - MultipleActiveResultSets = true + MultipleActiveResultSets = true, + ApplicationIntent = ReadOnlyIntent ? ApplicationIntent.ReadOnly : ApplicationIntent.ReadWrite }; // Set encryption mode diff --git a/Lite/Windows/AddServerDialog.xaml b/Lite/Windows/AddServerDialog.xaml index d02d51dd..e63f7b9c 100644 --- a/Lite/Windows/AddServerDialog.xaml +++ b/Lite/Windows/AddServerDialog.xaml @@ -88,6 +88,9 @@ + diff --git a/Lite/Windows/AddServerDialog.xaml.cs b/Lite/Windows/AddServerDialog.xaml.cs index 84fa183f..de2c52b9 100644 --- a/Lite/Windows/AddServerDialog.xaml.cs +++ b/Lite/Windows/AddServerDialog.xaml.cs @@ -59,6 +59,7 @@ public AddServerDialog(ServerManager serverManager, ServerConnection existing) : FavoriteCheckBox.IsChecked = existing.IsFavorite; DescriptionTextBox.Text = existing.Description ?? ""; DatabaseNameBox.Text = existing.DatabaseName ?? ""; + ReadOnlyIntentCheckBox.IsChecked = existing.ReadOnlyIntent; // Set authentication mode if (existing.AuthenticationType == AuthenticationTypes.EntraMFA) @@ -140,7 +141,10 @@ private SqlConnectionStringBuilder BuildConnectionBuilder() ApplicationName = "PerformanceMonitorLite", ConnectTimeout = 10, TrustServerCertificate = TrustCertCheckBox.IsChecked == true, - Encrypt = ParseEncryptOption(GetSelectedEncryptMode()) + Encrypt = ParseEncryptOption(GetSelectedEncryptMode()), + ApplicationIntent = ReadOnlyIntentCheckBox.IsChecked == true + ? ApplicationIntent.ReadOnly + : ApplicationIntent.ReadWrite }; if (WindowsAuthRadio.IsChecked == true) @@ -342,6 +346,7 @@ private async void SaveButton_Click(object sender, RoutedEventArgs e) AddedServer.IsFavorite = FavoriteCheckBox.IsChecked == true; AddedServer.Description = DescriptionTextBox.Text.Trim(); AddedServer.DatabaseName = string.IsNullOrWhiteSpace(DatabaseNameBox.Text) ? null : DatabaseNameBox.Text.Trim(); + AddedServer.ReadOnlyIntent = ReadOnlyIntentCheckBox.IsChecked == true; _serverManager.UpdateServer(AddedServer, username, password); } @@ -358,7 +363,8 @@ private async void SaveButton_Click(object sender, RoutedEventArgs e) EncryptMode = GetSelectedEncryptMode(), IsFavorite = FavoriteCheckBox.IsChecked == true, Description = DescriptionTextBox.Text.Trim(), - DatabaseName = string.IsNullOrWhiteSpace(DatabaseNameBox.Text) ? null : DatabaseNameBox.Text.Trim() + DatabaseName = string.IsNullOrWhiteSpace(DatabaseNameBox.Text) ? null : DatabaseNameBox.Text.Trim(), + ReadOnlyIntent = ReadOnlyIntentCheckBox.IsChecked == true }; _serverManager.AddServer(AddedServer, username, password);