Wednesday
23Dec2009

Connect from Azure to an SQL Server Named Instance

In some situations you can’t or don’t want to move all your data completely to the cloud. Be it to connect to your existing infrastructure, a company policy, to remain multi-tenant or simply when migrating slowly step by step. Common to these cases is often the requirement to synchronize with or connect from Azure to some local or offsite SQL Server database. For synchronization you may want to try the Microsoft Sync Framework. This post is about the other option: connecting to an external named SQL Server instance.

Connecting to Named SQL Server Instances

In addition to its own storage options like SQL Azure and Azure Table Storage, Azure also allows you to connect to external SQL Servers over TCP/IP. However, there’s a pitfall right now when using named SQL Server instances:

System.Data.SqlClient.SqlException: 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: SQL Network Interfaces, error: 26 - Error Locating Server/Instance Specified) at System.Data.SqlClient.SqlInternalConnection.OnError(SqlException exception, Boolean breakConnection) at … (source)

Provided your connection string is correct, this is likely to be an issue with how SQL server finds your named instance.

Instance Resolution using SQL Server Browser

Since SQL Server 2005, the SQL Server Browser service is responsible for enumerating available instances on a machine, and to resolve instance names to the actual named pipe or TCP port (for SQL Server 2000 it was the SQL Server Resolution Protocol).

In order to resolve the TCP port of a named instance, the client sends an UDP datagram to port 1434, to which the server browser replies with another datagram listing the instance endpoint to which the client then connects to. Thanks to this mechanism it is no longer required to have the server listen on the standard SQL server TCP port 1433, so it can fully support multiple (named) instances. In fact, the default for named instances is to use a dynamic random TCP port.

Azure vs. SQL Server Browser

When connecting from Azure this resolution mechanism fails, simply because the UDP datagrams never reach their target (this may change in the future). So there’s no way the client can find the actual probably random TCP port to connect to, and will throw the SqlException cited above.

Solution

To work around this issue, you can configure your named instance to listen on a static TCP port instead of randomly selecting a new dynamic one on every restart (related kb). You can then specify this static port directly in the connection string in your Azure worker role:

Data Source={domain/ip},{port};Network Library=DBMSSOCN;
Initial Catalog={dbname};User ID={user};Password={pw}

Note that in this case there’s no need to specify the name of the instance in the connection string. The network library parameter tells the client to use TCP/IP instead of e.g. Named Pipes.

Tuesday
15Dec2009

Azure: Cloud Service Models

Since I joined Lokad this September I finally had the chance to dive into cloud computing. We chose Windows Azure as platform for our very computation intensive business, and built a neutral opensource framework on top of it: Lokad.Cloud.

Cloud Services

Lokad.Cloud is described as a .net object-to-cloud persistence mapper, but it’s actually much more. This post shall concentrate on one aspect only: Its notion of Cloud Services as horizontally scalable workers.

In essence, cloud services are managed and executed as follows:

  1. The Lokad.Cloud management infrastructure (for now essentially a web role) allows you to upload one or more assemblies containing a set of cloud services and optionally some configuration file.
  2. Every Azure worker role instance loads all these services in an isolated AppDomain.
  3. Each Azure worker then executes these services one at a time according to some scheduling algorithm and execution policy.

We provide specialized base classes to simplify implementing services processing items from a shared queue or for services which are to be called in regular intervals.

We treat all azure workers as equal and therefore execute every cloud service on each Azure worker from time to time. In other words, we map all cloud services to all Azure workers, forming a complete bipartite graph between cloud services and Azure workers as shown in the following figure.

This is a fundamental concept that yields a very simple design with a potential for ideal horizontal scaling, and is even resilient to failing azure workers as long as at least one worker remains intact.

Cloud Service Models and Deployments

The only object that is aware of this mapping is the service scheduler. Yet, from the management and diagnostics perspective it would be interesting to represent the cloud services as first class objects. I’m therefore introducing the notion of Cloud Service Models for Lokad.Cloud (not part of the current release, open whether it ever will be).

In Azure, web and worker roles are explicitly defined and configured in two xml files. Since the latest update of the Azure tools for Microsoft VisualStudio, they are referred to as Azure Service Model. Using the Azure management website one can upload an assembly plus the two xml files to create a unique Azure deployment. A deployment can be stopped or running, either in production or in staging mode.

