是否可以计划新数据层SQL Azure实例的规模?

是否可以计划新数据层SQL Azure实例的规模?,azure,azure-sql-database,Azure,Azure Sql Database,是否可以计划在夜间将Azure SQL实例的重缩放(即缩减为“基本”),然后在白天将其升级为“标准S2” 谢谢 编辑 我确实尝试使用Powershell Runbook使用Azure Automation,但出现以下错误: Error: New-AzureSqlDatabaseServerContext : A network-related or instance- specific error occurred while establishing a connection to SQ

是否可以计划在夜间将Azure SQL实例的重缩放(即缩减为“基本”),然后在白天将其升级为“标准S2”

谢谢

编辑

我确实尝试使用Powershell Runbook使用Azure Automation,但出现以下错误:

Error: New-AzureSqlDatabaseServerContext : A network-related or instance-  
specific error occurred while establishing a 
connection to SQL Server. The server was not found or was not accessible.
Verify that the instance name is correct and 
that SQL Server is configured to allow remote connections. (provider: Named 
Pipes Provider, error: 40 - Could not open 
a connection to SQL Server)
我已经提供了所有请求的参数值。也许我有一个复杂的事实,自动化必须从西欧运行,我的资源在北欧

编辑2


分类。只需将DatabaseServerName指定为名称,并排除“.database.windows.net”。另外,请确保为SQLServer而不是Active Directory创建凭据资产,并使用此资源。所以,再次标记作为答案。

你们可以这样做,但要确保你们有足够的空间来放大完成。按数据库大小的顺序进行放大操作,这是一个没有停机的在线操作。

您可以这样做,但只需确保您有足够的空间来完成放大操作。按数据库大小的顺序进行放大操作,这是一个没有停机时间的在线操作。

我通过运行CloudService Worker角色和使用更新数据库Azure SQL Rest操作的计划任务来完成此操作

