2
votes

I have created a database project in visual studio, but when I publish I get the error:

Invalid usage of the option flush_interval_seconds in the ALTER DATABASE statement

And the code that is generated is:

Msg 153, Level 15, State 5, Line 5
Invalid usage of the option flush_interval_seconds in the ALTER DATABASE statement.
(43,0): SQL72045: Script execution error. The executed script:

IF EXISTS (SELECT 1
           FROM   [master].[dbo].[sysdatabases]
           WHERE  [name] = N'$(DatabaseName)')
    BEGIN
        ALTER DATABASE [$(DatabaseName)]
            SET QUERY_STORE (DATA_FLUSH_INTERVAL_SECONDS = 0, INTERVAL_LENGTH_MINUTES = 0) 
            WITH ROLLBACK IMMEDIATE;
    END

SQL72014: .Net SqlClient Data Provider:
Msg 153, Level 16, State 6, Line 5
Invalid usage of the option interval_length_minutes in the ALTER DATABASE statement.

(43,0): SQL72045: Script execution error. The executed script:

IF EXISTS (SELECT 1
           FROM   [master].[dbo].[sysdatabases]
           WHERE  [name] = N'$(DatabaseName)')
    BEGIN
        ALTER DATABASE [$(DatabaseName)]
            SET QUERY_STORE (DATA_FLUSH_INTERVAL_SECONDS = 0, INTERVAL_LENGTH_MINUTES = 0) 
            WITH ROLLBACK IMMEDIATE;
    END

An error occurred while the batch was being executed.

I am struggling to find any reference on this, and what causes it, and ultimately how to fix it, so any guidance is appreciated.

Edit: the above SQL is auto generated when the DB is published from Visual Studio

2
That SQL, have you written that or is that generated by Visual Studio? - sticky bit
Sorry, I should have said, that is auto generated SQL when the DB is published from Visual Studio. - Keith

2 Answers

0
votes

You could set it up using Visual Studio.

Solution Explorer-> Database Project -> Right Click -> Properties -> Project Settings -> Database Settings -> Query Store

Change 0 to desired value.


Related: SSDT: SQL Project Options and Database Project Settings

If this does not work, it means that you have custom SQL Script in Pre/Post Deployment folder.

2
votes

A zero value for DATA_FLUSH_INTERVAL_SECONDS doesn't make sense as the value is for the asynchronous flush. I think 60 seconds is the minimum. Also, 1 minute is the minimum for INTERVAL_LENGTH_MINUTES, the size of the fixed-length statistics time window.