ssis sql

In this article, I am going to explain how we can transfer logins to the secondary replica of the Always On availability group using sp_help_revlogin and Transfer Logins Task of the SQL Server Integration Services package.

在本文中,我将解释如何使用SQL Server Integration Services程序包的sp_help_revlogin和“ 传输登录名”任务将登录名传输到Always On可用性组的辅助副本。

问题陈述 (Problem statement)

When we configure a new secondary replica, we must move the logins that are created on the primary replica. If we do not move the logins, after failover to the secondary replicas, users will receive the following error:

配置新的辅助副本时,必须移动在主副本上创建的登录名。 如果我们不移动登录名,则在故障转移到辅助副本后,用户将收到以下错误:

错误文字 (Error text)

TITLE: Connect to Server
——————————
Cannot connect to SQLAG.
——————————
ADDITIONAL INFORMATION:
Login failed for user ‘NUpadhyay.’ (Microsoft SQL Server, Error: 18456)
For help, click: http://go.microsoft.com/fwlink?ProdName=Microsoft%20SQL%20Server&EvtSrc=MSSQLServer&EvtID=18456&LinkId=20476

标题:连接到服务器
——————————
无法连接到SQLAG。
——————————
附加信息:
用户“ NUpadhyay”的登录失败。 (Microsoft SQL Server,错误:18456)
要获取帮助,请单击:http://go.microsoft.com/fwlink?ProdName=Microsoft%20SQL%20Server&EvtSrc=MSSQLServer&EvtID=18456&LinkId=20476

To demonstrate the scenario, I have created an Availability Group on my workstation. The following are the details:

为了演示这种情况,我在工作站上创建了一个可用性组。 详细信息如下:

Host name / Replica name

Role of the replica

SQL01

Primary Replica

SQL02

Secondary Replica

SQL03

Secondary Replica

主机名/副本名

副本的作用

SQL01

主副本

SQL02

二级副本

SQL03

二级副本

On the primary replica of the Availability group, I have created a SQL Login named NUpadhyay on the primary replica. It has a bulkadmin fixed server role. Execute the following query to obtain the information:

在“可用性”组的主副本上,我在主副本上创建了一个名为NUpadhyaySQL登录名。 它具有bulkadmin固定服务器角色。 执行以下查询以获取信息:

SELECT  sp.name AS [Name of Role],   member.name AS [Name of Member]
FROM sys.server_role_members  srm
JOIN sys.server_principals AS sp  ON srm.role_principal_id = sp.principal_id
JOIN sys.server_principals AS member  ON srm.member_principal_id = member.principal_id;

Following is the output:

以下是输出:

Now, let us do a planned manual failover. After failover, the SQL02.dc.local will become the primary replica, and SQL01.dc.local will become a secondary replica. To do that, execute the following set of commands on SQLCMD:

现在,让我们执行计划的手动故障转移。 故障转移后, SQL02.dc.local将成为主副本,而SQL01.dc.local将成为辅助副本。 为此,请在SQLCMD上执行以下命令集:

:Connect SQLAG
:Connect SQL01
ALTER AVAILABILITY GROUP [SQLAAG] FAILOVER;
GO
GO

See the following image:

见下图:

Once failover completes, try to login using NUpadhyay. You will see the following error:

故障转移完成后,尝试使用NUpadhyay登录。 您将看到以下错误:

As you can see, when we failover primary replica to the secondary replica, we are not able to connect to the database engine using SQL Login NUpadhyay. This issue can be fixed by recreating the same login on the secondary replicas. This looks easy, right? But imagine that we have a database server that has 100-200 logins. This task becomes very time-consuming. To resolve this issue, we can use any of the following approaches:

如您所见,当我们将主副本故障转移到辅助副本时,我们将无法使用SQL Login NUpadhyay连接到数据库引擎。 可以通过在辅助副本上重新创建相同的登录名来解决此问题。 这看起来很容易,对吧? 但是,假设我们有一台具有100-200个登录名的数据库服务器。 该任务非常耗时。 要解决此问题,我们可以使用以下任何一种方法:

  1. SSIS Transfer Login task SSIS转移登录任务
  2. sp_help_revlogin and sp_help_revloginsp_hexadecimal and use it to generate a sp_hexadecimal的存储过程,并使用它为所有用户生成CREATE LOGIN script for all the users CREATE LOGIN脚本

SSIS传输登录任务 (SSIS Transfer Logins task)

We can transfer the logins by using the Transfer Login task in the SQL Server Integration Services package. To do that, open SQL Server Data Tools 2017, create a new integration services project, and on the task flow window, drag and drop Transfer Login Task as shown below:

