简体   繁体   English

无法从SSIS(SQL Server)连接到网页

[英]Unable to connect to a Web page from SSIS (SQL Server)

Alright! 好的! After a lot of research on web, I couldn't find any of the solution working for me. 经过大量的网络研究,我找不到适合我的任何解决方案。 I am trying to connect to a Web page from SSIS and I've tried both http connection manager and a Script Task but none of them seems to be working. 我正在尝试从SSIS连接到网页,并且尝试了http连接管理器和脚本任务,但是它们似乎都无法正常工作。

I get the following errors: 我收到以下错误:

Through Script Component: Exception has been thrown by the target of an invocation. 通过脚本组件: 调用的目标引发了异常。

Through http connection manager: The remote server returned an error: (503) Server Unavailable. 通过http连接管理器: 远程服务器返回错误:(503)服务器不可用。

Here is one of the VB code I've tried: 这是我尝试过的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

And, here is one of the C# codes I've tried: 而且,这是我尝试过的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;
    }

I could open the same web page mentioned in the code manually in all my browsers (IE, Firefox, Chrome). 我可以在所有浏览器(IE,Firefox,Chrome)中手动打开代码中提到的同一网页。

FYI, I am using SQL Server 2014. Please let me know if you need any other information that I can give you to help me. 仅供参考,我正在使用SQL Server2014。如果您需要任何其他可以帮助我的信息,请告诉我。

I cannot reproduce your issue both via Http connection manager and Script Task. 我无法同时通过Http连接管理器和脚本任务重现您的问题。

In Http Connection Manager, I simply pasted the uri you provided ( http://www.fhfa.gov/DataTools/Downloads/Pages/Conforming-Loan-Limits.aspx ) and test connection succeeded. 在Http Connection Manager中,我只是粘贴了您提供的uri( http://www.fhfa.gov/DataTools/Downloads/Pages/Conforming-Loan-Limits.aspx ),然后测试连接成功。

In Script Task, I just use the simplest code: 在脚本任务中,我只使用最简单的代码:

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

And the script task also successfully download the file. 并且脚本任务也成功下载了文件。

I tested both on SSDT-BI 2014 and SSDT 2016. And I've also tried to deploy and run the package with Script Task on SQL Server 2014, the result was also successful. 我在SSDT-BI 2014和SSDT 2016上都进行了测试。我还尝试在SQL Server 2014上使用脚本任务部署和运行该程序包,结果也很成功。

So I want to know if the issue happened on your SSIS designer or SQL Server. 因此,我想知道问题是否在您的SSIS设计器或SQL Server上发生。 If it just happened on your SQL Server, maybe you should check the network setting of your SQL Server. 如果只是在您的SQL Server上发生过,也许您应该检查SQL Server的网络设置。 If your SQL Server is OK, I think you can change a machine to verify if the issue happens again. 如果您的SQL Server正常,我认为您可以更改计算机以验证问题是否再次发生。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM