Monday, May 13, 2013

Azure Network Load Balancer Time-out Errors

Another Azure enigma...

I've been working on a web application where we process mail merges and return .docx files via OpenXML. The system works great locally and remotely on Azure, if the mail merge batch is relatively small.

Here's where the problem becomes obvious; some of the batches have the potential to parse through thousands of records and returning documents with thousands of pages, this causes the document return to take several minutes.

Azure, however, employs an NLB to make sure that there aren't any idle connections that are wasting resources. Makes sense, right, otherwise how are they going to keep the pipes clear for the traffic to your site.

There is a fairly simple solution to getting around this, though some may see it as a bit of a hack. We created a custom status object, to return to an $.ajax() call. This object returns the status of the mail merge and if any errors have been encountered.

After our call to the method for the document was updated we added an <iFrame> element to the site and via jQuery update the .attr("src","{server.url.for.doc}). This allows the ability to simulate the post and download the file.

Known Issues:

  • Requires GET - and removes POST for document, making the call less secure (IMO)

Saturday, May 11, 2013

"No Such Host is Known..." - Windows Azure

Today, while working on a hobby project hosted on Windows Azure, I ran into one of those nagging problems that does not easily explain itself. My few updates to a project that had grown dusty, a web publish, presented me with the dreaded YSoD proclaiming "No Such Host Is Known."

This was a new error for me but the stack trace lead me to believe that it had to do with the database.

[Win32Exception (0x80004005): No such host is known]

[SqlException (0x80131904): A network-related or instance-specific error occurred while establishing a connection to SQL Server. The server was not found or was not accessible. Verify that the instance name is correct and that SQL Server is configured to allow remote connections. (provider: TCP Provider, error: 0 - No such host is known.)]
System.Data.SqlClient.SqlInternalConnection.OnError(SqlException exception, Boolean breakConnection, Action`1 wrapCloseInAction) +5296071
System.Data.SqlClient.TdsParser.ThrowExceptionAndWarning(TdsParserStateObject stateObj, Boolean callerHasConnectionLock, Boolean asyncClose) +558
System.Data.SqlClient.TdsParser.Connect(ServerInfo serverInfo, SqlInternalConnectionTds connHandler, Boolean ignoreSniOpenTimeout, Int64 timerExpire, Boolean encrypt, Boolean trustServerCert, Boolean integratedSecurity, Boolean withFailover) +5308555

Maybe it was Azure. Nope, everything was indeed running as it should be there. Maybe my connection string in the project. Still no, Web.config looked good. I'll try doing a EF "Update-Database" via the Package Manager Console. Sure enough this was working too.

So what was the cause of this problem?

Well it turns out my hunch about the Web.config connection string was pretty darn close. Azure provides a way to obfuscate your connection string details by overriding the connection string with details provided in the Azure site configuration settings.

Via the Azure Portal, go to your sites "Configure" tab and you can view the "Connection String" overrides.

It was their connection string override that was causing the problem.

Well, okay, it was mostly their fault.

My issue was that my connection string name in Azure did not match the one in my system. Making the connection string name equal to the one in my system, a quick save, and back in business.

My online searches did not have much to say on fixing this issue for a site hosted in Azure but hopefully this can help you with troubleshooting your issue. Good luck and happy coding.

Obligatory First Post

I use this blog to help help ensure that I don't forget some of the great content that I come across while troubleshooting or browsing the web. Hopefully you'll find these entries of value. Feel free to contribute via the comments.