New-​Azure​Sql​Database​Server​Context

Creates a server connection context.

Syntax

New-AzureSqlDatabaseServerContext
   -Credential <PSCredential>
   [-Profile <AzureSMProfile>]
   -ServerName <String>
   [<CommonParameters>]
New-AzureSqlDatabaseServerContext
   -Credential <PSCredential>
   -ManageUrl <Uri>
   [-Profile <AzureSMProfile>]
   [-ServerName <String>]
   [<CommonParameters>]
New-AzureSqlDatabaseServerContext
   -Credential <PSCredential>
   -FullyQualifiedServerName <String>
   [-Profile <AzureSMProfile>]
   [<CommonParameters>]
New-AzureSqlDatabaseServerContext
   -FullyQualifiedServerName <String>
   [-Profile <AzureSMProfile>]
   [-SubscriptionName <String>]
   [-UseSubscription]
   [<CommonParameters>]
New-AzureSqlDatabaseServerContext
   [-Profile <AzureSMProfile>]
   -ServerName <String>
   [-SubscriptionName <String>]
   [-UseSubscription]
   [<CommonParameters>]

Description

The New-AzureSqlDatabaseServerContext cmdlet creates an Azure SQL Database server connection context. Use SQL Server authentication to create a connection context to a SQL Database server by using the specified credentials. You can specify the SQL Database server by name, by the fully qualified name, or by URL. To obtain a credential, use the Get-Credential cmdlet that prompts you to specify the user name and password.

Use the New-AzureSqlDatabaseServerContext cmdlet with certificate based authentication to create a connection context to the specified SQL Database server by using the specified Azure subscription data. You can specify SQL Database server by name or by the fully qualified name. You can specify the subscription data as a parameter or it can be retrieved from the current Azure subscription. Use the Select-AzureSubscriptionhttp://msdn.microsoft.com/library/windowsazure/jj152833.aspx cmdlet to select the current Azure subscription.

Examples

Example 1: Create a context by using SQL Server authentication

PS C:\> $Credential = Get-Credential
PS C:\> $Context = New-AzureSqlDatabaseServerContext -ServerName "lpqd0zbr8y" -Credential $Credential
PS C:\> $Database17 = New-AzureSqlDatabase -ConnectionContext $Context -DatabaseName "Database17" -MaxSizeGB 50 -Collation "SQL_Latin1_General_CP1_CI_AS"

This example uses the SQL Server authentication.

The first command prompts you for server administrator credentials, and stores the credentials in the $Credential variable.

The second command connects to the SQL Database server named lpqd0zbr8y by using $Credential.

The final command creates a database named Database17 on the server that is part of the context in $Context.

Example 2: Create a context by using certificate based authentication

PS C:\> $SubscriptionId = <Subscription ID>
PS C:\> $Thumbprint = <Certificate Thumbprint>
PS C:\> $Certificate = Get-Item "Cert:\CurrentUser\My\$Thumbprint"
PS C:\> Set-AzureSubscription -SubscriptionName "Subscription07" -SubscriptionId $SubscriptionId -Certificate $Certificate
PS C:\> Select-AzureSubscription -SubscriptionName "Subscription07"
PS C:\> $Context = New-AzureSqlDatabaseServerContext -ServerName "lpqd0zbr8y" -UseSubscription

This example uses the certificate based authentication.

The first two commands assign values to the $SubscriptionId and $Thumbprint variables.

The third command gets the certificate identified by the thumbprint in $Thumbprint, and stores it in $Certificate.

The fourth command sets the subscription to be Subscription07, and the fifth command selects that subscription.

The final command creates a context in the current subscription for the server named lpqd0zbr8y.

Required Parameters

-Credential

Specifies a credential object that provides SQL Server authentication for you to access the server.

Type:PSCredential
Position:Named
Default value:None
Accept pipeline input:False
Accept wildcard characters:False
-FullyQualifiedServerName

Specifies the fully qualified domain name (FQDN) name for the Azure SQL Database server. For example, Server02.database.windows.net.

Type:String
Position:Named
Default value:None
Accept pipeline input:False
Accept wildcard characters:False
-ManageUrl

Specifies the URL that this cmdlet uses to access the Azure SQL DatabaseManagement Portal for the server.

Type:Uri
Position:Named
Default value:None
Accept pipeline input:False
Accept wildcard characters:False
-ServerName

Specifies the name of the database server.

Type:String
Position:Named
Default value:None
Accept pipeline input:True (ByPropertyName)
Accept wildcard characters:False
-UseSubscription

Indicates that this cmdlet uses Azure subscription for creating the connection context.

Type:SwitchParameter
Position:Named
Default value:None
Accept pipeline input:False
Accept wildcard characters:False

Optional Parameters

-Profile

Specifies the Azure profile from which this cmdlet reads. If you do not specify a profile, this cmdlet reads from the local default profile.

Type:AzureSMProfile
Position:Named
Default value:None
Accept pipeline input:False
Accept wildcard characters:False
-SubscriptionName

Specifies the name of the Azure subscription that this cmdlet uses to create the connection context. If you do not specify a value for this parameter, the cmdlet uses the current subscription. Run the Select-AzureSubscription cmdlet to change the current subscription.

Type:String
Position:Named
Default value:None
Accept pipeline input:True (ByPropertyName)
Accept wildcard characters:False

Outputs

Microsoft.WindowsAzure.Commands.SqlDatabase.Services.Server.IServerDataServiceContext

Notes

  • If you authenticate without specifying a domain, and if you use Windows PowerShell 2.0, the Get-Credential cmdlet returns a backslash (\) prepended to the username, for example, \user. Windows PowerShell 3.0 does not add the backslash. This backslash is not recognized by the Credential parameter of the New-AzureSqlDatabaseServerContext cmdlet. To remove it, use commands similar to the following:

    PS C:\\\> $Credential = Get-Credential PS C:\\\> $Credential = New-Object -TypeName 'System.Management.Automation.PSCredential' -ArgumentList $Credential.Username.Replace("\",""),$Credential.Password