从SQL Server里导出存储过程和用户自定义函数

exec master..xp_cmdshell
'bcp "Select routine_definition from OnlyVC.information_Schema.routines order by routine_name" queryout "d:\1.sql" -c –T'

加粗部分为db的name

执行前要注意2个地方:

1.先执行

EXEC sp_configure 'show advanced options', 1
RECONFIGURE WITH OVERRIDE
EXEC sp_configure 'xp_cmdshell', 1
RECONFIGURE WITH OVERRIDE
EXEC sp_configure  'show advanced options', 0

否则会遇到下面的错误:

Msg 15281, Level 16, State 1, Procedure xp_cmdshell, Line 1
SQL Server blocked access to procedure 'sys.xp_cmdshell' of component 'xp_cmdshell' because this component is turned off as part of the security configuration for this server. A system administrator can enable the use of 'xp_cmdshell' by using sp_configure. For more information about enabling 'xp_cmdshell', see "Surface Area Configuration" in SQL Server Books Online.

2.添加-T参数:

否则会遇到下面的错误:

err1

User name not provided, either use -U to provide the user name or use -T for Trusted Connection

posted @ 2008-08-03 16:12  new 维生素C.net()  阅读(1490)  评论(0编辑  收藏  举报