SqlConnection的 - 是远程或本地连接? [英] SqlConnection - is remote or local connection?

查看:454
本文介绍了SqlConnection的 - 是远程或本地连接?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我如何能确定它是本地连接(本地主机或127.0.0.1)或者是远程连接(在本地区的其它机器),如果我有SqlConnection对象?

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?

推荐答案

这是我所知道的是检查直接的ConnectionString以查看它是否包含任何的话本地主机,127.0.0.1(本地主机),最简单的方法。 或本地机器名。检查开始,因为他们可以以SQL为本地命名实例中运行。

Easiest way that I am aware of is to check the connectionstring directly to see if it contains either the words localhost, 127.0.0.1, (localhost), "." or the local machine name. Check for starting with since their could be a local named instance of Sql running.

您可以使用统环境库检索当前计算机名称。您还可以看看使用ConnectionBuilder库在.net中检索数据,而无需使用完整的字符串解析。这个细节可以发现这里

You can use the System.Environment library to retrieve the current machine name. You can also look at using the ConnectionBuilder library in .Net to retrieve the data without using complete string parsing. Details on this can be found here

这篇关于SqlConnection的 - 是远程或本地连接?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