你好,游客 登录 注册 搜索
背景:
阅读新闻

SQL Server AlwaysOn 可用性组副本只读设置

[日期:2017-05-18] 来源:Linux社区  作者:黄泽成 [字体:大 中 小]

SQL Server AlwaysOn 可用性组副本是允许只读的,默认情况下不可读。

其中副本的可读性有几个选项:

NO : 不可连接到副本数据库,因此也不可读。默认设置。

Read-intent only:只有限定 “read-only” 时才能访问数据库,但只读。

Yes:所有连接都有可访问数据库,但只读。

如果设置为 “Read-intent only” ,客户端查询该数据库对象时提示以下错误:

Msg 976, Level 14, State 1, Line 1
The target database, 'TestDB', 
is participating in an availability group and is currently not accessible for queries. 
Either data movement is suspended or the availability replica is not enabled for read access. 
To allow read-only access to this and other databases in the availability group, 
enable read access to one or more secondary availability replicas in the group.  
For more information, see the ALTER AVAILABILITY GROUP statement in SQL Server Books Online.

若设置为 “Read-intent only”,又打算可读副本数据库数据,客户端连接设置如下:

连接时加上 ReadOnly 参数: ApplicationIntent=ReadOnly

其他程序连接设置如:ApplicationIntent=readonly

("Driver={SQL Server Native Client 11.0};server=AGListener;Database=dbname;trusted_connection=yes;ApplicationIntent=readonly”) 


使用 sqlcmd 工具连接需要设置参数 “-K”

sqlcmd -SAGListener -E -dDBName -Kreadonly 

若都允许只读,选择 “Yes” 即可更改,或使用命令更改:

  1. USE [master] 
  2. GO 
  3. ALTER AVAILABILITY GROUP [AGName] 
  4. MODIFY REPLICA ON N'InstanceName' WITH (SECONDARY_ROLE(ALLOW_CONNECTIONS = ALL)) 
  5. GO 

参考:

将连接字符串关键字用于 SQL Server Native Client

onnect to SQL Server AlwaysOn replica with SSMS when Readable Secondary is set to Read-intent only

本文永久更新链接地址:http://www.linuxidc.com/Linux/2017-05/143922.htm

linux
相关资讯       SQL Server AlwaysOn 
本文评论   查看全部评论 (0)
表情: 表情 姓名: 字数

       

评论声明
  • 尊重网上道德,遵守中华人民共和国的各项有关法律法规
  • 承担一切因您的行为而直接或间接导致的民事或刑事法律责任
  • 本站管理人员有权保留或删除其管辖留言中的任意内容
  • 本站有权在网站内转载或引用您的评论
  • 参与本评论即表明您已经阅读并接受上述条款