Added code to verify database version and upgrade database from 2.2 (mRemoteNG 1.66 or earlier) to 2.3 (mRemoteNG 1.67).

This commit is contained in:
Riley McArdle
2011-06-05 12:06:07 -05:00
parent 69ab11eb5f
commit 0bed923a4d
3 changed files with 81 additions and 1 deletions

View File

@@ -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
@@ -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)
@@ -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

View File

@@ -2150,6 +2150,15 @@ Namespace My.Resources
End Get
End Property
'''<summary>
''' Looks up a localized string similar to The database version {0} is not compatible with this version of {1}..
'''</summary>
Friend ReadOnly Property strErrorBadDatabaseVersion() As String
Get
Return ResourceManager.GetString("strErrorBadDatabaseVersion", resourceCulture)
End Get
End Property
'''<summary>
''' Looks up a localized string similar to Error code {0}..
'''</summary>
@@ -2159,6 +2168,15 @@ Namespace My.Resources
End Get
End Property
'''<summary>
''' Looks up a localized string similar to The connection list could not be saved..
'''</summary>
Friend ReadOnly Property strErrorConnectionListSaveFailed() As String
Get
Return ResourceManager.GetString("strErrorConnectionListSaveFailed", resourceCulture)
End Get
End Property
'''<summary>
''' Looks up a localized string similar to Errors.
'''</summary>
@@ -2168,6 +2186,15 @@ Namespace My.Resources
End Get
End Property
'''<summary>
''' Looks up a localized string similar to VerifyDatabaseVersion (Config.Connections.Save) failed. {0}.
'''</summary>
Friend ReadOnly Property strErrorVerifyDatabaseVersionFailed() As String
Get
Return ResourceManager.GetString("strErrorVerifyDatabaseVersionFailed", resourceCulture)
End Get
End Property
'''<summary>
''' Looks up a localized string similar to Expand all folders.
'''</summary>

View File

@@ -1,4 +1,4 @@
<?xml version="1.0" encoding="utf-8"?>
<?xml version="1.0" encoding="utf-8"?>
<root>
<!--
Microsoft ResX Schema
@@ -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>