Skip to content

Commit

Permalink
Added code to verify database version and upgrade database from 2.2 (…
Browse files Browse the repository at this point in the history
…mRemoteNG 1.66 or earlier) to 2.3 (mRemoteNG 1.67).
  • Loading branch information
Riley McArdle committed Jun 5, 2011
1 parent 69ab11e commit 0bed923
Show file tree
Hide file tree
Showing 3 changed files with 81 additions and 1 deletion.
44 changes: 44 additions & 0 deletions mRemoteV1/Config/Config.Connections.Save.vb
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ Imports System.Globalization
Imports mRemoteNG.App.Runtime
Imports System.Data.SqlClient
Imports mRemoteNG.Tools.Misc
Imports mRemoteNG.My.Resources

Namespace Config
Namespace Connections
Expand Down Expand Up @@ -173,6 +174,44 @@ Namespace Config
#End Region

#Region "SQL"
Private Function VerifyDatabaseVersion(ByVal sqlConnection As SqlConnection) As Boolean
Dim isVerified As Boolean = False
Dim sqlDataReader As SqlDataReader = Nothing
Dim databaseVersion As System.Version = Nothing
Try
Dim sqlCommand As New SqlCommand("SELECT * FROM tblRoot", sqlConnection)
sqlDataReader = sqlCommand.ExecuteReader()
sqlDataReader.Read()

Dim enCulture As CultureInfo = New CultureInfo("en-US")
databaseVersion = New System.Version(Convert.ToDouble(sqlDataReader.Item("confVersion"), enCulture))

sqlDataReader.Close()

If databaseVersion.CompareTo(New System.Version(2, 2)) = 0 Then ' 2.2
mC.AddMessage(Messages.MessageClass.InformationMsg, String.Format("Upgrading database from version {0} to version {1}.", databaseVersion.ToString, "2.3"))
sqlCommand = New SqlCommand("ALTER TABLE tblCons ADD EnableFontSmoothing bit NOT NULL DEFAULT 0, EnableDesktopComposition bit NOT NULL DEFAULT 0, InheritEnableFontSmoothing bit NOT NULL DEFAULT 0, InheritEnableDesktopComposition bit NOT NULL DEFAULT 0;", sqlConnection)
sqlCommand.ExecuteNonQuery()
databaseVersion = New System.Version(2, 3)
End If

If databaseVersion.CompareTo(New System.Version(2, 3)) = 0 Then ' 2.3
isVerified = True
End If

If isVerified = False Then
mC.AddMessage(Messages.MessageClass.WarningMsg, String.Format(strErrorBadDatabaseVersion, databaseVersion.ToString, My.Application.Info.ProductName))
End If
Catch ex As Exception
mC.AddMessage(Messages.MessageClass.ErrorMsg, String.Format(strErrorVerifyDatabaseVersionFailed, ex.Message))
Finally
If sqlDataReader IsNot Nothing Then
If Not sqlDataReader.IsClosed Then sqlDataReader.Close()
End If
End Try
Return isVerified
End Function

Private Sub SaveToSQL()
If _SQLUsername <> "" Then
sqlCon = New SqlConnection("Data Source=" & _SQLHost & ";Initial Catalog=" & _SQLDatabaseName & ";User Id=" & _SQLUsername & ";Password=" & _SQLPassword)
Expand All @@ -182,6 +221,11 @@ Namespace Config

sqlCon.Open()

If Not VerifyDatabaseVersion(sqlCon) Then
mC.AddMessage(Messages.MessageClass.ErrorMsg, strErrorConnectionListSaveFailed)
Return
End If

Dim tN As TreeNode
tN = RootTreeNode.Clone

Expand Down
27 changes: 27 additions & 0 deletions mRemoteV1/My Project/Resources.Designer.vb

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

11 changes: 10 additions & 1 deletion mRemoteV1/My Project/Resources.resx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<?xml version="1.0" encoding="utf-8"?>
<?xml version="1.0" encoding="utf-8"?>
<root>
<!--
Microsoft ResX Schema
Expand Down Expand Up @@ -2337,4 +2337,13 @@ Error Description: {1}</value>
<data name="strLabelSQLServerDatabaseName" xml:space="preserve">
<value>Database:</value>
</data>
<data name="strErrorVerifyDatabaseVersionFailed">
<value xml:space="preserve">VerifyDatabaseVersion (Config.Connections.Save) failed. {0}</value>
</data>
<data name="strErrorConnectionListSaveFailed">
<value xml:space="preserve">The connection list could not be saved.</value>
</data>
<data name="strErrorBadDatabaseVersion">
<value xml:space="preserve">The database version {0} is not compatible with this version of {1}.</value>
</data>
</root>

0 comments on commit 0bed923

Please sign in to comment.