Database | Proc | Application | Created | Links |
sybsystemprocs | sp_config_rep_agent ![]() | ![]() | 31 Aug 14 | Defects Dependencies |
1 2 /* 3 ** Messages for "sp_config_rep_agent" 18373 4 ** 5 ** 17260, "Can't run %1! from within a transaction." 6 ** 17329, "Warning: the configuration property 'multithread rep agent' should be true when the number of paths is greater than 1." 7 ** 17410, "Configuration option doesn't exist." 8 ** 17411, "Configuration option is not unique." 9 ** 17421, "No such database -- run sp_helpdb to list databases." 10 ** 17431 "true" 11 ** 17432 "false" 12 ** 17756, "The execution of the stored procedure '%1!' in database 13 ** '%2!' was aborted because there was an error in writing the 14 ** replication log record." 15 ** 18373, "SQL Server is not currently configured to use Replication Agent threads. Use sp_configure to set this property." 16 ** 18374, "Database '%1!' is not configured to use Replication Agent. Run sp_config_rep_agent without parameters to see a list of databases that use Replication Agent. Use the ENABLE option of sp_config_rep_agent to configure a database to use this feature." 17 ** 18375, "You are not authorized to execute this stored procedure. Only the System Administrator (SA), the Database Owner (DBO) or a user with replication_role authorization can execute this stored procedure." 18 ** 18381, "You must be in the specified database '%1!' to configure its Replication Agent thread." 19 ** 18382, "Database '%1!' is already configured to use Replication Agent. Request to enable Replication Agent has been ignored." 20 ** 18383, "Replication Agent enabled for database '%1!'. The Replication Agent thread needs to be started using sp_start_rep_agent." 21 ** 18384, "Replication Agent disabled for database '%1!'. The secondary truncation point in the database is preserved." 22 ** 18385, "Replication Agent disabled for database '%1!'. The secondary truncation point in the database is no longer active." 23 ** 18423, "Incorrect syntax for sp_config_rep_agent. Usage: sp_config_rep_agent, enable, 36 create procedure sp_config_rep_agent 37 @dbname varchar(30) = NULL, /* database name - optional */ 38 @configname varchar(30) = NULL, /* option to configure */ 39 @configvalue varchar(255) = NULL, /* value */ 40 @rs_username varchar(30) = NULL, /* used only for 'enable' */ 41 @rs_password varchar(30) = NULL, /* used only for 'enable' */ 42 @rs_encpwd varbinary(256) = NULL /* encrypted rs password */ 43 as 44 45 declare @dbid int /* dbid of the database */ 46 declare @dbuid int /* id of the owner of the database */ 47 declare @msg varchar(1024) 48 declare @sptlang int 49 declare @true varchar(10) 50 declare @false varchar(10) 51 declare @procval int 52 declare @type int /* Type of the config. parameter */ 53 declare @hidden int /* whether parameter is hidden */ 54 declare @dynamic int /* whether parameter is dynamic */ 55 declare @attrib_id int /* id of the parameter */ 56 declare @preserve_trunc_pt int /* whether to preserve trunc. pt */ 57 declare @intvalue int /* converted from char parameter */ 58 declare @charvalue varchar(255) /* copy of char parameter */ 59 declare @attrname varchar(30) 60 declare @realoption varchar(30) /* real option - user may type 61 in abbreviation*/ 62 declare @action int 63 declare @oldvalue int 64 declare @tracenum int 65 declare @configcount int 66 declare @class int 67 declare @curdbname varchar(30) 68 declare @has_sa_role int /* User has SA role. */ 69 declare @has_repl_role int /* User has REPLICATION role. */ 70 declare @dbstatus3 int /* Database's status3 */ 71 declare @tempdb_mask int /* Mask indicating this is a 72 ** temporary database */ 73 declare @mrp_class int /* replication path class = 38 */ 74 declare @pp int /* Attribute for physical paths */ 75 declare @num_physical_paths int /* Number of physical paths */ 76 declare @multithread_repagent varchar(5) /* True/false value or config */ 77 declare @total_paths int /* Total number of paths */ 78 declare @stakey int /* for rs password encryption */ 79 80 declare @multithread_warning varchar(250) 81 82 select @class = 11, 83 @stakey = 54 84 85 /* If we're in a transaction, disallow this */ 86 if @@trancount > 0 87 begin 88 /* 89 ** 17260, "Can't run %1! from within a transaction." 90 */ 91 raiserror 17260, "sp_config_rep_agent" 92 return (1) 93 end 94 else 95 begin 96 set chained off 97 end 98 99 set transaction isolation level 1 100 101 /* 102 ** Initialize 'true' and 'false' strings 103 */ 104 /* 17431, "true" */ 105 exec sp_getmessage 17431, @true out 106 /* 17432, "false" */ 107 exec sp_getmessage 17432, @false out 108 109 select @sptlang = @@langid 110 111 if @@langid != 0 112 begin 113 if not exists ( 114 select * from master.dbo.sysmessages where error 115 between 17050 and 17069 116 and langid = @@langid) 117 select @sptlang = 0 118 end 119 120 /* 121 ** Initialize the mask for temporary databases 122 */ 123 select @tempdb_mask = number 124 from master.dbo.spt_values 125 where type = "D3" and name = "TEMPDB STATUS MASK" 126 127 /* Use lower case */ 128 select @configname = lower(@configname) 129 130 if (@dbname is not NULL) 131 begin 132 /* 133 ** Verify the database name and get the @dbid and @dbuid 134 */ 135 select @dbid = dbid, @dbuid = suid, @dbstatus3 = status3 136 from master.dbo.sysdatabases 137 where name = @dbname 138 139 /* 140 ** If @dbname not found, say so and list the databases. 141 */ 142 if @dbid is NULL 143 begin 144 /* 145 ** 17421, "No such database -- run sp_helpdb to list databases." 146 */ 147 raiserror 17421 148 return (1) 149 end 150 151 /* 152 ** Verify that this database is not being shutdown, or the shutdown 153 ** is complete after a HA takeover. 154 ** status3 = 8 : Database is being shutdown 155 ** status3 = 4096 : Shutdown of the database is complete 156 ** or it is a temporary database. 157 */ 158 if (((@dbstatus3 & 8) = 8) or 159 ((@dbstatus3 & 4096) = 4096) or 160 ((@dbstatus3 & @tempdb_mask) != 0)) 161 begin 162 raiserror 18374, @dbname 163 return (1) 164 end 165 166 end 167 168 /* 169 ** Check SA and REPLICATION role. 170 ** Keep their status in local variables for auditing later. 171 */ 172 select @has_sa_role = charindex("sa_role", show_role()) 173 select @has_repl_role = charindex("replication_role", show_role()) 174 175 /* 176 ** Only the Database Owner (DBO) or 177 ** Accounts with SA role or replication role can execute it. 178 ** First check if we are the DBO if the database name is specified. 179 */ 180 if (@dbname is NULL) or (suser_id() != @dbuid) 181 begin 182 /* Check if we have sa_role or replication_role. */ 183 if (@has_sa_role = 0 and @has_repl_role = 0) 184 begin 185 /* 186 ** Audit failure. This will result in three messages, but 187 ** we will live with that until there is a better 'proc_role()' 188 ** interface. 189 */ 190 select @procval = proc_role("sa_role") 191 select @procval = proc_role("replication_role") 192 193 /* 18375, "You are not authorized to execute this stored 194 ** procedure. Only the System Administrator (SA), the 195 ** Database Owner (DBO) or a user with replication_role 196 ** authorization can execute this stored procedure." 197 */ 198 raiserror 18375 199 return (1) 200 end 201 end 202 203 /* Audit success(es) */ 204 if (@has_sa_role > 0) 205 select @procval = proc_role("sa_role") 206 if (@has_repl_role > 0) 207 select @procval = proc_role("replication_role") 208 209 /* 210 ** Create a temporary table with the names of all configuration parameters. 211 ** The first column is the configuration parameter 212 ** The second column is the sysattributes attribute id. For options that 213 ** are not in sysattributes, for example enable,disbale, etc, use -1. 214 ** The third column is the optiontype, which can be 215 ** 0 (not in sysattributes), 216 ** 1 (char), 217 ** 2 (int), 218 ** 3 (boolean). 219 ** The fourth column is true if column is hidden, and false otherwise. 220 ** A hidden column is not displayed. 221 ** The fifth column is true if the variable is dynamic and false 222 ** otherwise. A dynamic variable takes effect immediately. 223 ** There is no relevance between the attribute ids and 224 ** RA_CFG_CFG_XXXX defines in $DBMS/include/rep_priv.h 225 */ 226 create table #rep_ag_options(optionname varchar(30), attrib_id int, 227 optiontype int, hidden int, dynamic int) 228 229 insert into #rep_ag_options values ("enable", - 1, 0, 1, 0) 230 insert into #rep_ag_options values ("disable", - 1, 0, 1, 0) 231 insert into #rep_ag_options values ("rs servername", 0, 1, 0, 0) 232 insert into #rep_ag_options values ("rs username", 1, 1, 0, 0) 233 insert into #rep_ag_options values ("rs password", 2, 1, 1, 0) 234 insert into #rep_ag_options values ("scan batch size", 3, 2, 0, 0) 235 insert into #rep_ag_options values ("scan timeout", 4, 2, 0, 0) 236 insert into #rep_ag_options values ("retry timeout", 5, 2, 0, 0) 237 insert into #rep_ag_options values ("fade timeout", 6, 2, 1, 0) 238 insert into #rep_ag_options values ("skip ltl errors", 7, 3, 0, 0) 239 insert into #rep_ag_options values ("batch ltl", 8, 3, 0, 0) 240 insert into #rep_ag_options values ("send warm standby xacts", 9, 3, 0, 0) 241 insert into #rep_ag_options values ("connect dataserver", 10, 1, 0, 0) 242 insert into #rep_ag_options values ("connect database", 11, 1, 0, 0) 243 insert into #rep_ag_options values ("send maint xacts to replicate", 12, 3, 0, 0) 244 insert into #rep_ag_options values ("traceon", 13, 2, 0, 1) 245 insert into #rep_ag_options values ("traceoff", 13, 2, 0, 1) 246 insert into #rep_ag_options values ("trace log file", 14, 1, 0, 1) 247 insert into #rep_ag_options values ("security mechanism", 15, 1, 0, 0) 248 insert into #rep_ag_options values ("unified login", 16, 3, 0, 0) 249 insert into #rep_ag_options values ("msg confidentiality", 17, 3, 0, 0) 250 insert into #rep_ag_options values ("msg integrity", 18, 3, 0, 0) 251 insert into #rep_ag_options values ("msg replay detection", 19, 3, 0, 0) 252 insert into #rep_ag_options values ("msg origin check", 20, 3, 0, 0) 253 insert into #rep_ag_options values ("msg out-of-sequence check", 21, 3, 0, 0) 254 insert into #rep_ag_options values ("mutual authentication", 22, 3, 0, 0) 255 insert into #rep_ag_options values ("net password encryption", 31, 3, 0, 0) 256 insert into #rep_ag_options values ("skip unsupported features", 23, 3, 0, 0) 257 insert into #rep_ag_options values ("ha failover", - 1, 3, 0, 1) 258 insert into #rep_ag_options values ("short ltl keywords", 24, 3, 0, 0) 259 insert into #rep_ag_options values ("send buffer size", 25, 1, 0, 0) 260 insert into #rep_ag_options values ("priority", 26, 2, 0, 0) 261 insert into #rep_ag_options values ("send structured oqids", 27, 3, 0, 0) 262 insert into #rep_ag_options values ("schema cache growth factor", 28, 2, 0, 0) 263 insert into #rep_ag_options values ("data limits filter mode", 29, 1, 0, 0) 264 insert into #rep_ag_options values ("auto start", - 1, 3, 0, 1) 265 insert into #rep_ag_options values ("startup delay", 30, 2, 0, 0) 266 insert into #rep_ag_options values ("bind to engine", 32, 2, 0, 0) 267 insert into #rep_ag_options values ("ltl batch size", 34, 2, 0, 0) 268 insert into #rep_ag_options values ("multithread rep agent", 36, 3, 0, 0) 269 insert into #rep_ag_options values ("number of send buffers", 37, 2, 0, 1) 270 insert into #rep_ag_options values ("max number replication paths", 38, 2, 0, 0) 271 insert into #rep_ag_options values ("ltl metadata reduction", 39, 3, 0, 0) 272 insert into #rep_ag_options values ("activate monitoring", 40, 3, 0, 1) 273 insert into #rep_ag_options values ("ddl path for unbound objects", 41, 1, 0, 0) 274 275 276 if @configname is not NULL 277 begin 278 /* Verify that the option is valid */ 279 280 select @configcount = count(*) 281 from #rep_ag_options 282 where optionname like "%" + @configname + "%" 283 284 /* If more than one option, show duplicates */ 285 if @configcount > 1 286 begin 287 select "List of Matching Options" = optionname 288 from #rep_ag_options 289 where optionname like "%" + @configname + "%" 290 /* 291 ** 17411, "Configuration option is not unique." 292 */ 293 raiserror 17411 294 return (1) 295 end 296 297 /* Now we know that there is a unique option */ 298 select @type = - 1 299 300 select @realoption = optionname, @attrib_id = attrib_id, 301 @type = optiontype, @hidden = hidden, @dynamic = dynamic 302 from #rep_ag_options 303 where optionname like "%" + @configname + "%" 304 305 /* if no match found */ 306 if @type = - 1 307 begin 308 /* The option specified was incorrect */ 309 select "List of Options" = optionname 310 from #rep_ag_options 311 where optionname != "fade timeout" 312 /* 313 ** 17410, "Configuration option doesn't exist." 314 */ 315 raiserror 17410 316 return (1) 317 end 318 end 319 320 /* Get the name of the sysattributes entry */ 321 if @realoption in ("traceon", "traceoff") 322 begin 323 select @attrname = "trace flags" 324 end 325 else 326 begin 327 select @attrname = @realoption 328 end 329 330 /* Check if Rep Agent threads are enabled for everything except disable */ 331 if (@realoption != "disable") and (is_rep_agent_enabled() = 0) 332 begin 333 /* 18373, "SQL Server is not currently configured to use Replication 334 ** Agent threads. Use sp_configure to set this property." 335 */ 336 raiserror 18373 337 return (1) 338 end 339 340 341 /* 342 ** If the database is not specified, then print out a list of databases 343 ** that use the Rep Agent. 344 */ 345 346 if @dbname is NULL 347 begin 348 349 select "Databases that use Rep Agent" = name 350 from master.dbo.sysdatabases 351 where 1 = case when ((status3 & @tempdb_mask) = 0) 352 then is_rep_agent_enabled(dbid) 353 else 0 354 end 355 and ((status3 & 4096) = 0) 356 and ((status3 & 8) = 0) 357 and dbid != 2 358 359 360 return (0) 361 end 362 363 /* If the database name is specified but no configuration parameter is 364 ** specified then print out the current settings for the database. 365 */ 366 if @realoption is NULL 367 begin 368 if is_rep_agent_enabled(@dbid) = 0 369 begin 370 /* 18374, "Database '%1!' is not configured to use Replication Agent. 371 ** Run sp_config_rep_agent without parameters to see a list of 372 ** databases that use Replication Agent. Use the ENABLE option of 373 ** sp_config_rep_agent to configure a database to use this feature." 374 */ 375 raiserror 18374, @dbname 376 return (1) 377 end 378 379 /* 'select into' the configuration information into a temp table. */ 380 select "Parameter_Name" = optionname, 381 "Default_Value" = rep_agent_config(@dbid, "default config", optionname), 382 "Config_Value" = rep_agent_config(@dbid, "current config", optionname), 383 "Run_Value" = rep_agent_config(@dbid, "config", optionname) 384 into #config_rep_agent_all 385 from #rep_ag_options 386 where hidden = 0 387 and attrib_id != 13 388 389 /* Insert 'trace flags' information into the temp table. */ 390 insert into #config_rep_agent_all values ("trace flags", 391 rep_agent_config(@dbid, "default config", "trace flags"), 392 rep_agent_config(@dbid, "current config", "trace flags"), 393 rep_agent_config(@dbid, "config", "trace flags")) 394 395 /* Output and format the content of the temp table. */ 396 exec sp_autoformat #config_rep_agent_all 397 398 /* drop the temp table */ 399 drop table #config_rep_agent_all 400 401 return (0) 402 end 403 /* If the option is specified, but no value is given, then we print out the 404 ** value unless the option is hidden. 405 */ 406 else if (@configvalue is NULL) and (@rs_username is NULL) 407 and (@rs_password is NULL) and (@hidden = 0) 408 begin 409 /* If the config option was specified, but no value, then we will 410 ** print out the settings for the option. 411 */ 412 413 /* 'select into' the configuration information into a temp table. */ 414 select "Parameter_Name" = @attrname, 415 "Default_Value" = rep_agent_config(@dbid, "default config", @attrname), 416 "Config_Value" = rep_agent_config(@dbid, "current config", @attrname), 417 "Run_Value" = rep_agent_config(@dbid, "config", @attrname) 418 into #config_rep_agent_someone 419 420 /* Output and format the content of the temp table. */ 421 exec sp_autoformat #config_rep_agent_someone 422 423 /* drop the temp table */ 424 drop table #config_rep_agent_someone 425 426 return (0) 427 end 428 429 /* Now, we are here to modify the current settings for the specified database. 430 ** Enforce that the current database is the same as the one specified. 431 */ 432 433 if @dbid != db_id() 434 begin 435 /* 18381, "You must be in the specified database '%1!' to configure 436 ** its Replication Agent thread." 437 */ 438 raiserror 18381, @dbname 439 return (1) 440 end 441 442 443 /* Else, it means that we have found a match with one of the options */ 444 445 if @realoption = "enable" 446 begin 447 /* Check if the database already has the Rep Agent enabled. */ 448 if is_rep_agent_enabled(@dbid) = 1 449 begin 450 /* 18382, "Database '%1!' is already configured to use 451 ** Replication Agent. Request to enable Replication Agent has 452 ** been ignored." 453 */ 454 raiserror 18382, @dbname 455 return (1) 456 end 457 if (@configvalue is NULL 458 or @rs_username is NULL) 459 begin 460 /* 18423, "Incorrect syntax for sp_config_rep_agent. Usage: 461 ** sp_config_rep_agent, , . Replication Agent was not enabled for this database." 24 ** 18424, "Failed to enable Replication Agent for database '%1!'." 25 ** 18426, "Incorrect syntax for sp_config_rep_agent. Usage: sp_config_rep_agent , disable [,'preserve secondary truncpt']. Replication Agent was not disabled for database '%1!'." 26 ** 18427, "Failed to disable Replication Agent for database '%1!'." 27 ** 18428, "Incorrect syntax for sp_config_rep_agent. Usage: sp_config_rep_agent , '%1!', . Replication Agent configuration has not been changed." 28 ** 18429, "Incorrect syntax for sp_config_rep_agent. Usage: sp_config_rep_agent , '%1!', {true| false}. Replication Agent configuration has not been changed." 29 ** 18430, "Replication Agent configuration changed for database '%1!'." 30 ** 18431, "Failed to configure the Replication Agent for database '%1!'." 31 ** 18432, "Replication Agent configuration changed for database '%1!'. The changes will take effect the next time the Replication Agent thread is started." 32 ** 18895, "Illegal send buffer size '%1!' specified, legal send buffer sizes are 2K, 4K, 8K and 16K." 33 ** 18896, "Illegal data limits filter mode '%1!' specified, legal filter modes are off, stop, truncate, and skip." 34 ** 18368, "Illegal ddl path for unbound objects '%1!' specified, legal paths are all, and default." 35 */ , enable, 465 raiserror 18423 466 return (1) 467 end 468 469 if (@rs_encpwd is NULL) 470 begin 471 /* 472 ** The rs password (@rs_password) needs to be 473 ** encrypted. 474 */ 475 select @rs_encpwd = internal_encrypt(@rs_password, @stakey, 0) 476 477 if (@rs_encpwd is NULL) 478 begin 479 /* 480 ** 17067 "Unable to encrypt password for '%1!'. 481 ** See prior error message for reason." 482 */ 483 raiserror 17067, @dbname 484 return (1) 485 end 486 487 select @rs_password = NULL 488 end 489 490 if (rep_agent_admin("enable", @dbid, @configvalue, @rs_username, 491 @rs_encpwd) = 0) 492 begin 493 /* 18424, "Failed to enable Replication Agent for database '%1!'." */ 494 raiserror 18424, @dbname 495 return (1) 496 end 497 498 /* 18383, "Replication Agent enabled for database '%1!'. The 499 ** Replication Agent thread needs to be started using 500 ** sp_start_rep_agent." 501 */ 502 exec sp_getmessage 18383, @msg output 503 print @msg, @dbname 504 return (0) 505 end 506 507 if is_rep_agent_enabled(@dbid) = 0 508 begin 509 /* 18374, "Database '%1!' is not configured to use Replication Agent. 510 ** Run sp_config_rep_agent without parameters to see a list of 511 ** databases that use Replication Agent. Use the ENABLE option of 512 ** sp_config_rep_agent to configure a database to use this feature." 513 */ 514 raiserror 18374, @dbname 515 return (1) 516 end 517 518 if @realoption = "disable" 519 begin 520 if (@configvalue = "preserve secondary truncpt") 521 begin 522 select @preserve_trunc_pt = 1 523 end 524 else if (@configvalue is NULL) 525 begin 526 select @preserve_trunc_pt = 0 527 end 528 else 529 begin 530 /* 18426, "Incorrect syntax for sp_config_rep_agent. Usage: 531 ** sp_config_rep_agent, 462 ** , . Replication Agent was not 463 ** enabled for this database." 464 */ , disable [,'preserve secondary 532 ** truncpt']. Replication Agent was not disabled for database 533 ** '%1!'." 534 */ 535 raiserror 18426, @dbname 536 537 return (1) 538 end 539 540 /* Now go ahead and call the builtin */ 541 if (rep_agent_admin("disable", @dbid, @preserve_trunc_pt) = 0) 542 begin 543 /* 18427, "Failed to disable Replication Agent for 544 ** database '%1!'." 545 */ 546 raiserror 18427, @dbname 547 return (1) 548 end 549 550 if @preserve_trunc_pt = 1 551 begin 552 /* 18384, "Replication Agent disabled for database '%1!'. The 553 ** secondary truncation point in the database is preserved." 554 */ 555 exec sp_getmessage 18384, @msg output 556 print @msg, @dbname 557 return (0) 558 end 559 else 560 begin 561 /* 18385, "Replication Agent disabled for database '%1!'. The 562 ** secondary truncation point in the database is no longer 563 ** active." 564 */ 565 exec sp_getmessage 18385, @msg output 566 print @msg, @dbname 567 return (0) 568 end 569 570 end 571 572 else if @realoption in ("ha failover", "auto start") 573 begin 574 /* 575 ** HA failover takes a boolean arguement, but does not have a row in 576 ** sysattributes. 577 */ 578 select @intvalue = NULL 579 580 /* Verify that value is passed in and other parameters are NULL */ 581 if (@configvalue is NULL 582 or @rs_username is not NULL 583 or @rs_password is not NULL) 584 begin 585 /* 586 ** 18428, "Incorrect syntax for sp_config_rep_agent. Usage: 587 ** sp_config_rep_agent588 ** Agent configuration has not been changed." 589 */ 590 raiserror 18428, @realoption 591 return (1) 592 end 593 if (lower(@configvalue) in ("true", @true)) 594 begin 595 select @intvalue = 1 596 end 597 else if (lower(@configvalue) in ("false", @false)) 598 begin 599 select @intvalue = 0 600 end 601 else 602 begin 603 /* 18429, "Incorrect syntax for sp_config_rep_agent. 604 ** Usage: sp_config_rep_agent605 ** false}. Replication Agent configuration has not 606 ** been changed." 607 */ 608 raiserror 18429, @realoption 609 return (1) 610 end 611 612 /* Now go ahead and call the builtin */ 613 if (rep_agent_admin(@attrname, @dbid, @intvalue) != 0) 614 begin 615 /* 'select into' the configuration information into a temp table. */ 616 select "Parameter_Name" = @attrname, 617 "Default_Value" = rep_agent_config(@dbid, "default config", @attrname), 618 "Config_Value" = rep_agent_config(@dbid, "current config", @attrname), 619 "Run_Value" = rep_agent_config(@dbid, "config", @attrname) 620 into #config_rep_agent_ha 621 622 /* Output and format the content of the temp table. */ 623 exec sp_autoformat #config_rep_agent_ha 624 625 /* drop the temp table */ 626 drop table #config_rep_agent_ha 627 628 end 629 end 630 631 else 632 begin 633 /* Instead of repeating code for ints and chars, use @charvalue 634 ** and @intvalue (only one of them will be non-NULL). 635 */ 636 select @charvalue = NULL 637 select @intvalue = NULL 638 639 /* Verify that value is passed in and other parameters are NULL */ 640 if ((@configvalue is NULL and @rs_encpwd is NULL) 641 or (@configvalue is not NULL and @rs_encpwd is not NULL) 642 or @rs_username is not NULL 643 or @rs_password is not NULL) 644 begin 645 /* 18428, "Incorrect syntax for sp_config_rep_agent. Usage: 646 ** sp_config_rep_agent, '%1!', 649 raiserror 18428, @realoption 650 return (1) 651 end 652 653 /* For booleans */ 654 if @type = 3 655 begin 656 if (lower(@configvalue) in ("true", @true)) 657 begin 658 select @intvalue = 1 659 end 660 else if (lower(@configvalue) in ("false", @false)) 661 begin 662 select @intvalue = 0 663 end 664 else 665 begin 666 /* 18429, "Incorrect syntax for sp_config_rep_agent. 667 ** Usage: sp_config_rep_agent. Replication 647 ** Agent configuration has not been changed." 648 */ , '%1!', {true| 668 ** false}. Replication Agent configuration has not 669 ** been changed." 670 */ 671 raiserror 18429, @realoption 672 return (1) 673 end 674 end 675 else if @type = 2 /* integers */ 676 begin 677 select @intvalue = convert(int, @configvalue) 678 end 679 else /* characters */ 680 begin 681 select @charvalue = @configvalue 682 end 683 684 /* 685 ** Special case check for send buffer size, which only allows 686 ** 2k, 4k, 8k, and 16k as arguments. 687 */ 688 if @realoption = "send buffer size" 689 begin 690 /* Check for legal sizes. */ 691 select @charvalue = lower(@charvalue) 692 if not (@charvalue in ('2k', '4k', '8k', '16k')) 693 begin 694 raiserror 18895, @charvalue 695 return (1) 696 end 697 698 /* 699 ** Convert char value to integer. 700 ** Note that this attribute will have both a charvalue and 701 ** an intvalue. 702 */ 703 select @intvalue 704 = convert(int, substring(@charvalue, 1, 705 charindex('k', @charvalue) - 1)) 706 end 707 708 /* 709 ** Special case check for multithread rep agent false and 710 ** max number replication paths > 1. 711 */ 712 if @realoption = "multithread rep agent" 713 begin 714 /* Check number of replication paths when setting 715 ** multithread rep agent to false. If greater than 1 716 ** warn user. @intvalue = 0 means property is false. 717 */ 718 if (@intvalue = 0) 719 begin 720 /* Get number of physical paths defined for this database. 721 ** attribute = 0 is connection info 722 */ 723 select @mrp_class = 41 724 select @pp = 0 725 select @num_physical_paths = count(*) from sysattributes 726 where class = @mrp_class and attribute = @pp 727 728 /* Add 1 for default path */ 729 select @total_paths = @num_physical_paths + 1 730 731 if (@total_paths > 1) 732 begin 733 exec sp_getmessage 17329, @multithread_warning output 734 print "%1!", @multithread_warning 735 end 736 end 737 end 738 else 739 if @realoption = "max number replication paths" 740 begin 741 /* Check if multithread rep agent is false when setting 742 ** max number replication paths > 1. If multithread rep agent 743 ** is false, warn user. @intvalue is max number replication paths. 744 */ 745 if (@intvalue > 1) 746 begin 747 /* 748 ** Get multithread rep agent config value defined for this database. 749 */ 750 select @multithread_repagent = 751 convert(varchar(5), rep_agent_config(@dbid, "current config", "multithread rep agent")) 752 if @multithread_repagent = "false" 753 begin 754 exec sp_getmessage 17329, @multithread_warning output 755 print "%1!", @multithread_warning 756 end 757 end 758 end 759 else 760 if @realoption = "ddl path for unbound objects" 761 begin 762 /* special syntax check for DDL path of unbound objects */ 763 select @charvalue = lower(@charvalue) 764 if not (@charvalue in ('all', 'default')) 765 begin 766 raiserror 18368, @charvalue 767 return (1) 768 end 769 end 770 else 771 if @realoption = "data limits filter mode" 772 begin 773 /* Special case check for legal filter modes. */ 774 select @charvalue = lower(@charvalue) 775 if not (@charvalue in ('off', 'stop', 'truncate', 'skip')) 776 begin 777 raiserror 18896, @charvalue 778 return (1) 779 end 780 end 781 else 782 if @realoption = "cluster instance name" and 783 lower(@charvalue) = 'coordinator' 784 begin 785 select @charvalue = lower(@charvalue) 786 end 787 788 /* 789 ** Figure out whether or not we need to insert a row or update in 790 ** sysattributes. 791 */ 792 select @oldvalue = int_value 793 from sysattributes where class = @class 794 and attribute = @attrib_id 795 and object_type = "RA" 796 and object_cinfo = @attrname 797 if @@rowcount != 0 798 begin 799 if ((@realoption = 'cluster instance name') and 800 (@charvalue = 'coordinator')) 801 begin 802 select @action = 3 /* ATTR_DROP */ 803 end 804 else 805 begin 806 select @action = 2 /* ATTR_CHANGE */ 807 end 808 end 809 else 810 begin 811 select @action = 1 /* ATTR_ADD */ 812 select @oldvalue = 0 813 end 814 815 /* 816 ** If traceoff is the operation, then there should have been an 817 ** entry in sysattributes. 818 */ 819 if (@realoption = "traceoff" and @action = 1) 820 begin 821 /* 18430, "Replication Agent configuration changed for database '%1!'." */ 822 exec sp_getmessage 18430, @msg output 823 print @msg, @dbname 824 return (0) 825 end 826 827 if (@attrname = "rs password") 828 begin 829 if (@rs_encpwd is NULL) 830 begin 831 /* 832 ** The rs password (@configvalue) needs to be 833 ** encrypted. 834 */ 835 select @rs_encpwd = internal_encrypt(@configvalue, 836 @stakey, 0) 837 838 if (@rs_encpwd is NULL) 839 begin 840 /* 841 ** 17067 "Unable to encrypt password for '%1!'. 842 ** See prior error message for reason." 843 */ 844 raiserror 17067, @dbname 845 return (1) 846 end 847 848 select @configvalue = NULL 849 end 850 851 select @charvalue = @rs_encpwd 852 end 853 854 begin transaction rs_logexec 855 856 if attrib_valid(@class, @attrib_id, 'RA', @dbid, NULL, NULL, NULL, 857 @attrname, @intvalue, @charvalue, NULL, NULL, NULL, @action) = 0 858 begin 859 rollback transaction rs_logexec 860 861 /* 18431, "Failed to configure the 862 ** Replication Agent for database '%1!'." 863 */ 864 raiserror 18431, @dbname 865 return (1) 866 end 867 868 /* If this is for trace flags, figure out what to set */ 869 if @attrname = "trace flags" 870 begin 871 select @tracenum = @intvalue 872 if @realoption = "traceon" 873 begin 874 select @intvalue = @oldvalue | 875 (power(2, (@tracenum - 9200))) 876 end 877 else 878 begin 879 select @intvalue = @oldvalue & 880 (~ power(2, (@tracenum - 9200))) 881 end 882 end 883 884 /* 885 ** For the password, the insert/update in sysattributes 886 ** is done by attrib_notify. 887 ** Beginning with 15.7 the object_info1 field is required for 888 ** all rows. For configuration values manipulated by this proc 889 ** the value will always be 0 for the default path, the MRP 890 ** specific sp_replication_path proc handles non-default rows 891 */ 892 if @attrname != "rs password" 893 begin 894 if (@action = 2) /* ATTR_CHANGE */ 895 begin 896 update sysattributes 897 set char_value = @charvalue, 898 int_value = @intvalue 899 where class = @class 900 and attribute = @attrib_id 901 and object_type = "RA" 902 and object_cinfo = @attrname 903 and object_info1 = 0 904 905 /* 906 ** If there was an error, @@error will be non-zero 907 */ 908 if @@error != 0 909 begin 910 if @@trancount != 0 911 rollback transaction rs_logexec 912 /* 18431, "Failed to configure the 913 ** Replication Agent for database '%1!'." 914 */ 915 raiserror 18431, @dbname 916 return (1) 917 end 918 end 919 else 920 if (@action = 3) /* DROP attribute */ 921 begin 922 delete from sysattributes 923 where class = @class 924 and attribute = @attrib_id 925 and object_type = "RA" 926 and object_cinfo = @attrname 927 and object_info1 = 0 928 end 929 else /* ADD attribute */ 930 begin 931 932 insert into sysattributes(class, attribute, object_type, 933 object, object_cinfo, object_info1, int_value, char_value) 934 values (@class, @attrib_id, "RA", 0, @attrname, 0, 935 @intvalue, @charvalue) 936 937 /* 938 ** If there was an error, @@error will be non-zero 939 */ 940 if @@error != 0 941 begin 942 if @@trancount != 0 943 rollback transaction rs_logexec 944 /* 18431, "Failed to configure the 945 ** Replication Agent for database '%1!'." 946 */ 947 raiserror 18431, @dbname 948 return (1) 949 end 950 end 951 952 end 953 954 /* Notify */ 955 if attrib_notify(@class, @attrib_id, "RA", @dbid, NULL, NULL, NULL, 956 @attrname, @intvalue, @charvalue, NULL, NULL, NULL, @action) = 0 957 /* Unable to notify ? */ 958 begin 959 rollback transaction rs_logexec 960 961 /* 18431, "Failed to configure the 962 ** Replication Agent for database '%1!'." 963 */ 964 raiserror 18431, @dbname 965 return (1) 966 end 967 968 /* 969 ** Write the log record to replicate this invocation 970 ** of the stored procedure. 971 */ 972 if (logexec(@dbid) != 1) 973 begin 974 /* 975 ** 17756, "The execution of the stored procedure '%1!' 976 ** in database '%2!' was aborted because there 977 ** was an error in writing the replication log 978 ** record." 979 */ 980 select @curdbname = db_name() 981 raiserror 17756, "sp_config_rep_agent", @curdbname 982 983 rollback transaction rs_logexec 984 return (1) 985 end 986 987 commit tran 988 /* If the attribute is visible */ 989 if @hidden = 0 990 begin 991 /* 'select into' the configuration information into a temp table. */ 992 select "Parameter_Name" = @attrname, 993 "Default_Value" = rep_agent_config(@dbid, "default config", @attrname), 994 "Config_Value" = rep_agent_config(@dbid, "current config", @attrname), 995 "Run_Value" = rep_agent_config(@dbid, "config", @attrname) 996 into #config_rep_agent_rs 997 998 /* Output and format the content of the temp table. */ 999 exec sp_autoformat #config_rep_agent_rs 1000 1001 /* drop the temp table */ 1002 drop table #config_rep_agent_rs 1003 1004 end 1005 if @dynamic = 0 1006 begin 1007 /* 18432, "Replication Agent configuration changed for database '%1!'. 1008 ** The changes will take effect the next time the Replication Agent 1009 ** thread is started." 1010 */ 1011 exec sp_getmessage 18432, @msg output 1012 print @msg, @dbname 1013 end 1014 else 1015 begin 1016 /* 18430, "Replication Agent configuration changed for database '%1!'." */ 1017 exec sp_getmessage 18430, @msg output 1018 print @msg, @dbname 1019 end 1020 return (0) 1021 1022 end 1023 1024 return (0) 1025
exec sp_procxmode 'sp_config_rep_agent', 'AnyMode' go Grant Execute on sp_config_rep_agent to public go
RESULT SETS | |
sp_config_rep_agent_rset_003 | |
sp_config_rep_agent_rset_002 | |
sp_config_rep_agent_rset_001 |
DEFECTS | |
![]() | 854 |
![]() | 987 |
![]() | master..sysmessages |
![]() | sybsystemprocs..sysattributes |
![]() | 934 |
![]() | 934 |
![]() | 396 |
![]() | 421 |
![]() | 623 |
![]() | 999 |
![]() (number, type) Intersection: {type} | 125 |
![]() | 116 |
![]() | 116 |
![]() | 357 |
![]() | 726 |
![]() | 726 |
![]() | 793 |
![]() | 793 |
![]() | 794 |
![]() | 794 |
![]() | 899 |
![]() | 899 |
![]() | 900 |
![]() | 900 |
![]() | 923 |
![]() | 923 |
![]() | 924 |
![]() | 924 |
![]() | master..spt_values |
![]() | |
![]() | |
![]() | |
![]() | |
![]() | |
![]() | 105 |
![]() | 107 |
![]() | 229 |
![]() | 230 |
![]() | 231 |
![]() | 232 |
![]() | 233 |
![]() | 234 |
![]() | 235 |
![]() | 236 |
![]() | 237 |
![]() | 238 |
![]() | 239 |
![]() | 240 |
![]() | 241 |
![]() | 242 |
![]() | 243 |
![]() | 244 |
![]() | 245 |
![]() | 246 |
![]() | 247 |
![]() | 248 |
![]() | 249 |
![]() | 250 |
![]() | 251 |
![]() | 252 |
![]() | 253 |
![]() | 254 |
![]() | 255 |
![]() | 256 |
![]() | 257 |
![]() | 258 |
![]() | 259 |
![]() | 260 |
![]() | 261 |
![]() | 262 |
![]() | 263 |
![]() | 264 |
![]() | 265 |
![]() | 266 |
![]() | 267 |
![]() | 268 |
![]() | 269 |
![]() | 270 |
![]() | 271 |
![]() | 272 |
![]() | 273 |
![]() | 380 |
![]() | 390 |
![]() | 396 |
![]() | 414 |
![]() | 421 |
![]() | 502 |
![]() | 555 |
![]() | 565 |
![]() | 616 |
![]() | 623 |
![]() | 733 |
![]() | 754 |
![]() | 822 |
![]() | 922 |
![]() | 992 |
![]() | 999 |
![]() | 1011 |
![]() | 1017 |
![]() | 92 |
![]() | 130 |
![]() | 148 |
![]() | 158 |
![]() | 163 |
![]() | 183 |
![]() | 199 |
![]() | 204 |
![]() | 206 |
![]() | 294 |
![]() | 316 |
![]() | 337 |
![]() | 351 |
![]() | 360 |
![]() | 376 |
![]() | 401 |
![]() | 426 |
![]() | 439 |
![]() | 455 |
![]() | 457 |
![]() | 466 |
![]() | 469 |
![]() | 477 |
![]() | 484 |
![]() | 490 |
![]() | 495 |
![]() | 504 |
![]() | 515 |
![]() | 520 |
![]() | 524 |
![]() | 537 |
![]() | 541 |
![]() | 547 |
![]() | 557 |
![]() | 567 |
![]() | 581 |
![]() | 591 |
![]() | 593 |
![]() | 597 |
![]() | 609 |
![]() | 613 |
![]() | 640 |
![]() | 650 |
![]() | 656 |
![]() | 660 |
![]() | 672 |
![]() | 695 |
![]() | 718 |
![]() | 731 |
![]() | 745 |
![]() | 767 |
![]() | 778 |
![]() | 799 |
![]() | 819 |
![]() | 824 |
![]() | 827 |
![]() | 829 |
![]() | 838 |
![]() | 845 |
![]() | 865 |
![]() | 875 |
![]() | 880 |
![]() | 894 |
![]() | 916 |
![]() | 920 |
![]() | 948 |
![]() | 965 |
![]() | 972 |
![]() | 984 |
![]() | 1020 |
![]() | 1024 |
![]() | 226 |
![]() | 123 |
![]() | 300 |
![]() | 792 |
![]() | 287 |
![]() | 309 |
![]() | 349 |
![]() | 380 |
![]() | 414 |
![]() | 616 |
![]() | 992 |
![]() | 99 |
![]() | 932 |
![]() (error, dlevel, langid) Intersection: {error, langid} | 114 |
![]() (class, attribute, object_type, object, object_info1, object_info2, object_info3, object_cinfo) Intersection: {class, attribute} | 726 |
![]() (class, attribute, object_type, object, object_info1, object_info2, object_info3, object_cinfo) Intersection: {object_type, object_cinfo, attribute, class} | 793 |
![]() (class, attribute, object_type, object, object_info1, object_info2, object_info3, object_cinfo) Intersection: {object_info1, object_type, object_cinfo, attribute, class} | 899 |
![]() (class, attribute, object_type, object, object_info1, object_info2, object_info3, object_cinfo) Intersection: {object_info1, object_type, object_cinfo, attribute, class} | 923 |
![]() | 117 |
![]() | 207 |
![]() | 848 |
![]() | 287 |
![]() | 309 |
![]() | 349 |
![]() | 113 |
![]() | 36 |
![]() | 36 |
![]() | 36 |
DEPENDENCIES |
PROCS AND TABLES USED writes table tempdb..#config_rep_agent_someone (1) read_writes table tempdb..#rep_ag_options (1) calls proc sybsystemprocs..sp_getmessage ![]() reads table master..sysmessages (1) ![]() calls proc sybsystemprocs..sp_validlang ![]() reads table master..syslanguages (1) ![]() reads table sybsystemprocs..sysusermessages ![]() reads table master..syslanguages (1) ![]() reads table master..sysmessages (1) ![]() writes table tempdb..#config_rep_agent_all (1) read_writes table sybsystemprocs..sysattributes ![]() reads table master..sysdatabases (1) ![]() writes table tempdb..#config_rep_agent_ha (1) calls proc sybsystemprocs..sp_autoformat ![]() read_writes table tempdb..#colinfo_af (1) calls proc sybsystemprocs..sp_namecrack ![]() reads table tempdb..systypes (1) ![]() calls proc sybsystemprocs..sp_autoformat ![]() reads table master..systypes (1) ![]() reads table master..syscolumns (1) ![]() reads table tempdb..syscolumns (1) ![]() writes table tempdb..#config_rep_agent_rs (1) reads table master..spt_values (1) ![]() |