Create Server (classic)

 

THIS TOPIC APPLIES TO: noSQL Server yesAzure SQL DatabaseyesAzure SQL Data Warehouse noParallel Data Warehouse

Create a new Azure SQL Database server.

Important

The recommended REST commands to work with SQL Database are the Resource Manager based Azure SQL Database REST API. While there is no change to SQL Database, be aware that the classic deployment model command in this article is scheduled for deprecation on December 1, 2019. For a table providing links to the specific new commands you should use, see Operations for Azure SQL Databases.

Request

The Create Server request must be specified as follows:

  • Replace {subscriptionId} with the subscription ID to create the server under.
Method Request URI HTTP Version
POST https://management.core.windows.net:8443/{subscriptionId}/services/sqlservers/servers HTTP/1.1

If the operation returns success, the operation is complete and the server is created immediately. If the operation fails because of a user error, a server is not created. If there is a communication error or internal server error, you should check the status of the operation using List Servers (classic).

URI Parameters

None.

Request Headers

The following table describes the required and optional request headers:

Request Header Description
x-ms-version Required. Specifies the version of the operation to use for this request. This header should be set to 2012-03-01.
x-ms-client-request-id Optional. Provides a client-generated, opaque value with a 1 KB character limit. Using this header is highly recommended for correlating client-side activities with requests received by the server.

Request Body

The format of the request body is as follows:

<Server xmlns="https://schemas.microsoft.com/sqlazure/2010/12/">  
  <AdministratorLogin>MyAdminAccount</AdministratorLogin>  
  <AdministratorLoginPassword>MyAdminPassword</AdministratorLoginPassword>  
  <Location>West US</Location>  
  <Version>12.0</Version>  
</Server>  

The following table describes elements of the request body:

Element Name Description
AdministratorLogin The administrator login name for the new server.
AdministratorLoginPassword The administrator login password for the new server.
Location The region to deploy the new server. Valid values are:

- South Central US
- Central US
- North Central US
- West US
- East US
- East US 2
- East Asia
- Southeast Asia
- Japan West
- Japan East
- North Europe
- West Europe
- Brazil South
- Australia East
- Australia Southeast
Version The version for the new server. Valid values are:

- 2.0 (v11 server)
- 12.0 (v12 server)

Azure SQL Database V12 has been promoted from preview status to general availability (GA) status in some geographic regions, but not all. For a status table per region, see V12 general availability (GA) status per region.

For more information about password requirements, see Password Policy

Response

The response includes an HTTP status code, a set of response headers, and a response body.

Status Code

Successful creation of the server returns a status of 'Created'.

Response Headers

The response for this operation includes the following headers. The response may also include additional standard HTTP headers. All standard headers conform to the HTTP/1.1 protocol specification.

Response Header Description
x-ms-request-id A value that uniquely identifies a request made against the database management service. This request id is used for request tracking. If a failure occurs that requires the user to contact Microsoft Support, the request id should be provided to Microsoft to assist in tracking and resolving the failure for the request.

Response Body

The following is an example response body:

<ServerName FullyQualifiedDomainName="ntvygry6ri.database.windows.net" xmlns="https://schemas.microsoft.com/sqlazure/2010/12/">ntvygry6ri</ServerName>  

The following table describes the elements of the response body:

Element Name Description
ServerName The name of the newly created server.

Example

The following console application creates a new Azure SQL Database Server.

Replace the following:

  • {subscriptionId} – replace with the subscription identifier for your subscription.

  • {adminLogin} – replace with the administrator login for your subscription.

  • {adminPassword} – replace with the administrator password for your subscription.

  • {dataCenterLocation} – replace with the location to deploy the new server.

  • {thumbprint} – replace with the thumbprint of a management certificate in your subscription.

using System;  
using System.Collections.Generic;  
using System.Linq;  
using System.Text;  
using System.Threading.Tasks;  
using System.IO;  
using System.Xml;  
using System.Security;  
using System.Security.Cryptography;  
using System.Security.Cryptography.X509Certificates;  
using System.Net;  
  
