Dela via


sys.sp_rda_reauthorize_db (Transact-SQL)

Applies to: SQL Server 2016 (13.x) and later versions

Restores the authenticated connection between a local database enabled for Stretch and the remote database.

Important

Stretch Database is deprecated in SQL Server 2022 (16.x) and Azure SQL Database. This feature will be removed in a future version of the Database Engine. Avoid using this feature in new development work, and plan to modify applications that currently use this feature.

Transact-SQL syntax conventions

Syntax

sp_rda_reauthorize_db
    [ @credential = ] credential
      , [ @with_copy = ] with_copy
    [ , [ @azure_servername = ] azure_servername
      , [ @azure_databasename = ] azure_databasename ]
[ ; ]

Arguments

[ @credential = ] N'credential'

The database scoped credential associated with the local Stretch-enabled database. @credential is sysname.

[ @with_copy = ] with_copy

Specifies whether to make a copy of the remote data and connect to the copy (recommended). @with_copy is bit.

[ @azure_servername = ] azure_servername

Specifies the name of the Azure server that contains the remote data. @azure_servername is sysname.

[ @azure_databasename = ] azure_databasename

Specifies the name of the Azure database that contains the remote data. @azure_databasename is sysname.

Return code values

0 (success) or > 0 (failure).

Permissions

Requires db_owner permissions.

Remarks

When you run sys.sp_rda_reauthorize_db (Transact-SQL) to reconnect to the remote Azure database, this operation automatically resets the query mode to LOCAL_AND_REMOTE, which is the default behavior for Stretch Database. That is, queries return results from both local and remote data.

Examples

The following example restores the authenticated connection between a local database enabled for Stretch and the remote database. It makes a copy of the remote data (recommended) and connects to the new copy.

DECLARE @credentialName NVARCHAR(128);

SET @credentialName = N'<existing_database_scoped_credential_name>';

EXEC sp_rda_reauthorize_db
    @credential = @credentialName,
    @with_copy = 1;