[810143] Database error 50000: Could not process the operation. Always On Availability Groups replica manager is disabled on this instance of SQL Server. Enable Always On Availability Groups, by using the SQL Server Configuration Manager.

1 - Sql command failed.
at ConfigWizard.Controls.PreCheckResultControl.btnRepair_Click(Object sender, EventArgs e)
at Quantum.Migrator.Base.ExtensionMethods.ExecuteWithLogging(IList`1 lCommands, MigrationContext context)
[810023] Error running statement:
declare @cmd nvarchar(max)
declare @DBName nvarchar(128)
declare @FGName nvarchar(256)
declare @DBFile VARCHAR(300)
declare @DBPath VARCHAR(300)
declare @ErrorMessage nvarchar(1000)= '50000'+char(9)+'2'+char(9)

select @DBName = DB_NAME()

select top 1 @DBFile = physical_name
from sys.database_files f
where f.type_desc = 'ROWS'

if isnull(@DBFile, '') = ''
begin
raiserror('#LDS#No database file found.|', 18, 2 ) with nowait
end

-- extract the path
if CHARINDEX('/', @DBFile) > 0
begin
select @DBPath = left(@DBFile, 1 +len(@DBFile) - charindex('/', reverse(@DBFile)) )
end
else
begin
select @DBPath= left(@DBFile, 1 +len(@DBFile) - charindex('\', reverse(@DBFile)) )
end

-- load the file group
select top 1 @FGName = name
from sys.filegroups g
where g.type = 'FX'

if isnull(@FGName, '') = ''
begin
raiserror('#LDS#No filegroup is defined. Create the filegroup first.|', 18, 2 ) with nowait
end

-- formate the sql query
select @cmd = concat('alter database "'
, @DBName
, '" ADD FILE( name='''
, @DBName
, '_mem'' , filename='''
, @DBPath
, @FGname
, ''') TO FILEGROUP '
, @FGName)

-- execute the command
begin try
exec sp_executesql @cmd
end try
begin catch
select @ErrorMessage = @ErrorMessage + ERROR_MESSAGE()
raiserror(@ErrorMessage, 18, 1 ) with nowait
end catch


at Quantum.Migrator.Base.ExtensionMethods.ExecuteWithLogging(IList`1 lCommands, MigrationContext context)
at Quantum.Migrator.Base.CommandBase.Execute(MigrationContext context)
at Quantum.Migrator.Base.MigrationContext.SqlExecuteNonQuery(IOperation sender, String strSql, String logMessage)
at VI.Base.SyncActions.Do[T,T1,T2](T1 p1, T2 p2, Func`3 function)
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
--- End of stack trace from previous location where exception was thrown ---
at VI.DB.DataAccess.ReadWriteDbSession.<SqlExecuteNonQueryAsync>d__21.MoveNext()
[810143] Database error 50000: Could not process the operation. Always On Availability Groups replica manager is disabled on this instance of SQL Server. Enable Always On Availability Groups, by using the SQL Server Configuration Manager. Then, restart the SQL Server service, and retry the currently operation. For information about how to enable and disable Always On Availability Groups, see SQL Server Books Online.
at VI.DB.DataAccess.ReadWriteDbSession.<SqlExecuteNonQueryAsync>d__21.MoveNext()
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
--- End of stack trace from previous location where exception was thrown ---
at VI.DB.DataAccess.ReadWriteDbSession.<IgnoreBrokenConnectionAsync>d__55`1.MoveNext()
at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
--- End of stack trace from previous location where exception was thrown ---
at VI.DB.DataAccess.ReadWriteDbSession.<_SqlExecuteNonQueryAsync>d__22.MoveNext()
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
--- End of stack trace from previous location where exception was thrown ---
at VI.DB.DataAccess.ReadOnlyDbSession.<ExecuteAndLogAsync>d__107`1.MoveNext()
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
--- End of stack trace from previous location where exception was thrown ---
at VI.DB.DataAccess.ReadOnlyDbSession.<ExecuteAndLogAsync>d__108`1.MoveNext()
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
--- End of stack trace from previous location where exception was thrown ---
at VI.DB.DataAccess.SafeDbCommand.<ExecuteNonQueryAsync>d__16.MoveNext()
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
--- End of stack trace from previous location where exception was thrown ---
at VI.DB.DataAccess.SafeDbCommand.<_CheckedAsync>d__43`1.MoveNext()

Crash report:

2023-07-10 16:40:45 Quantum.Migrator.Migrator Condition 0 returned true.
2023-07-10 16:40:45 Quantum.Migrator.Migrator Condition 1 returned false.
2023-07-10 16:40:45 Quantum.Migrator.Migrator 23 prechecks to execute.
2023-07-10 16:40:45 Quantum.Migrator.Migrator Running step QBM DatabaseCheckCollation (Database Check Collation).
2023-07-10 16:40:45 SqlLog (< 1 ms) - Pin DbSession to physical connection
2023-07-10 16:40:45 SqlLog (110 ms) -
if exists (
select top 1 1
from sys.columns c join sys.objects t on c.object_id = t.object_id
where t.type = 'TT'
and c.collation_name != 'SQL_Latin1_General_CP1_CI_AS' /* 35127 CI */
)
or exists (select top 1 1
FROM INFORMATION_SCHEMA.COLUMNS c join INFORMATION_SCHEMA.TABLES t on t.TABLE_NAME = c.TABLE_NAME
where c.DATA_TYPE like '%char%'
and c.COLLATION_NAME != 'SQL_Latin1_General_CP1_CI_AS' /* 35127 CI */
)
or exists (select top 1 1
from sys.databases b
where b.database_id = db_id()
and b.collation_name != 'SQL_Latin1_General_CP1_CI_AS' /* 35127 CI */
)
begin
raiserror('50000 2 wrong collation, use the file "QBM\Database\MSSQL\StartupPhase\ChangeCollation.sql" and follow the instructions', 18, 1) with nowait
end

2023-07-10 16:40:45 SqlLog (110 ms) - Pinned physical connection
2023-07-10 16:40:45 Quantum.Migrator.Migrator 1 - Sql command succeeded.
2023-07-10 16:40:45 Quantum.Migrator.Migrator Running step QBM InitialMigrationRunning (The database is in initial database migration state and the Configuration Wizard cannot be run.).
2023-07-10 16:40:45 SqlLog (< 1 ms) - Pin DbSession to physical connection
2023-07-10 16:40:45 SqlLog (41 ms) -
if exists (select top 1 1
from sys.tables t with (readpast) join sys.columns c with (readpast) on t.object_id = c.object_id
where t.name = 'DialogDatabase'
and c.name = 'InitialMigrationRunning'
)
begin
raiserror('#LDS#This database contains an aborted initial migration and cannot be used.|', 18, 1) with nowait
end

2023-07-10 16:40:45 SqlLog (41 ms) - Pinned physical connection
2023-07-10 16:40:45 Quantum.Migrator.Migrator 1 - Sql command succeeded.
2023-07-10 16:40:45 Quantum.Migrator.Migrator Running step QBM DatabaseSettings_ServerName (DatabaseSettings_servername).
2023-07-10 16:40:45 SqlLog (< 1 ms) - Pin DbSession to physical connection
2023-07-10 16:40:45 SqlLog (< 1 ms) -
set lock_timeout 10000
declare @ErrorMessage nvarchar(1000) = '50000' + CHAR(9) + '2' + CHAR(9)

if ISNULL(@@servername, N'') = N''
begin
select @ErrorMessage = concat(@ErrorMessage , 'Your @@servername must not be null')
raiserror(@ErrorMessage, 18, 2 ) with nowait
end
--else
-- begin
-- -- print 'Servername was OK'
-- end

set lock_timeout -1


2023-07-10 16:40:45 SqlLog (1 ms) - Pinned physical connection
2023-07-10 16:40:45 Quantum.Migrator.Migrator 1 - Sql command succeeded.
2023-07-10 16:40:45 Quantum.Migrator.Migrator Running step QBM DatabaseSettings_ServerProperty (DatabaseSettings_ServerProperty).
2023-07-10 16:40:45 SqlLog (< 1 ms) - Pin DbSession to physical connection
2023-07-10 16:40:45 SqlLog (< 1 ms) -
set lock_timeout 10000
declare @ErrorMessage nvarchar(1000) = '50000' + CHAR(9) + '2' + CHAR(9)


if isnull(convert(nvarchar(1000), SERVERPROPERTY('servername')), N'') != ISNULL(@@servername, N'')
begin
select @ErrorMessage = concat(@ErrorMessage
, '#LDS#Your @@Servername is different from Your ServerProperty (''servername'') '
)
raiserror (@ErrorMessage, 18, 2) WITH NOWAIT
end
--else
-- begin
-- -- print 'SERVERPROPERTY was OK'
-- end

set lock_timeout -1


2023-07-10 16:40:45 SqlLog (< 1 ms) - Pinned physical connection
2023-07-10 16:40:45 Quantum.Migrator.Migrator 1 - Sql command succeeded.
2023-07-10 16:40:45 Quantum.Migrator.Migrator Running step QBM DatabaseSettings_IsQuotedIdentifiersEnabled (DatabaseSettings_IsQuotedIdentifiersEnabled).
2023-07-10 16:40:45 SqlLog (< 1 ms) - Pin DbSession to physical connection
2023-07-10 16:40:45 SqlLog (2 ms) -
set lock_timeout 10000
declare @ErrorMessage nvarchar(1000) = '50000' + CHAR(9) + '2' + CHAR(9)
declare @cmd nvarchar(max)
declare @DBName nvarchar(128)
select @DBName = DB_NAME()

set quoted_identifier on

if 0 = ( select DATABASEPROPERTYex(@DBName, 'IsQuotedIdentifiersEnabled'))
begin
select @cmd = 'alter database "' + @DBName + '" set quoted_Identifier on '
exec sp_executesql @cmd
-- print 'IsQuotedIdentifiersEnabled switched on'
end
--else
-- begin
-- -- print 'IsQuotedIdentifiersEnabled was OK'
-- end

set lock_timeout -1


2023-07-10 16:40:45 SqlLog (2 ms) - Pinned physical connection
2023-07-10 16:40:45 Quantum.Migrator.Migrator 1 - Sql command succeeded.
2023-07-10 16:40:45 Quantum.Migrator.Migrator Running step QBM DatabaseSettings_IsArithmeticAbortEnabled (DatabaseSettings_IsArithmeticAbortEnabled).
2023-07-10 16:40:45 SqlLog (< 1 ms) - Pin DbSession to physical connection
2023-07-10 16:40:45 SqlLog (1 ms) -
set lock_timeout 10000
declare @ErrorMessage nvarchar(1000) = '50000' + CHAR(9) + '2' + CHAR(9)
declare @cmd nvarchar(max)
declare @DBName nvarchar(128)
select @DBName = DB_NAME()


if 0 = (select DATABASEPROPERTYEX(@DBName, 'IsArithmeticAbortEnabled'))
begin
select @cmd = '
alter database "' + @DBName + '" set arithabort on '
exec sp_executesql @cmd
-- print 'IsArithmeticAbortEnabled switched on'
end
--else
-- begin
-- -- print 'IsArithmeticAbortEnabled was OK'
-- end



-- select DATABASEPROPERTY('' + DB_NAME() + '', 'IsBulkCopy')
set lock_timeout -1


2023-07-10 16:40:45 SqlLog (1 ms) - Pinned physical connection
2023-07-10 16:40:45 Quantum.Migrator.Migrator 1 - Sql command succeeded.
2023-07-10 16:40:45 Quantum.Migrator.Migrator Running step QBM DatabaseSettings_COMPATIBILITY_LEVEL (DatabaseSettings_COMPATIBILITY_LEVEL).
2023-07-10 16:40:45 SqlLog (< 1 ms) - Pin DbSession to physical connection
2023-07-10 16:40:45 SqlLog (70 ms) -
set lock_timeout 10000
declare @ErrorMessage nvarchar(1000) = '50000' + CHAR(9) + '2' + CHAR(9)
declare @cmd nvarchar(max)
declare @DBName nvarchar(128)
select @DBName = DB_NAME()


if not (
select top 1 compatibility_level
from sys.databases
where name = @DBName
) in ('150','160')
begin
select @cmd = concat('
ALTER DATABASE "' , @DBName , '" SET COMPATIBILITY_LEVEL = ', '150'
)
exec sp_executesql @cmd
-- print 'COMPATIBILITY_LEVEL switched'
end
--else
-- begin
-- -- print 'COMPATIBILITY_LEVEL was OK'
-- end

set lock_timeout -1


2023-07-10 16:40:45 SqlLog (70 ms) - Pinned physical connection
2023-07-10 16:40:45 Quantum.Migrator.Migrator 1 - Sql command succeeded.
2023-07-10 16:40:45 Quantum.Migrator.Migrator Running step QBM DatabaseSettings_DEFERRED_COMPILATION_TV (Enabling DEFERRED_COMPILATION_TV.).
2023-07-10 16:40:45 SqlLog (< 1 ms) - Pin DbSession to physical connection
2023-07-10 16:40:45 SqlLog (3 ms) -
set lock_timeout 10000
declare @ErrorMessage nvarchar(1000) = '50000' + CHAR(9) + '2' + CHAR(9)
declare @cmd nvarchar(max)
declare @DBName nvarchar(128)
select @DBName = DB_NAME()


if exists ( select 1
from sys.database_scoped_configurations c
where c.name = 'DEFERRED_COMPILATION_TV'
and c.value = 0
)
begin
select @cmd = '
ALTER DATABASE SCOPED CONFIGURATION SET DEFERRED_COMPILATION_TV = ON;'
exec sp_executesql @cmd
--print 'DEFERRED_COMPILATION_TV switched'
end
--else
-- begin
-- print 'DEFERRED_COMPILATION_TV was OK'
-- end

set lock_timeout -1


2023-07-10 16:40:45 SqlLog (3 ms) - Pinned physical connection
2023-07-10 16:40:45 Quantum.Migrator.Migrator 1 - Sql command succeeded.
2023-07-10 16:40:45 Quantum.Migrator.Migrator Running step QBM DatabaseSettings_INTERLEAVED_EXECUTION_TVF (Enabling INTERLEAVED_EXECUTION_TVF.).
2023-07-10 16:40:45 SqlLog (< 1 ms) - Pin DbSession to physical connection
2023-07-10 16:40:45 SqlLog (3 ms) -
set lock_timeout 10000
declare @ErrorMessage nvarchar(1000) = '50000' + CHAR(9) + '2' + CHAR(9)
declare @cmd nvarchar(max)
declare @DBName nvarchar(128)
select @DBName = DB_NAME()


if exists ( select 1
from sys.database_scoped_configurations c
where c.name = 'INTERLEAVED_EXECUTION_TVF'
and c.value = 0
)
begin
select @cmd = '
ALTER DATABASE SCOPED CONFIGURATION SET INTERLEAVED_EXECUTION_TVF = ON;'
exec sp_executesql @cmd
--print 'INTERLEAVED_EXECUTION_TVF switched'
end
--else
-- begin
-- print 'INTERLEAVED_EXECUTION_TVF was OK'
-- end

set lock_timeout -1


2023-07-10 16:40:45 SqlLog (3 ms) - Pinned physical connection
2023-07-10 16:40:45 Quantum.Migrator.Migrator 1 - Sql command succeeded.
2023-07-10 16:40:45 Quantum.Migrator.Migrator Running step QBM DatabaseSettings_transactionmode_normal (DatabaseSettings_transactionmode:normal).
2023-07-10 16:40:45 SqlLog (< 1 ms) - Pin DbSession to physical connection
2023-07-10 16:40:45 SqlLog (42 ms) -
set lock_timeout 10000
declare @ErrorMessage nvarchar(1000) = '50000' + CHAR(9) + '2' + CHAR(9)
declare @cmd nvarchar(max)
declare @DBName nvarchar(128) = db_name()

if 0 = (select is_read_committed_snapshot_on
from sys.databases where name = @DBName )
begin
if exists (select top 1 1
from sys.sysprocesses p
where p.dbid = db_id()
and p.spid != @@spid
and isnull(p.status, '') != 'background'

)
begin
select @ErrorMessage = concat(@ErrorMessage
, '#LDS#Cannot switch transactionmode because of other users are active. {0}.|'
)
select @ErrorMessage = concat(@ErrorMessage
, '#LDS#Stop the other processes, please.|'
)
raiserror(@ErrorMessage, 18, 2 ) with nowait
end

select @cmd = concat('
alter database "' , @dbname , '" set READ_COMMITTED_SNAPSHOT ON '
)
exec sp_executesql @cmd

-- print 'READ_COMMITTED_SNAPSHOT switched'
end
--else
-- begin
-- -- print 'READ_COMMITTED_SNAPSHOT was OK'
-- end

set lock_timeout -1

2023-07-10 16:40:45 SqlLog (42 ms) - Pinned physical connection
2023-07-10 16:40:45 Quantum.Migrator.Migrator 1 - Sql command succeeded.
2023-07-10 16:40:45 Quantum.Migrator.Migrator Running step QBM DatabaseSettings_AUTO_CREATE_STATISTICS (DatabaseSettings_AUTO_CREATE_STATISTICS).
2023-07-10 16:40:45 SqlLog (< 1 ms) - Pin DbSession to physical connection
2023-07-10 16:40:45 SqlLog (39 ms) -
set lock_timeout 10000
declare @ErrorMessage nvarchar(1000) = '50000' + CHAR(9) + '2' + CHAR(9)
declare @cmd nvarchar(max)
declare @DBName nvarchar(128)
select @DBName = DB_NAME()


if 0 = (select is_auto_create_stats_on
from sys.databases where name = @DBName )
begin
select @cmd = '
alter database "' + DB_NAME() + '" set AUTO_CREATE_STATISTICS ON'
exec sp_executesql @cmd
-- print 'AUTO_CREATE_STATISTICS switched'
end
--else
-- begin
-- -- print 'AUTO_CREATE_STATISTICS was OK'
-- end
set lock_timeout -1


2023-07-10 16:40:45 SqlLog (39 ms) - Pinned physical connection
2023-07-10 16:40:45 Quantum.Migrator.Migrator 1 - Sql command succeeded.
2023-07-10 16:40:45 Quantum.Migrator.Migrator Running step QBM DatabaseSettings_AUTO_UPDATE_STATISTICS (DatabaseSettings_AUTO_UPDATE_STATISTICS).
2023-07-10 16:40:45 SqlLog (< 1 ms) - Pin DbSession to physical connection
2023-07-10 16:40:45 SqlLog (38 ms) -
set lock_timeout 10000
declare @ErrorMessage nvarchar(1000) = '50000' + CHAR(9) + '2' + CHAR(9)
declare @cmd nvarchar(max)
declare @DBName nvarchar(128)
select @DBName = DB_NAME()


if 0 = (select is_auto_update_stats_on
from sys.databases where name = @DBName )
begin
select @cmd = '
alter database "' + @DBName + '" set AUTO_UPDATE_STATISTICS ON'
exec sp_executesql @cmd
-- print 'AUTO_UPDATE_STATISTICS switched'
end
--else
-- begin
-- -- print 'AUTO_UPDATE_STATISTICS was OK'
-- end

set lock_timeout -1


2023-07-10 16:40:45 SqlLog (38 ms) - Pinned physical connection
2023-07-10 16:40:45 Quantum.Migrator.Migrator 1 - Sql command succeeded.
2023-07-10 16:40:45 Quantum.Migrator.Migrator Running step QBM DatabaseSettings_AUTO_UPDATE_STATISTICS_ASYNC (DatabaseSettings_AUTO_UPDATE_STATISTICS_ASYNC).
2023-07-10 16:40:45 SqlLog (< 1 ms) - Pin DbSession to physical connection
2023-07-10 16:40:45 SqlLog (38 ms) -
set lock_timeout 10000
declare @ErrorMessage nvarchar(1000) = '50000' + CHAR(9) + '2' + CHAR(9)
declare @cmd nvarchar(max)
declare @DBName nvarchar(128)
select @DBName = DB_NAME()


if 1 = (select is_auto_update_stats_async_on
from sys.databases where name = @DBName )
begin
select @cmd = '
alter database "' + @DBName + '" set AUTO_UPDATE_STATISTICS_ASYNC OFF'
exec sp_executesql @cmd
-- print 'AUTO_UPDATE_STATISTICS_ASYNC switched'
end
--else
-- begin
-- -- print 'AUTO_UPDATE_STATISTICS_ASYNC was OK'
-- end

set lock_timeout -1


2023-07-10 16:40:45 SqlLog (38 ms) - Pinned physical connection
2023-07-10 16:40:45 Quantum.Migrator.Migrator 1 - Sql command succeeded.
2023-07-10 16:40:45 Quantum.Migrator.Migrator Running step QBM DatabaseSettings_PARAMETERIZATION_FORCED (DatabaseSettings_PARAMETERIZATION_FORCED).
2023-07-10 16:40:45 SqlLog (< 1 ms) - Pin DbSession to physical connection
2023-07-10 16:40:45 SqlLog (38 ms) -
set lock_timeout 10000
declare @ErrorMessage nvarchar(1000) = '50000' + CHAR(9) + '2' + CHAR(9)
declare @cmd nvarchar(max)
declare @DBName nvarchar(128)
select @DBName = DB_NAME()


if 0 = (select is_parameterization_forced
from sys.databases where name = @DBName )
begin
select @cmd = '
alter database "' + @DBName + '" SET PARAMETERIZATION FORCED'
exec sp_executesql @cmd
end

set lock_timeout -1


2023-07-10 16:40:45 SqlLog (38 ms) - Pinned physical connection
2023-07-10 16:40:45 Quantum.Migrator.Migrator 1 - Sql command succeeded.
2023-07-10 16:40:45 Quantum.Migrator.Migrator Running step QBM DatabaseSettings_Recovery (Migration should be executed in recovery mode SIMPLE.).
2023-07-10 16:40:45 SqlLog (< 1 ms) - Pin DbSession to physical connection
2023-07-10 16:40:45 SqlLog Raw data for unique database id: 'INNSKILL-08\MSSQLSERVER02|IAMDB|5|2023-06-30T18:00:52.2330000'
2023-07-10 16:40:45 SqlLog Computed hash value for unique database id: 0u/xUbWug/1kXs3xQQSiaXgFMY535FmF
2023-07-10 16:40:45 SqlLog (48 ms) -
set lock_timeout 10000
declare @ErrorMessage nvarchar(1000) = '50000' + CHAR(9) + '2' + CHAR(9)
declare @cmd nvarchar(max)
declare @DBName nvarchar(128)
select @DBName = DB_NAME()


if isnull(DATABASEPROPERTYEX(@DBName, 'Recovery'), '') != 'SIMPLE'
begin
select @ErrorMessage = concat(@ErrorMessage
, '#LDS#Migration should be executed in recovery mode SIMPLE.|'
)
raiserror(@ErrorMessage, 18, 2 ) with nowait
end
--else
-- begin
-- -- print 'recovery was OK'
-- end
set lock_timeout -1


2023-07-10 16:40:45 SqlLog (51 ms) - Pinned physical connection
2023-07-10 16:40:45 Quantum.Migrator.Migrator 1 - Sql command failed.
2023-07-10 16:40:45 Quantum.Migrator.Migrator Processing step 'QBM DatabaseSettings_Recovery (Migration should be executed in recovery mode SIMPLE.)' failed.
2023-07-10 16:40:45 Quantum.Migrator.Migrator Running step QBM DatabaseSettings_active_replication (Cannot do migration while active replication.).
2023-07-10 16:40:45 SqlLog (< 1 ms) - Pin DbSession to physical connection
2023-07-10 16:40:45 SqlLog (1 ms) -
set lock_timeout 10000
declare @ErrorMessage nvarchar(1000) = '50000' + CHAR(9) + '2' + CHAR(9)
declare @cmd nvarchar(max)
declare @DBName nvarchar(128)
select @DBName = DB_NAME()


if isnull(DATABASEPROPERTYEX(@DBName, 'IsMergePublished'), 0) != 0
or isnull(DATABASEPROPERTYEX(@DBName, 'IsPublished'), 0) != 0
begin
select @ErrorMessage = concat(@ErrorMessage
, '#LDS#Cannot do migration while active replication.|'
)
raiserror(@ErrorMessage, 18, 2 ) with nowait
end
--else
-- begin
-- -- print 'replication was OK'
-- end
set lock_timeout -1


2023-07-10 16:40:45 SqlLog (1 ms) - Pinned physical connection
2023-07-10 16:40:45 Quantum.Migrator.Migrator 1 - Sql command succeeded.
2023-07-10 16:40:45 Quantum.Migrator.Migrator Running step QBM DatabaseSettings_inMemoryOLTP (The SQL Server is not enabled for In-Memory-OLTP.).
2023-07-10 16:40:45 SqlLog (< 1 ms) - Pin DbSession to physical connection
2023-07-10 16:40:45 SqlLog (2 ms) -
set lock_timeout 10000
declare @ErrorMessage nvarchar(1000) = '50000' + CHAR(9) + '2' + CHAR(9)

if 1 != (select ISNULL(SERVERPROPERTY('IsXTPSupported'), 0))
begin
select @ErrorMessage = concat(@ErrorMessage
, '#LDS#The SQL Server is not enabled for In-Memory-OLTP.|'
)
raiserror(@ErrorMessage, 18, 2 ) with nowait
end
set lock_timeout -1


2023-07-10 16:40:45 SqlLog (2 ms) - Pinned physical connection
2023-07-10 16:40:45 Quantum.Migrator.Migrator 1 - Sql command succeeded.
2023-07-10 16:40:45 Quantum.Migrator.Migrator Running step QBM DatabaseSettings_FGinMemoryOLTP (There is no filegroup for In-Memory-OLTP defined.).
2023-07-10 16:40:45 SqlLog (< 1 ms) - Pin DbSession to physical connection
2023-07-10 16:40:45 SqlLog (8 ms) -
set lock_timeout 10000
declare @ErrorMessage nvarchar(1000)= '50000'+char(9)+'2'+char(9)

if not exists(
select top 1 1
from sys.filegroups g
where g.type = 'FX' /* MEMORY_OPTIMIZED_DATA_FILEGROUP*/
)
begin
select @ErrorMessage = concat(@ErrorMessage
, '#LDS#There is no filegroup for In-Memory-OLTP defined.|'
)
raiserror(@ErrorMessage, 18, 2) with nowait
end

set lock_timeout-1

2023-07-10 16:40:45 SqlLog (8 ms) - Pinned physical connection
2023-07-10 16:40:45 Quantum.Migrator.Migrator 1 - Sql command succeeded.
2023-07-10 16:40:45 Quantum.Migrator.Migrator Running step QBM DatabaseSettings_FileinMemoryOLTP (DatabaseSettings_FileinMemoryOLTP).
2023-07-10 16:40:45 SqlLog (< 1 ms) - Pin DbSession to physical connection
2023-07-10 16:40:45 SqlLog Raw data for unique database id: 'INNSKILL-08\MSSQLSERVER02|IAMDB|5|2023-06-30T18:00:52.2330000'
2023-07-10 16:40:45 SqlLog Computed hash value for unique database id: 0u/xUbWug/1kXs3xQQSiaXgFMY535FmF
2023-07-10 16:40:45 SqlLog (30 ms) -
set lock_timeout 10000
declare @ErrorMessage nvarchar(1000)= '50000'+char(9)+'2'+char(9)

if not exists(
select top 1 1
from sys.filegroups g join sys.data_spaces s on g.data_space_id = s.data_space_id
join sys.database_files f on s.data_space_id = f.data_space_id
where g.type = 'FX'
)
begin
select @ErrorMessage = concat(@ErrorMessage
, '#LDS#There is no file in filegroup for In-Memory-OLTP defined.|'
)
raiserror(@ErrorMessage, 18, 2) with nowait
end

set lock_timeout-1

2023-07-10 16:40:45 SqlLog (30 ms) - Pinned physical connection
2023-07-10 16:40:45 Quantum.Migrator.Migrator 1 - Sql command failed.
2023-07-10 16:40:45 Quantum.Migrator.Migrator Processing step 'QBM DatabaseSettings_FileinMemoryOLTP (DatabaseSettings_FileinMemoryOLTP)' failed.
2023-07-10 16:40:45 Quantum.Migrator.Migrator Running step QBM DatabaseSettings_Modules_newer_than (Cannot do migration for Modules newer than 2022.0009.0001.9999.).
2023-07-10 16:40:45 SqlLog (< 1 ms) - Pin DbSession to physical connection
2023-07-10 16:40:46 SqlLog (23 ms) -
set lock_timeout 10000
declare @ErrorMessage nvarchar(1000) = '50000' + CHAR(9) + '2' + CHAR(9)

if exists(select top 1 1
from sys.tables
where name = 'QBMModuleDef'
)
begin
declare @cmd nvarchar(max) = '
declare @ErrorMessage nvarchar(1000) = ''50000'' + CHAR(9) + ''2'' + CHAR(9)
if exists (select top 1 d.MigrationVersion
from QBMModuleDef d
where d.ModuleName <> ''CCC''
and d.MigrationVersion > ''2022.0009.0001.9999''
)
begin
select @ErrorMessage = @ErrorMessage + ''#LDS#Cannot do migration for Modules newer than {0}.|2022.0009.0001.9999|''
raiserror(@ErrorMessage, 18, 2 ) with nowait
end'
exec sp_executesql @cmd
end
set lock_timeout -1


2023-07-10 16:40:46 SqlLog (23 ms) - Pinned physical connection
2023-07-10 16:40:46 Quantum.Migrator.Migrator 1 - Sql command succeeded.
2023-07-10 16:40:46 Quantum.Migrator.Migrator Running step QBM DatabaseSettings_DataOrigin (DialogDatabase.DataOrigin has a wrong value. Please compile your database first.).
2023-07-10 16:40:46 SqlLog (< 1 ms) - Pin DbSession to physical connection
2023-07-10 16:40:46 SqlLog (30 ms) -
set lock_timeout 10000
declare @ErrorMessage nvarchar(1000) = '50000' + CHAR(9) + '2' + CHAR(9)

if exists(select top 1 1
from sys.tables
where name = 'DialogDatabase'
)
and exists ( select top 1 1
from sys.objects
where name = 'QBM_FGIDBDataOrigin'
)
begin
if (select top 1 DataOrigin
from DialogDatabase d with (readpast)
where d.IsMainDatabase = 1
)
!= dbo.QBM_FGIDBDataOrigin()
begin
select @ErrorMessage = concat(@ErrorMessage
, '#LDS#DialogDatabase.DataOrigin has a wrong value. Please compile your database first.|'
)
raiserror(@ErrorMessage, 18, 2 ) with nowait
end
end
set lock_timeout -1


2023-07-10 16:40:46 SqlLog (30 ms) - Pinned physical connection
2023-07-10 16:40:46 Quantum.Migrator.Migrator 1 - Sql command succeeded.
2023-07-10 16:40:46 Quantum.Migrator.Migrator Running step QBM DatabaseSettings_UpdatePhase (DialogDatabase.UpdatePhase is missing, will be added.).
2023-07-10 16:40:46 SqlLog (< 1 ms) - Pin DbSession to physical connection
2023-07-10 16:40:46 SqlLog (103 ms) -
set lock_timeout 10000
declare @SQLCmd nvarchar(max)

if exists(select top 1 1
from sys.tables
where name = 'DialogDatabase'
)
begin
if not exists(select top 1 1
from sys.tables t with (readpast) join sys.columns c with (readpast) on t.object_id = c.object_id
where t.name = 'DialogDatabase'
and c.name = 'UpdatePhase'
)
begin
Select @SQLCmd = 'alter table DialogDatabase add UpdatePhase int default 0'
exec sp_executesql @SQLCmd
Select @SQLCmd = 'update DialogDatabase set UpdatePhase = 0 where UpdatePhase is null'
exec sp_executesql @SQLCmd
end

if not exists(select top 1 1
from sys.tables t with (readpast) join sys.columns c with (readpast) on t.object_id = c.object_id
where t.name = 'DialogDatabase'
and c.name = 'UID_DialogCountryDefault'
)
begin
Select @SQLCmd = 'alter table DialogDatabase add UID_DialogCountryDefault varchar(38)'
exec sp_executesql @SQLCmd
end
end

set lock_timeout -1


2023-07-10 16:40:46 SqlLog (103 ms) - Pinned physical connection
2023-07-10 16:40:46 Quantum.Migrator.Migrator 1 - Sql command succeeded.
2023-07-10 16:40:46 Quantum.Migrator.Migrator Running step QBM DatabaseSettings_DialogDBQueue_Generation (DialogDBQueue.Generation is missing, will be added.).
2023-07-10 16:40:46 SqlLog (< 1 ms) - Pin DbSession to physical connection
2023-07-10 16:40:46 SqlLog (128 ms) -
set lock_timeout 10000
declare @SQLCmd nvarchar(max)

if exists(select top 1 1
from sys.tables
where name = 'DialogDBQueue'
)
begin
if not exists(select top 1 1
from sys.tables t with (readpast) join sys.columns c with (readpast) on t.object_id = c.object_id
where t.name = 'DialogDBQueue'
and c.name = 'Generation'
)
begin
Select @SQLCmd = 'alter table DialogDBQueue add Generation int default 0'
exec sp_executesql @SQLCmd
Select @SQLCmd = 'update DialogDBQueue set Generation = 0 where Generation is null'
exec sp_executesql @SQLCmd
end
end

if exists(select top 1 1
from sys.tables
where name = 'QBMDBQueueCurrent'
)
begin
if not exists(select top 1 1
from sys.tables t with (readpast) join sys.columns c with (readpast) on t.object_id = c.object_id
where t.name = 'QBMDBQueueCurrent'
and c.name = 'Generation'
)
begin
Select @SQLCmd = 'alter table QBMDBQueueCurrent add Generation int default 0'
exec sp_executesql @SQLCmd
Select @SQLCmd = 'update QBMDBQueueCurrent set Generation = 0 where Generation is null'
exec sp_executesql @SQLCmd
end
end

set lock_timeout -1


2023-07-10 16:40:46 SqlLog (128 ms) - Pinned physical connection
2023-07-10 16:40:46 Quantum.Migrator.Migrator 1 - Sql command succeeded.
2023-07-10 16:40:51 SqlLog (< 1 ms) - Pin DbSession to physical connection
2023-07-10 16:40:51 SqlLog (50 ms) -
declare @cmd nvarchar(max)
declare @DBName nvarchar(128)
declare @FGName nvarchar(256)
declare @DBFile VARCHAR(300)
declare @DBPath VARCHAR(300)
declare @ErrorMessage nvarchar(1000)= '50000'+char(9)+'2'+char(9)

select @DBName = DB_NAME()

select top 1 @DBFile = physical_name
from sys.database_files f
where f.type_desc = 'ROWS'

if isnull(@DBFile, '') = ''
begin
raiserror('#LDS#No database file found.|', 18, 2 ) with nowait
end

-- extract the path
if CHARINDEX('/', @DBFile) > 0
begin
select @DBPath = left(@DBFile, 1 +len(@DBFile) - charindex('/', reverse(@DBFile)) )
end
else
begin
select @DBPath= left(@DBFile, 1 +len(@DBFile) - charindex('\', reverse(@DBFile)) )
end

-- load the file group
select top 1 @FGName = name
from sys.filegroups g
where g.type = 'FX'

if isnull(@FGName, '') = ''
begin
raiserror('#LDS#No filegroup is defined. Create the filegroup first.|', 18, 2 ) with nowait
end

-- formate the sql query
select @cmd = concat('alter database "'
, @DBName
, '" ADD FILE( name='''
, @DBName
, '_mem'' , filename='''
, @DBPath
, @FGname
, ''') TO FILEGROUP '
, @FGName)

-- execute the command
begin try
exec sp_executesql @cmd
end try
begin catch
select @ErrorMessage = @ErrorMessage + ERROR_MESSAGE()
raiserror(@ErrorMessage, 18, 1 ) with nowait
end catch


2023-07-10 16:40:51 SqlLog (51 ms) - Pinned physical connection
2023-07-10 16:40:51 Quantum.Migrator.Migrator 1 - Sql command failed.