Recently, a Web Query created in MS Excel cannot be refreshed after it is created for a period of time (or after the file is closed, the file is opened again and the data is refreshed, an error is reported when you click Refresh:
You cannot download the required information.
This is a unfriendly error. From the prompt information, it seems that the website cannot be opened, but there is no problem in opening it in the browser (using the authentication of anonymous users ).
For more error information, I checked the System Event Log and found such a record:
Object reference not set to an instance of an object. at xxx. global. session_Start (Object sender, EventArgs e) at System. web. sessionState. sessionStateModule. raiseOnStart (EventArgs e)...
It seems that an unhandled exception was thrown during access to this webpage, so I checked the Global. asax. cs file of the website, and the access object exists in the Session_Start method.
Request. the Code of Headers ["Accept-Language"]. Because the Session will exist for a period of time, the Session_Start method is not called when it is refreshed after the query is created, so I added the code to determine whether the object is empty in this method and the problem was solved.
Conclusion: When you use Office to extract data from a website, if an exception occurs on the server side on the webpage you are visiting, this type of download failure will be reported without displaying the exception details, you need to view the event logs on the server. When creating a query in the Office, accessing the website is the same as accessing the website through a browser, so the behavior and performance are consistent. After a query is created, when the website is refreshed to obtain data, some functions are simplified compared with those of the browser, for example, Headers ["Accept-Language"] does not exist in the Request sent when refreshing website data. It is analyzed by using the network packet capture software Fiddler:
Request Header information when the browser accesses the website:
The request header information when the Office software accesses the website through Web Query:
. It seems that you need to pay attention to the Web Query construction in the future. I hope this article will be helpful and instructive to the friends who encounter the same problem. You are also welcome to give your comments and supplement.