从 sql 查询/脚本检查 Internet 连接....? [英] Check Internet Connectivity from sql query/script....?

查看:30
本文介绍了从 sql 查询/脚本检查 Internet 连接....?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我们可以从 sql 脚本检查互联网的可用性吗?我用谷歌搜索了很多都没有用.

Can we check availability of internet from sql Script? I google'd a lot with no use.

对此的任何建议表示高度赞赏.

Any suggestion regarding this is highly appreciated.

提前致谢

推荐答案

您可以使用 SQL CLR 做到这一点 UDF.下面是一个例子:

You can do this with a SQL CLR UDF. Here is an example:

[Microsoft.SqlServer.Server.SqlFunction]
public static SqlBoolean HasConnectivity(SqlString url)
{
    try
    {
        if (url.IsNull)
        {
            return false;
        }
        var httpRequest = (HttpWebRequest)HttpWebRequest.Create(url.ToString());
        using(var response = (HttpWebResponse)httpRequest.GetResponse())
        {
            //Make sure the Http Repsonse was HTTP 200 OK.
            return response.StatusCode == HttpStatusCode.OK;
        }
    }
    catch
    {
        return false;
    }
}

这篇关于从 sql 查询/脚本检查 Internet 连接....?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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