sqlserver 将存储过程分别导出为文件:
DECLARE @s VARCHAR(4000),@n INT,@i INT,@s1 VARCHAR(100) SELECT IDENTITY(INT) id,text INTO ## FROM syscomments SELECT @n=@@ROWCOUNT,@i=0 WHILE @i<@n BEGIN SELECT @i=@i+1,@s='' SELECT @s1=REPLACE(REPLACE(RTRIM(LTRIM(STUFF(STUFF(text,CHARINDEX('AS',text),40000,''),1,CHARINDEX('PROC',STUFF(text,''))+4,''))),CHAR(10),CHAR(13),'') FROM ## WHERE ID=RTRIM(@i) --SELECT @s1,ASCII(SUBSTRING(@s1,3,1)) --SELECT LEN(REPLACE(REPLACE(@s1,'')) SELECT @s='SELECT text FROM tempdb.dbo.## WHERE ID=' + RTRIM(@i) EXEC('EXEC master..xp_cmdshell ''bcp "' + @s + ' " queryout "e:\ProcTXT\' + @s1 + '.txt" -S"ROBINHOME\sqlEXPRESS" -c -U"sa" -P"bd5178"''') END DROP TABLE ##
BCP常见问题集:
1.错误:Error = [Microsoft][sql Native Client]Unable to open BCP host data-file.
2.错误:Error = [Microsoft][sql Native Client]String data,right truncation
原因:字符串长度过长
解决方案:检查数据长度是否超过表格设置,或者是否有正确的行结束标志。
3.错误:在sql SERVER 2005 调用“sys.xp_cmdshell”过程对过期备份文件进行删除出现如下出错提示:
-----------------------------
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.
-----------------------------
sql server 2005的默认安全策略关闭了用户对“sys.xp_cmdshell”的访问权限,用如下语句开启:
-----------------------------
sp_configure 'show advanced options',1 GO RECONfigURE GO sp_configure 'xp_cmdshell',1 GO RECONfigURE GO
------------------------------
另外,当你准备在sql SERVER 2005中调用操作系统内置的smtp组件发送邮件时,可能也会收到如下错误提示:
--------------------------------
“sql Server 阻止了对组件 'Ole Automation Procedures' 的 过程'sys.sp_OACreate' 的访问,因为此组件已作为此服务器安全配置的一部分而被关闭”
--------------------------------
同样道理,用如下语句开启Ole Automation Procedures的访问权限:
--------------------------------
sp_configure 'show advanced options',1 GO RECONfigURE GO sp_configure 'Ole Automation Procedures' GO RECONfigURE GO
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 [email protected] 举报,一经查实,本站将立刻删除。