私有字符串GetAuthorizationHeader()
{
AuthenticationResult=null;
var context=新的AuthenticationContext(“https://login.windows.net/“+_aadtenandomain);
//如果要显示凭证对话框,请执行以下操作:
//结果=上下文。AcquireToken(
//    "https://management.core.windows.net/", 
//_aadClientId,
//新Uri(“http://localhost)、PromptBehavior.Auto);
//直接指定用户名和密码。
var-credential=新用户凭证(
"yourusername@address.com",
“密码123”);
结果=context.AcquireToken(
"https://management.core.windows.net/",
_aadClientId,
证书);
如果(结果==null)
{
抛出新的InvalidOperationException(“未能获取JWT令牌”);
}
字符串令牌=result.AccessToken;
返回令牌;
}
私有void ScaleDatabase(字符串服务器名、字符串数据库名、字符串版本、Guid serviceLevelId)
{
使用(var client=new HttpClient())
{
var header=GetAuthorizationHeader();
client.DefaultRequestHeaders.Authorization=新的AuthenticationHeaderValue(“承载者”,标头);
client.DefaultRequestHeaders.Add(“x-ms-version”、“2012-03-01”);
字符串url=string.Format(“https://management.core.windows.net:8443/{0}/services/sqlservers/servers/{1}/databases/{2}“,
_订阅ID、服务器名、数据库名);
//string edition=“标准”;
//字符串serviceObjId=“f1173c43-91bd-4aaa-973c-54e79e15235b”;
string xmlBody=string.Format(
""
+ "{0}"
+ "{1}"
+ "{2}"
+“”,databaseName,edition,serviceLevelId.ToString());
var request=newhttprequestmessage(HttpMethod.Put,url);
request.Content=newstringcontent(xmlBody,Encoding.UTF8,“application/xml”);
var response=client.sendaync(request.Result);
}
}
您可能需要添加nuget软件包:安装软件包Microsoft.IdentityModel.Clients.ActiveDirectory

我还发现这个版本,虽然说是可选的,但实际上是必需的

此外,如果要缩小比例,请确保还为所需版本指定了数据库的最大大小。
当前标准数据库的最大数据库大小为50gb,将不允许您扩展到Basic,除非您还将新的最大数据库大小最大值设置为2gb。

我通过使用更新数据库Azure SQL Rest操作的计划任务运行CloudService Worker角色来实现这一点

私有字符串GetAuthorizationHeader()
{
AuthenticationResult=null;
var context=新的AuthenticationContext(“https://login.windows.net/“+_aadtenandomain);
//如果要显示凭证对话框,请执行以下操作:
//结果=上下文。AcquireToken(
//    "https://management.core.windows.net/", 
//_aadClientId,
//新Uri(“http://localhost)、PromptBehavior.Auto);
//直接指定用户名和密码。
var-credential=新用户凭证(
"yourusername@address.com",
“密码123”);
结果=context.AcquireToken(
"https://management.core.windows.net/",
_aadClientId,
证书);
如果(结果==null)
{
抛出新的InvalidOperationException(“未能获取JWT令牌”);
}
字符串令牌=result.AccessToken;
返回令牌;
}
私有void ScaleDatabase(字符串服务器名、字符串数据库名、字符串版本、Guid serviceLevelId)
{
使用(var client=new HttpClient())
{
var header=GetAuthorizationHeader();
client.DefaultRequestHeaders.Authorization=新的AuthenticationHeaderValue(“承载者”,标头);
client.DefaultRequestHeaders.Add(“x-ms-version”、“2012-03-01”);
字符串url=string.Format(“https://management.core.windows.net:8443/{0}/services/sqlservers/servers/{1}/databases/{2}“,
_订阅ID、服务器名、数据库名);
//string edition=“标准”;
//字符串serviceObjId=“f1173c43-91bd-4aaa-973c-54e79e15235b”;
string xmlBody=string.Format(
""
+ "{0}"
+ "{1}"
+ "{2}"
+“”,databaseName,edition,serviceLevelId.ToString());
private string GetAuthorizationHeader()
    {
        AuthenticationResult result = null;
        var context = new AuthenticationContext("https://login.windows.net/" + _aadTenantDomain);

        // If you wanted to show a credential dialog, do this: 
        //result = context.AcquireToken( 
        //    "https://management.core.windows.net/", 
        //    _aadClientId, 
        //      new Uri("http://localhost"), PromptBehavior.Auto); 

        // Directly specify the username and password. 
        var credential = new UserCredential(
            "yourusername@address.com",
            "password123");

        result = context.AcquireToken(
            "https://management.core.windows.net/",
            _aadClientId,
                credential);
        if (result == null)
        {
            throw new InvalidOperationException("Failed to obtain the JWT token");
        }

        string token = result.AccessToken;
        return token;
    }


    private void ScaleDatabase(string serverName, string databaseName, string edition, Guid serviceLevelId)
    {

        using (var client = new HttpClient())
        {
            var header = GetAuthorizationHeader();
            client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", header);
            client.DefaultRequestHeaders.Add("x-ms-version", "2012-03-01");

            string url = String.Format("https://management.core.windows.net:8443/{0}/services/sqlservers/servers/{1}/databases/{2}",
                _subscriptionId, serverName, databaseName);

            //string edition = "Standard";
            //string serviceObjId = "f1173c43-91bd-4aaa-973c-54e79e15235b";

            string xmlBody = String.Format(
            "<ServiceResource xmlns=\"http://schemas.microsoft.com/windowsazure\" xmlns:i=\"http://www.w3.org/2001/XMLSchema-instance\">"
               + "<Name>{0}</Name>"
              + "<Edition>{1}</Edition>"
              + "<ServiceObjectiveId>{2}</ServiceObjectiveId>"
               + "</ServiceResource>", databaseName, edition, serviceLevelId.ToString());

            var request = new HttpRequestMessage(HttpMethod.Put, url);
            request.Content = new StringContent(xmlBody, Encoding.UTF8, "application/xml");

            var response = client.SendAsync(request).Result;
        }

    }