Get Server Event Logs (classic)

 

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

Gets the event logs for an Azure SQL Database Server.

This command uses the classic deployment model. You should use the newer Resource Manager based REST API commands located here. For more information, see Azure Resource Manager vs. classic deployment: Understand deployment models and the state of your resources.

Request

The Get Server Event Logs request must be specified as follows:

  • Replace {subscriptionId} with your subscription ID.

  • Replace {serverName} with the name of the server to retrieve the event logs from.

  • Replace {startDate} with the date and time to start retrieving the event logs.

  • Replace {intervalSizeInMinutes} with the size of the event logs to retrieve; 5, 60, or 1440 minutes.

  • Replace {eventTypes} with the event types to retrieve.

Method Request URI HTTP Version
GET https://management.core.windows.net:8443/{subscriptionId}/services/sqlservers/servers/{serverName}/events?startDate={startDate}&intervalSizeInMinutes={intervalSizeInMinutes}&eventTypes={eventTypes} HTTP/1.1

If there is a communication error or internal server error, you can check the status of the operation using List Servers (classic).

URI Parameters

The following table describes the URI parameters:

URI Parameter Description
startDate The starting date and time of the events to retrieve in UTC format, for example '2011-09-28 16:05:00'.
intervalSizeInMinutes The number of minutes of log entries to retrieve. Valid values are:

- 5
- 60
- 1440
eventTypes The event type of the log entries you want to retrieve. Valid values are:

- connection_successful
- connection_failed
- connection_terminated
- deadlock
- throttling
- throttling_long_transaction

*To return all event types pass in an empty string.

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.

Request Body

None.

Response

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

Status Code

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:

<ServiceResources xmlns="http://schemas.microsoft.com/windowsazure" xmlns:i="http://www.w3.org/2001/XMLSchema-instance">  
  <ServiceResource>  
    <Name>60testdb2013-08-21T10:00:00connectivityconnection_successful0</Name>  
    <Type>Microsoft.SqlAzure.EventLog</Type>  
    <State>Normal</State>  
    <SelfLink>https://management.core.windows.net/2eae7c21-ffd1-49e4-ac22-39095e0b9f02/services/sqlservers/servers/bpr0d6li5t/events/60testdb2013-08-21T10:00:00connectivityconnection_successful0</SelfLink>  
    <ParentLink>https://management.core.windows.net/2eae7c21-ffd1-49e4-ac22-39095e0b9f02/services/sqlservers/servers/bpr0d6li5t</ParentLink>  
    <DatabaseName>testdb</DatabaseName>  
    <StartTimeUtc>2013-08-21T10:00:00</StartTimeUtc>  
    <IntervalSizeInMinutes>60</IntervalSizeInMinutes>  
    <EventCategory>connectivity</EventCategory>  
    <EventType>connection_successful</EventType>  
    <EventSubtype>0</EventSubtype>  
    <EventSubtypeDescription>connection_successful</EventSubtypeDescription>  
    <NumberOfEvents>1</NumberOfEvents>  
    <Severity>0</Severity>  
    <Description>Connected successfully to database.</Description>  
    <AdditionalData i:nil="true"/>  
  </ServiceResource>  
</ServiceResources>  

The following table describes the elements of the response body:

Element Name Description
Name
Type The type of this service resource; Microsoft.SqlAzure.Eventlog.
State The state of the service resource.
SelfLink The URI for this service resource.
ParentLink The URI for the parent service resource.
DatabaseName The name of the database.
StartTimeUtc UTC date and time to start returning log entries.
IntervalSizeInMinutes The number of minutes of log entries retrieved.
EventCategory The high-level component that generated this event.
EventType The type of event.
EventSubtype The subtype of the occurring event.
EventSubtypeDescription The description of the event subtype.
NumberOfEvents The number of times that this event occurred for the specified database within the time interval specified.
Severity The severity of the error.
Description A detailed description of the event.

Example

The following console application retrieves the event logs from a server.

Replace the following values:

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

  • {serverName} – replace with the name of the server to get the event logs from.

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

Note


Set startDate, intervalSizeInMinutes, and eventTypes for the specific event logs to retrieve.

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 GetServerLogs  
{  
    /// <summary>  
    /// Gets the event logs for a server.  
    /// </summary>  
    class Program  
    {  
        static void Main(string[] args)  
        {  
            Uri requestUri = new Uri("https://management.core.windows.net:8443/"  
                        + "{subscriptionId}"  
                        + "/services"  
                        + "/sqlservers/servers/{serverName}/events"  
                        + "?startDate=2014-05-17T00:00:00"  
                        + "&intervalSizeInMinutes=60"  
                        + "&eventTypes=connection_successful");  
  
            // Create the request and specify attributes.  
            HttpWebRequest request = (HttpWebRequest)HttpWebRequest.Create(requestUri);  
  
            // Add a x-ms-version header to specify 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 = "GET";  
            request.ContentType = "application/xml";  
  
            // 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 the 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
Azure SQL Database
Operations for Azure SQL Databases
Get Database Event Logs (classic)
Azure SQL Database Cmdlets