/// <summary> /// Create Firewall Rule on SQL Azure server to allow access from the specified range of addresses /// </summary> /// <param name="server"></param> /// <param name="ruleName"></param> /// <param name="startAddresss"></param> /// <param name="endAddress"></param> public void CreateFirewallRule(string server, string ruleName, String startAddress, String endAddress) { // Query SQL Azure for server info AzureManagementClient client = new AzureManagementClient(this.certificate, this.subscriptionId); string request = "<?xml version=\"1.0\" encoding=\"utf-8\"?>" + "<FirewallRule " + "xmlns=\"http://schemas.microsoft.com/sqlazure/2010/12/\" " + "xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" " + "xsi:schemaLocation=\"http://schemas.microsoft.com/sqlazure/2010/12/ FirewallRule.xsd\">" + "<StartIpAddress>" + startAddress + "</StartIpAddress>" + "<EndIpAddress>" + endAddress + "</EndIpAddress>" + "</FirewallRule>"; AzureManagementResponse response = client.SubmitSQLAzureRequestWithBody( RequestType.PUT, request, "1.0", "servers/{0}/firewallrules/{1}", server, ruleName); }
/// <summary> /// Creates a SQL Azure server /// </summary> public string CreateAzureSQLServer(AzureSQLServer config) { string serverName = null; // Create a SQL Azure create server request from this template string azureRequest = "<?xml version=\"1.0\" encoding=\"utf-8\"?>\r\n" + "<Server xmlns=\"http://schemas.microsoft.com/sqlazure/2010/12/\">\r\n" + "<AdministratorLogin>{0}</AdministratorLogin>\r\n" + "<AdministratorLoginPassword>{1}</AdministratorLoginPassword>\r\n" + "<Location>{2}</Location>\r\n" + "</Server>"; // Fill in the request template azureRequest = string.Format( azureRequest, config.AdministratorLogin, config.AdministratorLoginPassword, config.Location ); // Submit the request AzureManagementClient client = new AzureManagementClient(this.certificate, this.subscriptionId); AzureManagementResponse response = client.SubmitSQLAzureRequestWithBody( RequestType.POST, azureRequest, "1.0", "servers" ); XmlNode xml = response.GetSQLXmlNode("ServerName"); serverName = xml.InnerText; return serverName; }