[英]Unable to connect to a Web page from SSIS (SQL Server)
好的! 经过大量的网络研究,我找不到适合我的任何解决方案。 我正在尝试从SSIS连接到网页,并且尝试了http连接管理器和脚本任务,但是它们似乎都无法正常工作。
我收到以下错误:
通过脚本组件: 调用的目标引发了异常。
通过http连接管理器: 远程服务器返回错误:(503)服务器不可用。
这是我尝试过的VB代码之一:
Public Sub Main()
Dim MyWebClient As New System.Net.WebClient()
Dim proxyObject As New System.Net.WebProxy("BANANA:8080", True)
MyWebClient.Proxy = proxyObject
MyWebClient.Proxy.Credentials = CredentialCache.DefaultCredentials
Dim remoteURi As String
remoteURi = "http://www.fhfa.gov/DataTools/Downloads/Pages/Conforming-Loan-Limits.aspx"
Dim filename As String
filename = "C:\LoanLimits.html"
MyWebClient.DownloadFile(remoteURi, filename)
End Sub
而且,这是我尝试过的C#代码之一:
public void Main()
{
Variables varCollection = null;
Dts.VariableDispenser.LockForRead("User::RemoteUri");
Dts.VariableDispenser.LockForRead("User::LocalFolder");
Dts.VariableDispenser.GetVariables(ref varCollection);
varCollection.Unlock();
System.Net.WebClient myWebClient = new System.Net.WebClient();
string webResource = varCollection["User::RemoteUri"].Value.ToString();
string fileName = varCollection["User::LocalFolder"].Value.ToString() + webResource.Substring(webResource.LastIndexOf('/') + 1);
myWebClient.DownloadFile(webResource, fileName);
Dts.TaskResult = (int)ScriptResults.Success;
}
我可以在所有浏览器(IE,Firefox,Chrome)中手动打开代码中提到的同一网页。
仅供参考,我正在使用SQL Server2014。如果您需要任何其他可以帮助我的信息,请告诉我。
我无法同时通过Http连接管理器和脚本任务重现您的问题。
在Http Connection Manager中,我只是粘贴了您提供的uri( http://www.fhfa.gov/DataTools/Downloads/Pages/Conforming-Loan-Limits.aspx ),然后测试连接成功。
在脚本任务中,我只使用最简单的代码:
public void Main()
{
// TODO: Add your code here
var client = new WebClient();
client.DownloadFile(new Uri("http://www.fhfa.gov/DataTools/Downloads/Pages/Conforming-Loan-Limits.aspx"), "D:\\test.html");
Dts.TaskResult = (int)ScriptResults.Success;
}
并且脚本任务也成功下载了文件。
我在SSDT-BI 2014和SSDT 2016上都进行了测试。我还尝试在SQL Server 2014上使用脚本任务部署和运行该程序包,结果也很成功。
因此,我想知道问题是否在您的SSIS设计器或SQL Server上发生。 如果只是在您的SQL Server上发生过,也许您应该检查SQL Server的网络设置。 如果您的SQL Server正常,我认为您可以更改计算机以验证问题是否再次发生。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.