Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
248 views
in Technique[技术] by (71.8m points)

health check - asp.net core api healthcheck

I'm adding a few healthchecks to my netcore website. One of them is checking whether the connection string is pointing to a database that has the support for in memory tables activated (essentially if the filegroup was created with the CONTAINS MEMORY_OPTIMIZED_DATA flag).

The healthcheck is det to use this query:

IF((SELECT COUNT(1) FROM sys.filegroups FG
JOIN sys.database_files DF
ON FG.data_space_id = DF.data_space_id
JOIN sys.master_files MF
ON DF.file_id = MF.file_id
JOIN sys.databases DB
ON DB.database_id = MF.database_id
where FG.type = 'FX'
and DB.name ='MyDB')>0)
BEGIN
SELECT 1
END
ELSE
BEGIN
RAISERROR ('Memory file group not set',  
18, -- Severity,  
-1); -- State);
END

And registered via:

.AddSqlServer(connectionString: connString,
    healthQuery: myHealthQuery, name: HealthCheckNames.InMemoryState)

The query does return 1, without any error. I've set up a profiler to run through it, and no error is thrown (and I can see the Select 1 being returned).

Still, that healthcheck returns unhealthy.

Any idea why?

question from:https://stackoverflow.com/questions/65617189/asp-net-core-api-healthcheck

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

It turns out it was a permission issue. The connection string's user was missing a permission (the VIEW ANY DEFINITION one), which I'm not willing to assign.

I solved it by skipping the join to the sys.master_files table and by using a like operator

IF((SELECT Count(1) FROM sys.filegroups FG
JOIN sys.database_files DF
ON FG.data_space_id = DF.data_space_id
where FG.type = 'FX'
and Df.name  LIKE 'MyDB%') > 0)
BEGIN
    SELECT 1
END
ELSE
BEGIN
    RAISERROR ('Memory file group not set',  
        18, -- Severity,  
        -1); -- State);
END

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...