Skip to content

Commit be47984

Browse files
committed
Fix issue deploying to an existing empty database
#1563
1 parent 3d89d85 commit be47984

File tree

2 files changed

+28
-10
lines changed

2 files changed

+28
-10
lines changed

DBADash/Upgrade/DBValidations.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ public static bool DBExists(string connectionString)
3535
connectionString = builder.ConnectionString;
3636

3737
using var cn = new SqlConnection(connectionString);
38-
using var cmd = new SqlCommand("SELECT CASE WHEN EXISTS(SELECT 1 FROM sys.databases WHERE name = @db) THEN CAST(1 as BIT) ELSE CAST(0 as BIT) END as DBExists",cn);
38+
using var cmd = new SqlCommand("SELECT CASE WHEN EXISTS(SELECT 1 FROM sys.databases WHERE name = @db) THEN CAST(1 as BIT) ELSE CAST(0 as BIT) END as DBExists", cn);
3939
cn.Open();
4040
cmd.Parameters.AddWithValue("@db", db);
4141
return (bool)cmd.ExecuteScalar();
@@ -73,7 +73,7 @@ WHERE type NOT IN('S','IT','SQ')
7373
)
7474
AND DB_ID()>4
7575
BEGIN
76-
SELECT '0.0.0.0' AS Version,1 AS DeployInProgress
76+
SELECT '0.0.0.0' AS Version,CAST(0 AS BIT) AS DeployInProgress
7777
END
7878
ELSE
7979
BEGIN

DBADashGUI/Main.cs

Lines changed: 26 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -414,22 +414,22 @@ private static bool CheckRepositoryDBConnection(string connectionString)
414414
return connectionCheckPassed;
415415
}
416416

417-
private static void WaitForDBUpgrade(string connectionString)
417+
private static void WaitForDBUpgrade(string connectionString, string caption = "Upgrade in progress", string heading = "Repository database upgrade is in progress. ", string text = "Please wait for this to complete. If you continue, the application might be unstable. \n\nThis dialog will close automatically...", bool allowContinue = true)
418418
{
419419
var closeButton = new TaskDialogButton("Close");
420420
var page = new TaskDialogPage
421421
{
422-
Caption = "Upgrade in progress",
423-
Heading = "Repository database upgrade is in progress. ",
424-
Text = "Please wait for this to complete. If you continue, the application might be unstable. \n\nThis dialog will close automatically...",
422+
Caption = caption,
423+
Heading = heading,
424+
Text = text,
425425
Icon = TaskDialogIcon.Information,
426-
Buttons = new TaskDialogButtonCollection() { closeButton, TaskDialogButton.Continue },
426+
Buttons = new TaskDialogButtonCollection() { closeButton },
427427
SizeToContent = true,
428428
ProgressBar = new TaskDialogProgressBar()
429429
{
430430
State = TaskDialogProgressBarState.Marquee,
431431
},
432-
DefaultButton = TaskDialogButton.Continue,
432+
DefaultButton = closeButton,
433433
Expander = new TaskDialogExpander()
434434
{
435435
Text = "If this process takes longer than expected, click the 'View Service Log' button on the service config tool to check the logs.",
@@ -438,12 +438,25 @@ private static void WaitForDBUpgrade(string connectionString)
438438
Position = TaskDialogExpanderPosition.AfterFootnote
439439
},
440440
};
441+
if (allowContinue)
442+
{
443+
page.Buttons.Add(TaskDialogButton.Continue);
444+
page.DefaultButton = TaskDialogButton.Continue;
445+
}
441446

442447
var tmr = new Timer() { Interval = 1000, Enabled = true };
443448
tmr.Tick += (s, e) =>
444449
{
445-
var dbVersion = DBValidations.GetDBVersion(connectionString);
446-
if (dbVersion.DeployInProgress) return;
450+
try
451+
{
452+
var dbVersion = DBValidations.GetDBVersion(connectionString);
453+
if (dbVersion.DeployInProgress || dbVersion.Version == Version.Parse("0.0.0.0")) return;
454+
}
455+
catch (Exception ex)
456+
{
457+
Task.Delay(1000);
458+
return;
459+
}
447460
tmr.Stop();
448461
tmr.Dispose();
449462
page.BoundDialog?.Close();
@@ -466,6 +479,11 @@ private async Task CheckVersion(string connectionString)
466479
WaitForDBUpgrade(connectionString);
467480
dbVersion = DBValidations.GetDBVersion(connectionString);
468481
}
482+
if (dbVersion.Version == Version.Parse("0.0.0.0"))
483+
{
484+
WaitForDBUpgrade(connectionString, "Database Deployment", "Waiting for first time database deployment to complete. ", "Please wait for the deployment to complete. \nIf this doesn't occur within a few minutes, check that the service is started. Check the log file for errors.", false);
485+
dbVersion = DBValidations.GetDBVersion(connectionString);
486+
}
469487
var compare = (new Version(appVersion.Major, appVersion.Minor)).CompareTo(new Version(dbVersion.Version.Major, dbVersion.Version.Minor));
470488
if (compare < 0)
471489
{

0 commit comments

Comments
 (0)