Exporteren (0) Afdrukken
Alles uitvouwen
EN
Deze inhoud is niet beschikbaar in uw taal, maar wel in het Engels.
1 van 1 hebben dit beoordeeld als nuttig - Dit onderwerp beoordelen

Enumerating Servers

The Get Servers operation enumerates SQL Database servers that are provisioned for a subscription.

Request

The Get Servers request must be specified as follows. Replace <subscription-id> with your subscription ID.

 

Method Request URI HTTP Version

GET

https://management.database.windows.net:8443/<subscription-id>/servers

HTTP/1.1

URI 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 Get Servers operation does not use a request body.

Response

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

Status Code

A successful Get Servers operation will return HTTP status code 200 (Succeeded).

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

 

Error code HTTP status code User Message

15021

Bad Request (400)

Invalid value given for parameter <parameter name>. Specify a valid parameter value.

40638

Bad Request (400)

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

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.

40648

Service Unavailable (503)

Too many requests have been performed. Please retry later.

40677

Bad Request (400)

The operation for the request uri '%.*ls' was not found. To continue, please provide a valid request uri.


For more information about status codes for the SQL Database 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 SQL Database Management API does not support asynchronous calls.

Response Body

The format of the response body is as follows:

<Servers xmlns="http://schemas.microsoft.com/sqlazure/2010/12/">
  <Server>
    <Name>ServerName</Name>
    <AdministratorLogin>AdminAccount</AdministratorLogin>
    <Location>North Central US | South Central US | North Europe | West Europe | East Asia | Southeast Asia</Location>
  </Server>
</Servers>

Sample Response

The following is an example response body:

<Servers xmlns="http://schemas.microsoft.com/sqlazure/2010/12/">
  <Server>
    <Name>bpr0d6li5t</Name>
    <AdministratorLogin>MyAdmin</AdministratorLogin>
    <Location>North Central US</Location>
  </Server>
</Servers>

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;

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



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

            // List the servers for the subscription
            GetServers(certFile, certPassword, subscriptionId);
        }


        //===============================================================================================================//
        //===                                                                                                         ===//
        //=== GetServers                                                                                              ===//
        //===                                                                                                         ===//
        //=== This function returns the list of SQL Database servers already provisioned for the specified subscription. ===//
        //===                                                                                                         ===//
        //=== 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: Password on the Personal Information Exchange (.pfx) file.                       ===//
        //===                                                                                                         ===//
        //===   string subscriptionId : This is the subscription id GUID in its string form.                          ===//
        //===                                                                                                         ===//
        //=== Output:                                                                                                 ===//
        //===                                                                                                         ===//
        //===   The output of this function is written to the console. The output includes:                           ===//
        //===                                                                                                         ===//
        //===     The subscription id passed to this function.                                                        ===//
        //===                                                                                                         ===//
        //===     The x-ms-request-id header returned from the REST API call.                                         ===//
        //===                                                                                                         ===//
        //===     The HTTP Status code return from the REST API call.                                                 ===//
        //===                                                                                                         ===//
        //===     The response body containing the server list returned from the REST API call or the exception/error ===//
        //===     encountered during the REST API call.                                                               ===//
        //===                                                                                                         ===//
        //===============================================================================================================//

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

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


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

                //=== No Request Payload needed to return server list ===//

                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");
            }
        }

    }
}


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 .NET Framework.

In this build shown below, the code was copied into a new text file named GetServers.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:GetServers.exe GetServers.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:24 PM    <DIR>          .
02/15/2011  02:24 PM    <DIR>          ..
02/15/2011  02:24 PM             6,144 GetServers.exe
02/15/2011  02:24 PM            13,824 GetServers.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 Windows Azure SQL Database Management API Requests.

The globally unique identifier 2eae7c21-ffd1-49e4-ac22-39095e0b9f02 is an example Windows Azure subscription id. The XML shown in the output shows the server’s response to the request to get all servers for the subscription. The response shows one server, l1ej7qgrem, provisioned for the subscription in the “North Central US” location with its administrator account name set to “MyAdmin”.

C:\Test>GetServers C:\SecureStore\MyCert.pfx MyCertPassword 2eae7c21-ffd1-49e4-ac22-39095e0b9f02


================================
====== GetServers Request ======
================================

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

Response x-ms-request-id : ddec2471-d98b-4094-aa61-2e57b1d35a4d
HttpStatusCode = 200

<Servers xmlns="http://schemas.microsoft.com/sqlazure/2010/12/">
  <Server>
    <Name>l1ej7qgrem</Name>
    <AdministratorLogin>MyAdmin</AdministratorLogin>
    <Location>North Central US</Location>
  </Server>
</Servers>

See Also

Vindt u dit nuttig?
(1500 tekens resterend)
Bedankt voor uw feedback

Community-inhoud

Weergeven:
© 2014 Microsoft. Alle rechten voorbehouden.