Esporta (0) Stampa
Espandi tutto

Managing the Administrator Password for Servers

The Set Server Administrator Password operation sets the administrative password of a database SQL di Azure server for a subscription.

Request

The Set Server Administrator Password request must be specified as follows. Replace <subscription-id> with your subscription ID and <servername> with the server name that will have its password reset.

 

Method Request URI HTTP Version

POST

https://management.database.windows.net:8443/<subscription-id>/servers/<servername>?op=ResetPassword

HTTP/1.1

URL Parameters

No URL parameters used with this operation.

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 1.0.

Request Body

The format of the request body is as follows:

<?xml version="1.0" encoding="utf-8"?>
<AdministratorLoginPassword xmlns="http://schemas.microsoft.com/sqlazure/2010/12/">TheNewPassword</AdministratorLoginPassword>

Sample Request

The following is an example request body:

<?xml version="1.0" encoding="utf-8"?>
<AdministratorLoginPassword xmlns="http://schemas.microsoft.com/sqlazure/2010/12/">S0m3N3wP@$$w0rd</AdministratorLoginPassword>

Response

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

Status Code

A successful Set Server Administrator Password operation will return HTTP status code 200 (Success).

Potential errors for this operation include the errors listed in the following table.

 

Error code HTTP status code User Message

40630

Bad Request (400)

Password validation failed. The password does not meet policy requirements because it is too short.

40631

Bad Request (400)

The password that you specified is too long. The password should have no more than 128 characters.

40632

Bad Request (400)

Password validation failed. The password does not meet policy requirements because it is not complex enough.

40638

Bad Request (400)

Invalid subscription id <subscription-id>. Subscription does not exist.

40639

Bad Request (400)

Request does not conform to schema: <schema error>.

40640

Internal Server Error (500)

The server encountered an unexpected exception.

40642

Service Unavailable (503)

The server is currently too busy. Please try again later.

40643

Bad Request (400)

The specified x-ms-version header value is invalid.

40644

Forbidden (403)

Failed to authorize access to the specified subscription.

40645

Bad Request (400)

Servername <servername> cannot be empty or null. It can only be made up of lowercase letters 'a'-'z', the numbers 0-9 and the hyphen. The hyphen may not lead or trail in the name.

40646

Bad Request (400)

Subscription ID cannot be empty.

40647

Bad Request (400)

Subscription <subscription-id> does not have server <servername>.

40648

Service Unavailable (503)

Too many requests have been performed. Please retry later.

40649

Bad Request (400)

Invalid content-type is specified. Only application/xml is supported.


For more information about status codes for the database SQL di Azure Management API, see Status and Error Codes.

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.

The database SQL di Azure Management API does not support asynchronous calls.

Response Body

The Set Server Administrator Password operation does not return a response body. The HTTP status code indicates success or failure.

Code Example

The following code provides a simple example for calling this operation from a C# console application. This code uses the System.Net.HttpWebRequest and System.Security.Cryptography.X509Certificate2 class to submit the request using the private key certificate.

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Net;
using System.Security.Cryptography.X509Certificates;
using System.IO;
using System.Xml;

namespace SQLAzureDatabaseManagement
{
    class Program
    {

        static void Main(string[] args)
        {
            string certFile;
            string certPassword;
            string subscriptionId;
            string ServerName;
            string NewPassword;

            if (args.Length != 5)
            {
                Console.WriteLine("\nInsufficient Arguments.\n");
                Console.WriteLine("Expected CertfilePath, CertfilePassword, SubscriptionID, ServerName, and NewPassword.\n");
                return;
            }
            else
            {
                certFile = args[0];
                certPassword = args[1];
                subscriptionId = args[2];
                ServerName = args[3];
                NewPassword = args[4];
            }


            //=========================================================================//
            //=== Execute SQL Database Server and Firewall Rules Management Operations ===//
            //=========================================================================//

            // Set a new server password
            SetServerAdministratorPassword(certFile, certPassword, subscriptionId, ServerName, NewPassword);
        }