我们可以使用SQL Server Integration Services程序包中的“传输登录名”任务来传输登录名。 为此,请打开SQL Server Data Tools 2017,创建一个新的Integration Services项目,然后在任务流窗口上,拖放“ 传输登录任务” ,如下所示:

To configure the Transfer Login task, double-click on Transfer Logins Task, specify the source as SQL01 and destination as SQL02 and execute the package:

要配置传输登录任务的传输登录任务,双击,指定源作为SQL01和目的地SQL02和执行包:

Now, choose the name of the SQL Login that you want to transfer. To do that, first, select SelectedLogins from the LoginsToTransfer drop-down box, then select the name of the login by clicking on eclipse (…) opposite to the LoginList, tick the name of SQL Login from Select Login dialog box:

现在,选择要传输SQL登录名。 为此,首先,从LoginsToTransfer下拉框中选择SelectedLogins ,然后通过单击Eclipse选择登录名。 (…)与LoginList相对,在“ 选择登录”对话框中勾选SQL登录名:

Click OK to close the dialog box and execute the package to copy the logins from the source server to the destination server. Once the package executes successfully, you can see that the login NUpadhyay has been created.

单击“ 确定”关闭对话框并执行程序包,以将登录名从源服务器复制到目标服务器。 包成功执行后,您可以看到已创建登录NUpadhyay

SSIS Package execution log:

SSIS包执行日志:

New Login in SSMS:

SSMS中的新登录名:

创建sp_help_revlogin和sp_hexadecimal SP,并使用它们生成CREATE LOGIN命令 (Create sp_help_revlogin and sp_hexadecimal SP and use them to generate the CREATE LOGIN command)

We can use sp_help_revlogin and sp_hexadecimal stored procedure to transfer the logins from the primary replica to secondary replicas. Before I explain the process of copying login between replicas, let me explain how both stored procedures work.

我们可以使用sp_help_revloginsp_hexadecimal存储过程将登录名从主副本转移到辅助副本。 在解释复制副本之间的登录过程之前,让我解释两个存储过程如何工作。

The stored procedure sp_help_revlogin generates the CREATE Login statement for all the SQL Logins on any database instance, and the stored procedure sp_hexadecimal converts the password hash into the text file. Using these procedures, we can generate the T-SQL code to recreate the SQL Logins.

存储过程sp_help_revlogin为任何数据库实例上的所有SQL登录名生成CREATE Login语句,存储过程sp_hexadecimal将密码哈希转换为文本文件。 使用这些过程,我们可以生成T-SQL代码以重新创建SQL登录名。

Now, let’s come back to our issue. First, create both stored procedures in the DBA utility database. You can download the scripts from the SQL Server knowledge base article 246133.

现在,让我们回到我们的问题。 首先,在DBA实用程序数据库中创建两个存储过程。 您可以从SQL Server知识库文章246133下载脚本。

Once the procedure is created, execute it using exec <storedprocedure_name> command. Once the procedure executes successfully, it creates a following Create Login command:

创建过程后,请使用exec <storedprocedure_name>命令执行该过程。 该过程成功执行后,它将创建以下“ 创建登录”命令:

  1. The SQL Server certification-based logins start with ## 基于SQL Server认证的登录名以##开头
  2. The NT Authority virtual account NT Authority虚拟帐户
  3. The NT Services virtual account NT Services虚拟帐户

The above logins are not required to recreate on the secondary replica; hence to filter those logins, we will create another script which does the following tasks:

不需要在辅助副本上重新创建上述登录名; 因此,为了过滤这些登录名,我们将创建另一个脚本,该脚本执行以下任务:

  1. ## or #SQLLogins的临时表中插入名称不是NT% in the temporary table named###SQLLogins tables NT%SQL登录名和组。
  2. #SQL_Logins table, select the name of the user/group from the #SQL_Logins表,从LoginName column and store it in LoginName列中选择用户/组的名称,并将其存储在@LoginName variable @LoginName变量中
  3. sp_help_revlogin to generate the Create Login script for the user/group stored in the sp_help_revlogin为存储在@LoginName variable @LoginName变量中的用户/组生成“创建登录”脚本。

Following is the T-SQL script:

以下是T-SQL脚本:

