SqlConnection - is remote or local connection?

后端 未结 4 1377
星月不相逢
星月不相逢 2021-01-27 20:20

How can I determine is it local connection (localhost or 127.0.0.1) or is it remote connection (other machine in local area) if I have SqlConnection object?

4条回答
  •  误落风尘
    2021-01-27 21:16

    You may check SqlConnection.ConnectionString property to see if it has something like (local) or . in its' server part, but that's not very reliable because of %systemroot%\system32\drivers\etc\hosts' and various other SQL Aliases, wherebyfoo-srv` may well be a local box.

提交回复
热议问题