阿里云-云小站(无限量代金券发放中)
【腾讯云】云服务器、云数据库、COS、CDN、短信等热卖云产品特惠抢购

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

144次阅读
没有评论

共计 1545 个字符,预计需要花费 4 分钟才能阅读完成。

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

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

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

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

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

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

如果设置为 “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

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

其他程序连接设置如: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

正文完
星哥说事-微信公众号
post-qrcode
 0
星锅
版权声明:本站原创文章,由 星锅 于2022-01-22发表,共计1545字。
转载说明:除特殊说明外本站文章皆由CC-4.0协议发布,转载请注明出处。
【腾讯云】推广者专属福利,新客户无门槛领取总价值高达2860元代金券,每种代金券限量500张,先到先得。
阿里云-最新活动爆款每日限量供应
评论(没有评论)
验证码
【腾讯云】云服务器、云数据库、COS、CDN、短信等云产品特惠热卖中