I'm working on an typical web application using cloud services to learn how to use windows azure. In my deployment, I have two roles, a web role running an ASP.NET MVC application, and a worker role that provides some backend services.
The database is hosted on SQL Azure (in the same subscription and datacenter) and is managed using Entity Framework Code First. The connection string is the one Azure provided.
The strange thing is that on the Web Role, Entity Framework is successful in connecting and executing queries against the SQL Azure Database. But when the same code is run in the Worker Role, it crashes with the following exception:
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)
I verified that the connecting strings used are the same, but have been unsuccessful in determining why the Worker Role won't connect.
EDIT: Executed the role using the Compute Emulator and the SQL Azure connection string (with the correct firewall exception already configured) and the code didn't crash. So apparently it is only happening when the code is run in the Cloud.
EDIT 2: The SQL Azure firewall is correctly configured to allow connections from the Azure Datacenter, as evidenced by the Web Role's successful connection.