declare @LoginCount int
declare @LoginName sysname
declare @i int =0
create table #SQL_Logins
(LoginName sysname)
insert into #SQL_Login (LoginName) select name from sys.server_principals where (LEFT(name, 4) NOT IN ('NT A', 'NT S')
AND
TYPE IN ('U', 'G'))
OR
(LEFT(name, 2) <> '##'
AND
TYPE = 'S');
set @LoginCount = (select count(LoginName) from #SQL_Logins)
While(@LoginCount>@i)
begin
set @LoginName = (select top 1 name from #SQL_Logins)
exec sp_help_revlogin @LoginName
delete from #SQL_Login where name=@LoginName
set @i=@i+1
End

Below is the output of the script:

以下是脚本的输出:

— Login: sa
CREATE LOGIN [sa] WITH PASSWORD = 0x0200653E7B270B00E2B21F0ED0157B9163D536C083AFBD243C38A06587DEE4992F31193F266EB40AE37477560896F60004A267409EFDD0FB40F87F3A57A2449C8C6E9E9E74A0 HASHED, SID = 0x01, DEFAULT_DATABASE = [master], CHECK_POLICY = ON, CHECK_EXPIRATION = OFF

— Login: DCLocal\administrator
CREATE LOGIN [DCLocal\administrator] FROM WINDOWS WITH DEFAULT_DATABASE = [master]

— Login: NUpadhyay
CREATE LOGIN [NUpadhyay] WITH PASSWORD = 0x0200BC66349CABC7E2DA1DF21146287E9C48204D87B00108C6A09328B4651D531866A05846899FBBCC746A6B10C018014B679DC06ECCA384ADB469A3EBDE3EDE4FBD7FA90466 HASHED, SID = 0xDFFB516810E4234B974514193834C64D, DEFAULT_DATABASE = [master], CHECK_POLICY = OFF, CHECK_EXPIRATION = OFF

— Login: NisargUpadhyay
CREATE LOGIN [NisargUpadhyay] WITH PASSWORD = 0x02003E426F1A9106140C4B913F7CFBAB2EC577CA1F6C85521C9C6EA9AB1FE4E4AB510BA9B32F54172C513799267774B71F5C5CF90E28BEC2F80049631B219CDB5B7365D8F555 HASHED, SID = 0xB01FBD7C17393447AC33AEAD41E3182E, DEFAULT_DATABASE = [master], CHECK_POLICY = OFF, CHECK_EXPIRATION = OFF

—登录:sa
使用密码= 0x0200653E7B270B00E2B21F0ED0157B9163D536C083AFBD243C38A06587DEE4992F31193F266EB40AE37477560896F60004A267409EFDD0FB40F87F3A57A2449C8C6E9E9E9E74E

—登录:DCLocal \ administrator
使用DEFAULT_DATABASE = [master]从WINDOWS创建登录[DCLocal \ administrator]

—登录:NUpadhyay
CREATE LOGIN [NUpadhyay] WITH PASSWORD = 0x0200BC66349CABC7E2DA1DF21146287E9C48204D87B00108C6A09328B4651D531866A05846899FBBCC746A6B10C018014B679DC06ECCA384ADB469A3EBDE3EDE4FBD7FA90466 HASHED,SID = 0xDFFB516810E4234B974514193834C64D,DEFAULT_DATABASE = [主],CHECK_POLICY = OFF,CHECK_EXPIRATION = OFF

—登录:NisargUpadhyay
CREATE LOGIN [NisargUpadhyay] WITH PASSWORD = 0x02003E426F1A9106140C4B913F7CFBAB2EC577CA1F6C85521C9C6EA9AB1FE4E4AB510BA9B32F54172C513799267774B71F5C5CF90E28BEC2F80049631B219CDB5B7365D8F555 HASHED,SID = 0xB01FBD7C17393447AC33AEAD41E3182E,DEFAULT_DATABASE = [主],CHECK_POLICY = OFF,CHECK_EXPIRATION = OFF

Now connect to SQL02 replica and execute the above query to create the user. You can connect to SQL02 using SQL Server Management Studio, or you can use PowerShell. We will use the SQL Server Management Studio:

现在连接到SQL02副本并执行上面的查询以创建用户。 您可以使用SQL Server Management Studio连接到SQL02,也可以使用PowerShell。 我们将使用SQL Server Management Studio:

Once the user has been created, try to login using it:

创建用户后,尝试使用它登录:

As you can see from below, the SQL Login NUpadhyay is now able to connect to the Availability Group:

从下面可以看到,SQL登录NUpadhyay现在可以连接到可用性组:

摘要 (Summary)

In this article, I have explained how we can transfer SQL Logins from the primary replica to the secondary replica of the Availability Group using Transfer Logins Task of SQL Server Integration Services and the stored procedure named sp_help_revlogin and sp_hexadecimal.

在本文中,我已经说明了如何使用SQL Server Integration Services的“传输登录任务”以及名为sp_help_revlogin和sp_hexadecimal的存储过程将SQL登录名从可用性组的主副本传输到辅助副本。

翻译自: https://www.sqlshack.com/transferring-sql-logins-to-the-secondary-replica-of-ag-using-sp_help_revlogin-and-ssis-transfer-login-tasks/

ssis sql

ssis sql_使用sp_help_revlogin和SSIS传输登录任务将SQL登录名传输到AG的辅助副本相关推荐

  1. 简述使用ftp进行文件传输时的两种登录方式?它们的区别是什么?常用的ftp文件传输命令是什么?

    简述使用ftp进行文件传输时的两种登录方式?它们的区别是什么?常用的ftp文件传输命令是什么? 参考答案: (1)ftp有两种登录方式:匿名登录和授权登录.使用匿名登录时,用户名为:anonymous ...

  2. ssis 列转换_将SSIS包转换为Biml脚本

    ssis 列转换 In our previous article, Getting started with Biml, we have explained what Biml is, what ar ...

  3. kali linux ssh不要密码登录密码,kali linux 登录ssh服务常见问题

    kali linux 登录ssh服务常见问题 kali linux 登录ssh服务常见问题 kali linux 登录ssh服务常见问题 一.ssh简介 1.层次 2.ssh解决问题 二.服务器发送了 ...

  4. ssh登录日志,ssh登录记录,最近ssh登录

    linux登录日志  /var/log/secure    (root用户可以删除该文件) 日志对于安全非常重要,记录了系统每天发生的各种事情,通过日志检查错误发生的原因,或者***后留下的痕迹.所有 ...

  5. 企业邮箱登录地址,邮箱登录入口,邮箱登录须知

    企业邮箱注册后,有很多登录方式选择,TOM企业邮箱可在官方网页端.独立定制登录页.微信端.手机APP.电脑邮箱客户端.接下来给大家一一介绍下~ 官方统一登录页 喜欢用网页端的用户,一般从统一登录页面登 ...

  6. 文件传输协议的五种安全文件传输替代方案

    对安全文件传输协议的需求,过去,文件传输协议(FTP)是发送文件的常用协议.这是一个更简单的时期,安全性比今天要少得多. 但是随着黑客变得越来越复杂,他们发现FTP缺乏安全性.他们知道FTP可以通过有 ...

  7. SpringBoot整合Shiro实现一键登录和免密码登录功能

    前提: 大概是这样一个情况,我们有两个平台,一个是运营平台,一个是使用平台,我们的每个运维人员手底下管理者许多的客户的账号,为了方便运维和避免经常问用户索要密码,那么在这种情况下就需要用到我们的一键登 ...

  8. 如何实现文件高速传输,推荐镭速高速文件传输解决方案

    随着互联网的发展,文件传输越来越频繁,如何实现文件高速传输已经越来越成为企业发展过程中需要解决的问题, 在当今的业务中,随着与客户和供应商以及内部系统的所有通信的数据量不断增加,对高速文件传输解决方案 ...

  9. 前端常见登录实现方案 + 单点登录方案

    登录是每个网站中都会用到的一个必备功能,但是如何实现一个优秀的登录功能,如何根据自己的项目来选择一个适合自己的登录方案?今天我们就来介绍几种常用的登录方案. Cookie + Session 登录 T ...

最新文章

  1. java查询结果自定义显示_JPA自定义对象接收查询结果集操作
  2. 程序员多数性功能不行_从面试官角度观察到的程序员技能瓶颈,同时给出突破瓶颈的建议...
  3. 一个基于ngrx的计数器例子
  4. 让我放弃FastDFS拥抱MinIO的8个瞬间
  5. (转)Spring Boot(六):如何优雅的使用 Mybatis
  6. 10G整数文件中寻找中位数或者第K大数
  7. Robot Freamwork 安装配置文档
  8. 企业项目管理软件介绍
  9. 2021美亚团队赛复盘
  10. 栅栏密码 - Python脚本
  11. 微信小程序——小程序UI框架首页
  12. Java 替换PDF中的字体
  13. ArcGIS ERROR 999999: 执行函数时出错,未找到表。
  14. 升级wamp的php版本,Wamp升级PHP版本
  15. 2020计算机保研夏令营网信中心华师大浙软面经
  16. 亚里士多德对于知识的分类
  17. uniapp引入字体文件
  18. DDR 内存 ECC 纠错
  19. 关于Mono的好网站
  20. access9磅字体是多_word字体中几号字与多少磅的对应关系

热门文章

  1. java集合讲解_Java集合详解
  2. python3图像处理_Python3与OpenCV3.3 图像处理(二)--图像基本操作
  3. PLSQL DEVELOPER编辑器的自动替换文件
  4. python正则表达式之re模块方法介绍
  5. Linux DMA Engine framework(3)_dma controller驱动
  6. hbase 核心知识
  7. HIT Software Construction Review Notes(2-1 Software Lifecycle and Configuration Management)
  8. 【Vue】—子级向父级传递数据
  9. 【Express】—post传递参数
  10. HTML之表格的基本知识