The same concepts can also be applied to Cloud Services, on a slightly higher level of abstraction and orthogonal to the Azure terms.

A Cloud Service Model is a unique entity, associated with a set of assemblies, the cloud services defined in them and their configuration (if applicable). Using the Lokad.Cloud management tools an administrator can upload such a model and create a unique Cloud Service Deployment. A deployment can be stopped or running, and of course be removed when no longer needed. A failing or malfunctioning deployment can be diagnosed and dealt with directly in the management UI.

Note that the currently implemented option to upload a zip file containing assemblies and optional configuration is already very close to such a models, but is missing identity and other metadata.

In each Azure worker, our scheduler will load the current service model, load the services and schedule them accordingly. From time to time the scheduler will check whether the deployed service model has changed, and update if necessary.

Technically this design would also allow to run multiple different deployments in parallel, e.g. by breaking the complete bipartite graph between Cloud Services and Azure workers into a non-complete bipartite one where Azure workers are assigned to a single Cloud Service Deployment:

Or by sharing the Azure workers by Cloud Service Deployments in a way or another (e.g. in parallel, or round robin):

Remember however that some of these scenarios violate the fundamental concept mentioned above. Hence, as usual, there’s a tradeoff between flexibility and robustness.

Monday
03Aug2009

dnAnalytics + Iridium = Math.NET Numerics

You may have wondered why the Math.NET Iridium development has stopped abruptly almost two months ago. Luckily this is not entirely true, in the last few weeks the .Net numerics library has progressed well - but at a different place:

Math.NET Iridium is being merged with dnAnalytics, resulting in a new project named "Math.NET Numerics".

What does that mean for existing Math.NET Iridium users?

  • Higher development momentum and larger user community (as a direct result of merging two projects).
  • Better algorithm and code quality by picking the best of each project and simply by having new highly skilled developers on board.
  • New opensource license model: MIT/X11. This is a very open license similar to the so called New BSD License. This model is much less restricting than the previous LGPL and is (to my knowledge) source-compatible to a wide range of licenses including all GPL-based licenses and the Microsoft opensource licenses, too.
  • Some API changes. This is unavoidable since we try to integrate the best of both dnAnalytics and Iridium. At the same time this is a good chance to throw out some old designs that have shown to be improvable and replace them with better approaches. However, we try hard to keep migration as smooth as possible.
  • In addition to the completely self-contained managed implementation, we'll profit from the dnAnalytics experience with parallelized and native optimizations (MKL, ACMS, CUDA etc) and will therefore provide optional wrappers around native libraries which provide significantly better performance when working with large data sets.
  • Again thanks to the dnAnalytics experience, you can expect better F# support, even though the library is still written in C#.
  • Although Iridium did support sparse linear algebra for a very short time, we had to remove it due to several issue. You can expect Math.NET Numerics to finally support sparse linear algebra in a clean way.

You'll find the new Math.NET Numerics discussion board and tracker at CodePlex and the current sources at Github (subversion mirror at google). The full portal website and wikis etc. will be available in a few weeks. Feel free to post your ideas, feedback or even fork the repository at github to contribute code to the project (note that we will completely reorganize the project structure until mid August).

We'll let you know here and on Twitter as soon as we reach a first milestone and have an api preview ready.

Friday
17Apr2009

Online API Reference

We now finally provide an online api reference in an rdoc-like style, generated by docu (actually by my github fork of it). Note that docu is new and still under heavy development, so the quality is likely to improve over the next months (e.g. right now the class summaries are missing).

http://numerics.mathdotnet.com/api/

It is simple, but (other than the older NDoc & Sandcastle generated sites) loads very fast.

Thursday
08Jan2009

Source Repository Mirror at Google Code

In addition to the official subversion repository we now also maintain a read-only repository mirror on google code, mainly as a fail-over backup solution if something happens to the primary server, but also because it provides additional ways to access the source: Subversion over the HTTP protocol (useful if you’re behind a restrictive firewall), and source code browsing directly in the web browser.

Official Subversion Repository:
svn://svn.opensourcedotnet.info/mathnet/trunk 

New Subversion Repository Mirror:
http://mathnet-mirror.googlecode.com/svn/trunk/

Of course the official/primary repository remains accessible anonymously as well.