首頁 > 資料庫 > mysql教程 > 设置SQL的Agent代理的登陆名和密码问题

设置SQL的Agent代理的登陆名和密码问题

WBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWB
發布: 2016-06-07 14:54:43
原創
1644 人瀏覽過

设置SQL的Agent代理的登陆名和密码问题 Agent 登陆名 密码 -- Copyright (C) 1991-2002 SQLDev.Net-- -- file: sp_sqlagent_set_connection.sql-- descr.: Set login and password for regular connections to SQL Agent-- author: Gert E.R. Drapers (GertD@

设置SQL的Agent代理的登陆名和密码问题 Agent 登陆名 密码

1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

18

19

20

21

22

23

24

25

26

27

28

29

30

31

32

33

34

35

36

37

38

39

40

41

42

43

44

45

46

47

48

49

50

51

52

53

54

55

56

57

58

59

60

61

62

63

64

65

66

67

68

69

70

71

72

73

74

75

76

77

78

79

80

81

82

83

84

85

86

87

88

89

90

91

92

93

94

95

96

97

98

99

100

101

102

103

104

105

106

107

108

109

110

111

-- Copyright (C) 1991-2002 SQLDev.Net

--

-- file: sp_sqlagent_set_connection.sql

-- descr.: Set login and password for regular connections to SQL Agent

-- author: Gert E.R. Drapers (GertD@SQLDev.Net)

--

-- @@bof_revsion_marker

-- revision history

-- yyyy/mm/dd  by       description

-- ==========  =======  ==========================================================

-- 2003/03/20  gertd v1.0.0.0 first release

--

-- @@eof_revsion_marker

-- ***************************************************************************

use msdb

go

 

if exists (select * from sysobjects where name = 'sp_sqlagent_set_connection' and type = 'P')

 drop proc dbo.sp_sqlagent_set_connection

go

 

create proc dbo.sp_sqlagent_set_connection @host_login_name sysname, @host_login_password sysname, @regular_connections int = NULL

as

 set nocount on

 

 declare @rc int,

   @os int

 

 -- check if sysadmin role member

 if is_srvrolemember ('sysadmin') <> 1

 begin

  raiserror('Only members of the sysadmin role can execute sp_sqlagent_set_connection', 16, 1)

  return

 end

 

 -- check parameters

 if (@host_login_name is null) or (len(@host_login_name) = 0)

 begin

  raiserror('Illegal parameter value %s is NULL or empty', 16, 1, '@host_login_name')

  return

 end

 

 if (@host_login_password is null) or (len(@host_login_password) = 0)

 begin

  raiserror('Illegal parameter value %s is NULL or empty', 16, 1, '@host_login_password')

  return

 end

  

 -- check if SQL Server 2000, depends on master.dbo.xp_sqlagent_param

 if (charindex(N'8.00', @@version, 0) = 0)

 begin

  raiserror('sp_sqlagent_set_connection is not supported for versions earlier than SQL Server 2000', 18, 1)

  return

 end

 

 -- check OS, master.dbo.xp_sqlagent_param only works on NT

 exec @rc = master.dbo.xp_MSplatform @os output

 if (@os = 2) -- Windows 9x

 begin

  raiserror('sp_sqlagent_set_connection is not supported on Windows 95/98 platforms', 18, 1)

  return

 end

  

 -- only if @regular_connections is turned on we allow setting the connection, otherwise we delete it

 if (@regular_connections is null)

 begin

  exec @rc = master.dbo.xp_instance_regread

   N'HKEY_LOCAL_MACHINE',

   N'SOFTWARE\Microsoft\MSSQLServer\SQLServerAgent',

   N'RegularConnections',

   @regular_connections OUTPUT,

   N'no_output'

 end

 else

 begin

  exec @rc = master.dbo.xp_instance_regwrite

   N'HKEY_LOCAL_MACHINE',

   N'SOFTWARE\Microsoft\MSSQLServer\SQLServerAgent',

            N'RegularConnections',

            N'REG_DWORD',

            @regular_connections

 end

 

 -- delete user id and password

 if (@regular_connections = 0)

 begin

  print N'Delete HostLoginID'

  exec @rc = master.dbo.xp_sqlagent_param 2, N'HostLoginID'

  print N'Delete HostPassword'

  exec @rc = master.dbo.xp_sqlagent_param 2, N'HostPassword'

 end

  

 -- set user id and password

 if (@regular_connections = 1)

 begin

  print N'Set HostLoginID'

  exec @rc = master.dbo.xp_sqlagent_param 1, N'HostLoginID', @host_login_name

  print N'Set HostPassword'

  exec @rc = master.dbo.xp_sqlagent_param 3, N'HostPassword', @host_login_password

 end

go

 

-- sample usage

 

-- regular_connections is already turned on either using SQL Enterprise Manager or

-- exec msdb.dbo.sp_set_sqlagent_properties @regular_connections = 1

-- this sets the login and password

exec msdb.dbo.sp_sqlagent_set_connection N'sa', N'LowRider99'

 

-- this switches to regular connections and set the login and password

exec msdb.dbo.sp_sqlagent_set_connection N'sa', N'LowRider99', 1

登入後複製
本網站聲明
本文內容由網友自願投稿,版權歸原作者所有。本站不承擔相應的法律責任。如發現涉嫌抄襲或侵權的內容,請聯絡admin@php.cn
最新問題
如何配置 bcmath
來自於 1970-01-01 08:00:00
0
0
0
Gitblog在apache上怎麼配置?
來自於 1970-01-01 08:00:00
0
0
0
路由配置不生效
來自於 1970-01-01 08:00:00
0
0
0
熱門教學
更多>
最新下載
更多>
網站特效
網站源碼
網站素材
前端模板