        //===============================================================================================================//
        //===                                                                                                         ===//
        //=== SetServerAdministratorPassword                                                                          ===//
        //===                                                                                                         ===//
        //=== This function resets the administrator password of the specified server to a new specified password.    ===//
        //===                                                                                                         ===//
        //=== Input Parameters:                                                                                       ===//
        //===                                                                                                         ===//
        //===   string certFilename : Full path to the Personal Information Exchange (.pfx) file which holds the      ===//
        //===                         private key for the certificate. The public key file must already be associated ===//
        //===                         to the subscription.                                                            ===//
        //===                                                                                                         ===//
        //===   string certPassword : The password of the Personal Information Exchange (.pfx) file.                  ===//
        //===                                                                                                         ===//
        //===   string subscriptionId : This is the subscription id GUID in its string form.                          ===//
        //===                                                                                                         ===//
        //===   string Server : The SQL Database server that will have its firewall rules modified.                      ===//
        //===                                                                                                         ===//
        //===   string RuleName : The name of the firewall rule that is to be deleted from the server.                ===//
        //===                                                                                                         ===//
        //=== Output:                                                                                                 ===//
        //===                                                                                                         ===//
        //===   The output of this function is written to the console. The output includes:                           ===//
        //===                                                                                                         ===//
        //===     The subscription id passed to this function.                                                        ===//
        //===                                                                                                         ===//
        //===     The server name passed to this function.                                                            ===//
        //===                                                                                                         ===//
        //===     The name of the firewall rule passed to this function that is to be deleted from the server.        ===//
        //===                                                                                                         ===//
        //===     The x-ms-request-id header returned from the REST API call.                                         ===//
        //===                                                                                                         ===//
        //===     The HTTP Status code returned from the REST API call.                                               ===//
        //===                                                                                                         ===//
        //===============================================================================================================//

        static void SetServerAdministratorPassword(string certFilename, string certPassword, string subscriptionId, string Server, string AdminPwd)
        {
            Console.WriteLine("\n======================================");
            Console.WriteLine("=== SetServerAdministratorPassword ===");
            Console.WriteLine("======================================\n");
            Console.WriteLine("Subscription : {0}", subscriptionId);
            Console.WriteLine("Server : {0}\n", Server);

            try
            {
                string url = string.Format("https://management.database.windows.net:8443/{0}/servers/{1}?op=ResetPassword", subscriptionId, Server);
                HttpWebRequest webRequest = HttpWebRequest.Create(url) as HttpWebRequest;

                webRequest.ClientCertificates.Add(new X509Certificate2(certFilename, certPassword));
                webRequest.Headers["x-ms-version"] = "1.0";
                webRequest.Method = "POST";

                //=== Add the Request Payload ===//

                string xmlBody = "<?xml version=\"1.0\" encoding=\"utf-8\"?>\n" +
                                  "<AdministratorLoginPassword xmlns=\"http://schemas.microsoft.com/sqlazure/2010/12/\">" + 
                                    AdminPwd.ToString() +
                                 "</AdministratorLoginPassword>";

                Console.WriteLine("Request Body for SetServerAdministratorPassword : ...\n");
                Console.WriteLine(xmlBody + "\n");

                byte[] bytes = Encoding.UTF8.GetBytes(xmlBody);
                webRequest.ContentLength = bytes.Length;
                webRequest.ContentType = "application/xml;charset=utf-8";
                using (Stream requestStream = webRequest.GetRequestStream())
                {
                    requestStream.Write(bytes, 0, bytes.Length);
                }


                //=== Send the request and wait on the response ===//

                using (WebResponse webResponse = webRequest.GetResponse())
                {
                    //=== x-ms-request-id is useful for troubleshooting request failures with Microsoft ===//
                    Console.WriteLine("Response x-ms-request-id : {0}", webResponse.Headers["x-ms-request-id"]);
                    Console.WriteLine("HttpStatusCode = {0}\n", (int)((HttpWebResponse)webResponse).StatusCode);

                    using (Stream stream = webResponse.GetResponseStream())
                    {
                        using (StreamReader sr = new StreamReader(stream))
                        {
                            Console.WriteLine(sr.ReadToEnd());
                        }
                    }
                }
            }


            //====================================================================================//
            //=== Catch WebExceptions. The SQL Database Management Service will          ===//
            //=== provide detailed error information in the response stream for WebExceptions. ===//
            //====================================================================================//

            catch (WebException webEx)
            {
                HttpWebResponse errorResponse = (HttpWebResponse)webEx.Response;
                Console.WriteLine(string.Format("HttpStatusCode = {0}", (int)errorResponse.StatusCode));

                try
                {
                    using (Stream errorResponseStream = errorResponse.GetResponseStream())
                    {
                        using (StreamReader sr = new StreamReader(errorResponseStream))
                        {
                            Console.WriteLine(sr.ReadToEnd());
                        }
                    }
                }
                catch (Exception innerEx)
                {
                    Console.WriteLine(innerEx.ToString());
                }
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.ToString() + "\n");
                if (ex.InnerException != null)
                {
                    Console.WriteLine(ex.InnerException.ToString() + "\n");
                }
            }
        }

    }
}


