Пример #1
0
        public void ReliableConnectionHelperTest()
        {
            using (SelfCleaningTempFile queryTempFile = new SelfCleaningTempFile())
            {
                var            result     = LiveConnectionHelper.InitLiveConnectionInfo(null, queryTempFile.FilePath);
                ConnectionInfo connInfo   = result.ConnectionInfo;
                DbConnection   connection = connInfo.ConnectionTypeToConnectionMap[ConnectionType.Default];
                connection.Open();

                Assert.True(connection.State == ConnectionState.Open, "Connection should be open.");
                Assert.True(ReliableConnectionHelper.IsAuthenticatingDatabaseMaster(connection));

                SqlConnectionStringBuilder builder = new SqlConnectionStringBuilder();
                Assert.True(ReliableConnectionHelper.IsAuthenticatingDatabaseMaster(builder, null));
                ReliableConnectionHelper.TryAddAlwaysOnConnectionProperties(builder, new SqlConnectionStringBuilder());

                Assert.NotNull(ReliableConnectionHelper.GetServerName(connection));
                Assert.NotNull(ReliableConnectionHelper.ReadServerVersion(connection));

                Assert.NotNull(ReliableConnectionHelper.GetAsSqlConnection(connection));

                ReliableConnectionHelper.ServerInfo info = ReliableConnectionHelper.GetServerVersion(connection);
                Assert.NotNull(ReliableConnectionHelper.IsVersionGreaterThan2012RTM(info));
            }
        }
Пример #2
0
        public static bool ValidatePaths(FileBrowserValidateEventArgs args, out string errorMessage)
        {
            errorMessage = string.Empty;
            bool          result     = true;
            SqlConnection connection = null;

            if (args != null)
            {
                ConnectionInfo connInfo;
                ConnectionService.Instance.TryFindConnection(args.OwnerUri, out connInfo);
                if (connInfo != null)
                {
                    DbConnection dbConnection = null;
                    connInfo.TryGetConnection(Connection.ConnectionType.Default, out dbConnection);
                    if (dbConnection != null)
                    {
                        connection = ReliableConnectionHelper.GetAsSqlConnection(dbConnection);
                    }
                }
            }

            if (connection != null)
            {
                foreach (string filePath in args.FilePaths)
                {
                    bool isFolder;
                    bool existing = IsPathExisting(connection, filePath, out isFolder);

                    if (existing)
                    {
                        if (isFolder)
                        {
                            errorMessage = SR.BackupPathIsFolderError;
                        }
                    }
                    else
                    {
                        if (args.ServiceType == FileValidationServiceConstants.Backup)
                        {
                            errorMessage = IsFolderPathExisting(connection, filePath);
                        }
                        else if (args.ServiceType == FileValidationServiceConstants.Restore)
                        {
                            errorMessage = SR.InvalidBackupPathError;
                        }
                    }

                    if (!string.IsNullOrEmpty(errorMessage))
                    {
                        result = false;
                        break;
                    }
                }
            }

            return(result);
        }
        public void ReliableConnectionHelperTest()
        {
            ScriptFile     scriptFile;
            ConnectionInfo connInfo = TestObjects.InitLiveConnectionInfo(out scriptFile);

            Assert.True(ReliableConnectionHelper.IsAuthenticatingDatabaseMaster(connInfo.SqlConnection));

            SqlConnectionStringBuilder builder = new SqlConnectionStringBuilder();

            Assert.True(ReliableConnectionHelper.IsAuthenticatingDatabaseMaster(builder));
            ReliableConnectionHelper.TryAddAlwaysOnConnectionProperties(builder, new SqlConnectionStringBuilder());

            Assert.NotNull(ReliableConnectionHelper.GetServerName(connInfo.SqlConnection));
            Assert.NotNull(ReliableConnectionHelper.ReadServerVersion(connInfo.SqlConnection));

            Assert.NotNull(ReliableConnectionHelper.GetAsSqlConnection(connInfo.SqlConnection));

            ServerInfo info = ReliableConnectionHelper.GetServerVersion(connInfo.SqlConnection);

            Assert.NotNull(ReliableConnectionHelper.IsVersionGreaterThan2012RTM(info));
        }
        public void ReliableConnectionHelperTest()
        {
            var            result     = LiveConnectionHelper.InitLiveConnectionInfo();
            ConnectionInfo connInfo   = result.ConnectionInfo;
            DbConnection   connection = connInfo.ConnectionTypeToConnectionMap[ConnectionType.Default];


            Assert.True(ReliableConnectionHelper.IsAuthenticatingDatabaseMaster(connection));

            SqlConnectionStringBuilder builder = new SqlConnectionStringBuilder();

            Assert.True(ReliableConnectionHelper.IsAuthenticatingDatabaseMaster(builder));
            ReliableConnectionHelper.TryAddAlwaysOnConnectionProperties(builder, new SqlConnectionStringBuilder());

            Assert.NotNull(ReliableConnectionHelper.GetServerName(connection));
            Assert.NotNull(ReliableConnectionHelper.ReadServerVersion(connection));

            Assert.NotNull(ReliableConnectionHelper.GetAsSqlConnection(connection));

            ReliableConnectionHelper.ServerInfo info = ReliableConnectionHelper.GetServerVersion(connection);
            Assert.NotNull(ReliableConnectionHelper.IsVersionGreaterThan2012RTM(info));
        }