Is the DB always connected to the same destination?

Asked 1 years ago, Updated 1 years ago, 30 views

The SQL destination host name is

SELECT@@SERVERNAME 

It seems that you can get it in

Aren't all the servers connected the same?

sql

2022-09-30 16:52

1 Answers

It literally returns the hostname of the database you are connected to. Of course, if a DB is in a single server and you have properly specified a destination for that single server's DB, it will be the same.

However, infrastructure configurations can be used to break that assumption.
For example, a read replica can be provided to change the destination of servers connected by DNS round robin or load balancer at complete random.
In that case, which server is randomly connected to?You can get the information that

However, it does not change behavior depending on the server.It's just an environment variable, so you can think of it as a variable for debugging and logging, and it's not often used in simple applications.


2022-09-30 16:52

If you have any answers or tips


© 2024 OneMinuteCode. All rights reserved.