Building the Example Code

The example code can be added to a console application project and built in the Visual Studio Integrated Development Environment (IDE), or you can compile from the command line of a command prompt using the Visual C# compiler which is also included with the .

In this build shown below, the code was copied into a new text file named SetServerPassword.cs and compiled from the command line. This build also generates debugging information.

C:\Test>C:\Windows\Microsoft.NET\Framework64\v4.0.30319\csc /debug /out:SetServerPassword.exe SetServerPassword.cs

Microsoft (R) Visual C# 2010 Compiler version 4.0.30319.1
Copyright (C) Microsoft Corporation. All rights reserved.


C:\Test>dir
 Volume in drive C has no label.
 Volume Serial Number is 5471-ED89

 Directory of C:\Test

02/15/2011  02:52 PM    <DIR>          .
02/15/2011  02:52 PM    <DIR>          ..
02/15/2011  02:52 PM             7,168 SetServerPassword.exe
02/15/2011  02:52 PM            13,824 SetServerPassword.pdb

Executing the Example Code

The following example executes the example code using the private key certificate MyCert.pfx for authentication. The public key certificate (MyCert.cer) has already been added to the subscription. For more information on authentication, see Authenticating Azure SQL Database Management API Requests.

The globally unique identifier 2eae7c21-ffd1-49e4-ac22-39095e0b9f02 is an example subscription id. This subscription already has the database SQL di Azure server, l1ej7qgrem, provisioned for it. The command line shown below sends a request to have that server’s administrative password changed to “S0m3N3wP@$$w0rd”. The HTTP status code, 200 is a success response code indicating the operation succeeded.

C:\Test>SetServerPassword C:\SecureStore\MyCert.pfx MyCertPassword 2eae7c21-ffd1-49e4-ac22-39095e0b9f02 l1ej7qgrem S0m3N3wP@$$w0rd

======================================
=== SetServerAdministratorPassword ===
======================================

Subscription : 2eae7c21-ffd1-49e4-ac22-39095e0b9f02
Server : l1ej7qgrem

Request Body for SetServerAdministratorPassword : ...

<?xml version="1.0" encoding="utf-8"?>
<AdministratorLoginPassword xmlns="http://schemas.microsoft.com/sqlazure/2010/12/">S0m3N3wP@$$w0rd</AdministratorLoginPassword>

Response x-ms-request-id : e9506d18-69de-4b2d-baa9-8543703ce691
HttpStatusCode = 200

Vedere anche

Mostra:
© 2014 Microsoft