public static async Task VerifyDatabaseSupported()

in src/SqlBindingUtilities.cs [204:226]


        public static async Task VerifyDatabaseSupported(SqlConnection connection, ILogger logger, CancellationToken cancellationToken)
        {
            // Need at least 130 for OPENJSON support
            const int MIN_SUPPORTED_COMPAT_LEVEL = 130;

            string verifyDatabaseSupportedQuery = $"SELECT compatibility_level FROM sys.databases WHERE Name = DB_NAME()";

            using (var verifyDatabaseSupportedCommand = new SqlCommand(verifyDatabaseSupportedQuery, connection))
            using (SqlDataReader reader = verifyDatabaseSupportedCommand.ExecuteReaderWithLogging(logger))
            {
                if (!await reader.ReadAsync(cancellationToken))
                {
                    throw new InvalidOperationException($"Received empty response when verifying whether the database is currently supported.");
                }

                int compatLevel = reader.GetByte(0);

                if (compatLevel < MIN_SUPPORTED_COMPAT_LEVEL)
                {
                    throw new InvalidOperationException($"SQL bindings require a database compatibility level of 130 or higher to function. Current compatibility level = {compatLevel}");
                }
            }
        }