TSQL Check Database Instance Online

What is the best way to check if an instance of Microsoft SQL Server is working? I have a view that spans two instances of Microsoft SQL Server, but before requesting it in a stored procedure, I would like to verify that the second server instance supports the fallback ability to simply query local data.

The second instance is a linked server.

I am currently considering a SQL CLR function that might try to open a connection with a shorter wait time, but I am wondering if it can do something that can be done directly in Transact SQL.

+3
source share
2 answers

, , , ?

select 
    name
from sys.databases
where name = 'DatabaseName'
    and state = 0 --Database is online

sys.databases : sys.databases

EDIT: SQL-

+4

sys.sysdatabases ( ),

1 = autoclose (ALTER DATABASE)

4 = /bulkcopy (ALTER DATABASE SET RECOVERY)

8 = trunc. chkpt (ALTER DATABASE SET RECOVERY)

16 = (ALTER DATABASE)

32 =

64 =

128 =

256 =

512 = (ALTER DATABASE)

1024 = (ALTER DATABASE)

2048 = dbo (ALTER DATABASE SET RESTRICTED_USER)

4096 = (ALTER DATABASE)

32768 =

4194304 = autoshrink (ALTER DATABASE)

1073741824 =

0

Source: https://habr.com/ru/post/1750327/


All Articles