zoukankan      html  css  js  c++  java
  • BCP SQL导出EXCEL常见问题及解决方法;数据导出存储过程

    一、‘xp_cmdshell’的启用

    SQL Server阻止了对组件‘xp_cmdshell’的过程‘sys.xp_cmdshell’的访问。因为此组件已作为此服务嚣安全配置的一部分而被关 闭。系统管理员可以通过使用sp_configure启用‘xp_cmdshell’。有关启用‘xp_cmdshell’的详细信息

    解决方法:

    1、通过SQL语句开启。[推荐此方法,因为在任何版本的SQL SERVER中都可以使用。]
    通过查询分析器,选择Master数据库,然后执行以下SQL内容:
    sp_configure 'show advanced options',1
    reconfigure
    go
    sp_configure 'xp_cmdshell',1
    reconfigure
    go

    2、开始 --> SQL安装目录 --> 配置 SQL server managerment 外围应用配置器-->“功能的外围应用配置器”-->找到“xp_cmdshell”点击启用

    二、SQLState = S0002, NativeError = 208   Error = [Microsoft][SQL Server Native Client 10.0][SQL Server]对象名 'XXX' 无效。

    SQLState = 37000, NativeError = 8180

    Error = [Microsoft][SQL Server Native Client 10.0][SQL Server]无法预定义语句。

    解决方法: 数据表名补全 [库名].[用户名].[表名]

     exec  xp_cmdshell 'bcp " select  * from [库名].[用户名].[表名]" queryout "  路径 "  -T  -c -U   -P  '

    三、SQLState = S1000, NativeError = 0

    Error = [Microsoft][SQL Server Native Client 10.0]无法打开 BCP 主数据文件

    解决方法:检查存储文件路径是否正正确,磁盘是否存在

    四、在执行 sp_xp_cmdshell_proxy_account 的过程中出错。可能原因: 提供的帐户无效或无法创建 '##xp_cmdshell_proxy_account##' 凭据。错误代码: '0'。

    master-->可编程性-->扩展存储过程-->系统扩展存储过程-->xp_cmdshell-->右键 属性-->权限--->添加当前执行用户--》勾选“执行”

    整体解决方法 存储过程

    CARATE  PROCEDURE execname @filename nvarchar(4000),@path nvarchar(2000) 
    AS
    BEGIN
    declare @sql nvarchar(4000)
    set @path=Replace (@path,'','/');  --替换路径符号
    set @filename=Replace (@filename,'from ','from [库名].[用户名].'); --添加数据表全名
    set @sql='bcp "'+@filename+'" queryout "'+@path+'"  -T  -c -U用户名 -P密码' 
     exec  xp_cmdshell @sql
    END
  • 相关阅读:
    MySQL-Front的安装简介
    【翻译】如何通过使用两台电脑变得更加有效率
    Vim学习资源汇总
    21天战拖记——Day1:不算好的开始(2014-05-04)
    课时97.背景定位上(掌握)
    课时96.背景平铺(掌握)
    课时95.背景图片(掌握)
    课时94.背景颜色(掌握)
    课时93.百度首页(理解)
    课时92.CSS元素显示模式转换(掌握)
  • 原文地址:https://www.cnblogs.com/cuozhixu/p/9909310.html
Copyright © 2011-2022 走看看