问题
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