Esempio n. 1
0
 private void ConnectToSqlDb()
 {
     try
     {
         _sqlConnector.Connect();
     }
     catch (Exception e)
     {
         Runtime.MessageCollector.AddMessage(MessageClass.WarningMsg, "Unable to connect to Sql DB to check for updates." + Environment.NewLine + e.Message, true);
     }
 }
        public SqlConnectionListMetaData GetDatabaseMetaData(SqlDatabaseConnector sqlDatabaseConnector)
        {
            SqlConnectionListMetaData metaData;
            SqlDataReader             sqlDataReader = null;

            try
            {
                var sqlCommand = new SqlCommand("SELECT * FROM tblRoot", sqlDatabaseConnector.SqlConnection);
                if (!sqlDatabaseConnector.IsConnected)
                {
                    sqlDatabaseConnector.Connect();
                }
                sqlDataReader = sqlCommand.ExecuteReader();
                if (!sqlDataReader.HasRows)
                {
                    return(null); // assume new empty database
                }
                else
                {
                    sqlDataReader.Read();
                }

                metaData = new SqlConnectionListMetaData
                {
                    Name        = sqlDataReader["Name"] as string ?? "",
                    Protected   = sqlDataReader["Protected"] as string ?? "",
                    Export      = (bool)sqlDataReader["Export"],
                    ConfVersion = new Version(Convert.ToString(sqlDataReader["confVersion"], CultureInfo.InvariantCulture))
                };
            }
            catch (Exception ex)
            {
                Runtime.MessageCollector.AddMessage(MessageClass.ErrorMsg, $"Retrieving database version failed. {ex}");
                throw;
            }
            finally
            {
                if (sqlDataReader != null && !sqlDataReader.IsClosed)
                {
                    sqlDataReader.Close();
                }
            }
            return(metaData);
        }
Esempio n. 3
0
        private void SaveToSql()
        {
            var sqlConnector = new SqlDatabaseConnector();

            sqlConnector.Connect();

            if (!VerifyDatabaseVersion(sqlConnector))
            {
                Runtime.MessageCollector.AddMessage(MessageClass.ErrorMsg, Language.strErrorConnectionListSaveFailed);
                return;
            }

            var rootTreeNode = Runtime.ConnectionTreeModel.RootNodes.OfType <RootNodeInfo>().First();

            UpdateRootNodeTable(rootTreeNode, sqlConnector);
            UpdateConnectionsTable(rootTreeNode, sqlConnector);
            UpdateUpdatesTable(sqlConnector);

            sqlConnector.Disconnect();
            sqlConnector.Dispose();
        }
Esempio n. 4
0
        private Version GetDatabaseVersion(SqlDatabaseConnector sqlDatabaseConnector)
        {
            Version       databaseVersion;
            SqlDataReader sqlDataReader = null;

            try
            {
                var sqlCommand = new SqlCommand("SELECT * FROM tblRoot", sqlDatabaseConnector.SqlConnection);
                if (!sqlDatabaseConnector.IsConnected)
                {
                    sqlDatabaseConnector.Connect();
                }
                sqlDataReader = sqlCommand.ExecuteReader();
                if (!sqlDataReader.HasRows)
                {
                    return(new Version()); // assume new empty database
                }
                else
                {
                    sqlDataReader.Read();
                }
                databaseVersion =
                    new Version(Convert.ToString(sqlDataReader["confVersion"], CultureInfo.InvariantCulture));
            }
            catch (Exception ex)
            {
                Runtime.MessageCollector.AddMessage(MessageClass.ErrorMsg, $"Retrieving database version failed. {ex}");
                throw;
            }
            finally
            {
                if (sqlDataReader != null && !sqlDataReader.IsClosed)
                {
                    sqlDataReader.Close();
                }
            }
            return(databaseVersion);
        }