Check Internet Connectivity from sql query/script…?

旧城冷巷雨未停 提交于 2019-12-12 05:46:40

问题


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

Any suggestion regarding this is highly appreciated.

Thanks in Advance


回答1:


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;
    }
}



回答2:


Write a SQL Assembly which contains WebClient/TcpClient code to check internet, then install the aseembly and call its methods in SQL




回答3:


You can try to ping some hosts using T-SQL procedure.



来源:https://stackoverflow.com/questions/10900030/check-internet-connectivity-from-sql-query-script

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!