namespace CreateServer  
{  
    /// <summary>  
    /// Creates a new database server.  
    /// </summary>  
    class Program  
    {  
        static void Main(string[] args)  
        {  
            Uri requestUri = new Uri("https://management.core.windows.net:8443/"  
                                    + "{subscriptionId}"  
                                    + "/services"  
                                    + "/sqlservers/servers");  
  
            // Create the request and specify attributes.  
            HttpWebRequest request = (HttpWebRequest)HttpWebRequest.Create(requestUri);  
  
            // Add a x-ms-version header to specify the API version.  
            request.Headers.Add("x-ms-version", "2012-03-01");  
  
            // Generate a request ID that can be used to identify this request in the service logs.  
            string clientRequestId = Guid.NewGuid().ToString();  
            request.Headers.Add("x-ms-client-request-id", clientRequestId);  
            request.Method = "POST";  
            request.ContentType = "application/xml";  
  
            // Build the request body for the POST.  
            string login = "{adminLogin}";  
            string password = "{adminPassword}";  
            string location = "{dataCenterLocation}";  
            string xmlBody = String.Format(  
                "<Server xmlns=\"https://schemas.microsoft.com/sqlazure/2010/12/\">"  
                + "<AdministratorLogin>{0}</AdministratorLogin>"  
                + "<AdministratorLoginPassword>{1}</AdministratorLoginPassword>"  
                + "<Location>{2}</Location>"  
                + "<Version>12.0</Version>"  
                + "</Server>", login, password, location);  
  
            // Write the POST body into the request.  
            ASCIIEncoding encoding = new ASCIIEncoding();  
            byte[] data = encoding.GetBytes(xmlBody);  
            Stream newStream = request.GetRequestStream();  
            newStream.Write(data, 0, data.Length);  
  
            // The thumbprint value of the management certificate.  
            // Replace {thumbprint} with the thumbprint of a management certificate associated with your subscription.  
            // It must also be installed on the machine accessing the API.  
            string certThumbprint = "{thumbprint}";  
  
            // Create a reference to the My certificate store.  
            X509Store certStore = new X509Store(StoreName.My, StoreLocation.CurrentUser);  
  
            // Open the store.  
            certStore.Open(OpenFlags.ReadOnly);  
  
            // Find the certificate that matches the thumbprint.  
            X509Certificate2Collection certCollection = certStore.Certificates.Find(X509FindType.FindByThumbprint, certThumbprint, false);  
            certStore.Close();  
  
            // Verify the certificate was added to the collection.  
            if (0 == certCollection.Count)  
            {  
                throw new Exception("Error: No certificate found with thumbprint " + certThumbprint);  
            }  
  
            // Create an X509Certificate2 object using our matching certificate.  
            X509Certificate2 certificate = certCollection[0];  
  
            // Attach the certificate to the request.  
            request.ClientCertificates.Add(certificate);  
  
            try  
            {  
                using (HttpWebResponse response = (HttpWebResponse)request.GetResponse())  
                using (Stream responseStream = response.GetResponseStream())  
                using (StreamReader reader = new StreamReader(responseStream))  
                {  
                    // Display the client request ID.  
                    Console.WriteLine("clientRequestId: " + clientRequestId);  
  
                    // Display the web response status code.  
                    Console.WriteLine("Response status code: " + response.StatusCode);  
  
                    // Display the request ID returned by Windows Azure.  
                    Console.WriteLine("x-ms-request-id: "  
                        + response.Headers["x-ms-request-id"]);  
  
                    // Display the raw response.  
                    Console.WriteLine("Received response:");  
                    Console.WriteLine(reader.ReadToEnd());  
                }  
            }  
            catch (Exception e)  
            {  
                Console.WriteLine(e.StackTrace);  
            }  
        }  
    }  
}  

See Also

Common REST API Error Codes
Operations for Azure SQL Databases
Azure SQL Database
Azure SQL Database Cmdlets
Delete Server (classic)
List Servers (classic)