列出SQL Azure数据库

时间:2012-11-26 12:13:17

标签: rest azure azure-sql-database

我们可以使用以下请求URL列出与特定订阅相对应的所有数据库服务器。

https://management.database.windows.net:8443/SunscriptionID/servers

X-MS-版本= 1.0。

想知道是否有任何可用的服务来获取每个特定服务器内的数据库列表。???

2 个答案:

答案 0 :(得分:1)

您可以连接到每个SQL Azure服务器的主数据库并查询sys.databases

SELECT * FROM sys.databases

答案 1 :(得分:0)

您可以使用SOAP管理服务。首先,您需要获取身份验证令牌(使用服务器的用户名/密码进行基本身份验证):

GET https://MYSERVERNAME.database.windows.net/v1/ManagementService.svc/GetAccessToken HTTP/1.1
sqlauthorization: Basic smafizjfpafijpoazjeoijfamz=
Host: MYSERVERNAME.database.windows.net

响应将是身份验证令牌和cookie:

Set-Cookie: .SQLSERVERMANAGEMENT=fmazoijfazmojf==; 

<string xmlns="http://schemas.microsoft.com/2003/10/Serialization/">ffmjjzoipfjpozajfpzofjjmoezafjimozafjoamfjiazfamzofijzmfoijzafjoizafazamijfiiozfmozafjozamfjzmofjizmfozjfohfomzaifjzaomfjizamofzijamofjafmozafjmzafojzmijfzoifzajoimfzaijomfmoizaj==</string>

然后,您可以使用cookie和身份验证令牌获取特定服务器的数据库列表:

GET https://MYSERVERNAME.database.windows.net/v1/ManagementService.svc/Server2('MYSERVERNAME')/Databases HTTP/1.1
AccessToken: ffmjjzoipfjpozajfpzofjjmoezafjimozafjoamfjiazfamzofijzmfoijzafjoizafazamijfiiozfmozafjozamfjzmofjizmfozjfohfomzaifjzaomfjizamofzijamofjafmozafjmzafojzmijfzoifzajoimfzaijomfmoizaj==
x-ms-client-session-id: e5a2b587-930f-4cb1-82bc-2be5385f6ad1-2012-11-26 20:12:14Z
x-ms-client-request-id: 1ac2599c-c4dc-4a66-822b-15f81ba8216b-2012-11-26 20:12:14Z
Accept: application/atom+xml,application/xml
Accept-Charset: UTF-8
Host: MYSERVERNAME.database.windows.net
Cookie: .SQLSERVERMANAGEMENT=fmazoijfazmojf==

响应将是一个数据库列表:

<?xml version="1.0" encoding="utf-8" standalone="yes"?>
<feed xml:base="https://MYSERVERNAME.database.windows.net/v1/ManagementService.svc/Server2('MYSERVERNAME')/" xmlns:d="http://schemas.microsoft.com/ado/2007/08/dataservices" xmlns:m="http://schemas.microsoft.com/ado/2007/08/dataservices/metadata" xmlns="http://www.w3.org/2005/Atom">
  <title type="text">Databases</title>
  <id>https://MYSERVERNAME.database.windows.net/v1/ManagementService.svc/Server2('MYSERVERNAME')/Databases</id>
  <updated>2012-11-26T20:19:32Z</updated>
  <link rel="self" title="Databases" href="Databases" />
  <entry>
    <id>https://MYSERVERNAME.database.windows.net/v1/ManagementService.svc/Server2('MYSERVERNAME')/Databases(1)</id>
    <title type="text"></title>
    <updated>2012-11-26T20:19:32Z</updated>
    <author>
      <name />
    </author>
    <link rel="edit" title="Database" href="Databases(1)" />
    <link rel="http://schemas.microsoft.com/ado/2007/08/dataservices/related/Server" type="application/atom+xml;type=entry" title="Server" href="Databases(1)/Server" />
    <link rel="http://schemas.microsoft.com/ado/2007/08/dataservices/related/DatabaseMetrics" type="application/atom+xml;type=entry" title="DatabaseMetrics" href="Databases(1)/DatabaseMetrics" />
    <category term="Microsoft.SqlServer.Management.Server.Domain.Database" scheme="http://schemas.microsoft.com/ado/2007/08/dataservices/scheme" />
    <content type="application/xml">
      <m:properties>
        <d:Id m:type="Edm.Int32">1</d:Id>
        <d:Name>master</d:Name>
        <d:Edition>Web</d:Edition>
        <d:MaxSizeGB m:type="Edm.Int32">5</d:MaxSizeGB>
        <d:CollationName>SQL_Latin1_General_CP1_CI_AS</d:CollationName>
        <d:CreationDate m:type="Edm.DateTime">2012-11-26T14:36:41.387</d:CreationDate>
        <d:IsSystemObject m:type="Edm.Boolean">true</d:IsSystemObject>
        <d:Status m:type="Edm.Int32">1</d:Status>
        <d:IsFederationRoot m:type="Edm.Boolean">false</d:IsFederationRoot>
        <d:SizeMB m:type="Edm.Decimal">-1.00</d:SizeMB>
        <d:IsRecursiveTriggersOn m:type="Edm.Boolean">false</d:IsRecursiveTriggersOn>
        <d:IsReadOnly m:type="Edm.Boolean">false</d:IsReadOnly>
      </m:properties>
    </content>
  </entry>
</feed>