先执行一下试试sp_xp_cmdshell_proxy_account 'sa','sa'

解决方案 »

  1.   

    Declare @r Varchar
    set nocount on
    exec @r=master..xp_cmdshell 'sqlcmd -S 192.168.1.1 -U sa -P sa',no_output
    if @r='0'
    print '正常'
    else
    print '异常'把p改成大写试试
      

  2.   

    执行过程中出错,可能原因:提供的账户无效或无法创建‘##xp_cmdshell_proxy_account##’
      

  3.   

    刚才我用你的语句替换我的ip试了,改成P就可以了
      

  4.   

    那改了大写还是不行?你用SSMS,用192.168.1.1作为实例名,sa登录试试能否成功
      

  5.   

    Declare @Vs_sql Varchar(8000),
    @Userip Varchar(30),
    @s Varchar(1000),
    @Ip Varchar(30),
    @Result Varchar
    Declare cur1 cursor
    for Select PosIp from openrowset('SQLOLEDB','192.168.8.50';'sa';'sa'),SQLDB_USER.dbo.table)
    open cur1
    select @Userip=count(*) from openrowset('SQLOLEDB','192.168.8.50';'sa';'sa'),SQLDB_USER.dbo.table)
    while @@FETCH_STATUS=0 and @Userip>1
    begin
    fetch next from cur1 into @Ip
    set @Userip=@Ip-1
    print @Ip
    set @s='''sqlcmd -S '+@Ip+' -U sa -P sa'''
    print (@s)
    set oncount on
    exec @Result=master..xp_cmdshell @Ip, on_output
    if @Result='0'
    print '正常'
    else
    print '异常'
    这样子,执行完显示的所有IP都是异常。
      

  6.   


    中间打错了,应该是exec @Result=master..xp_cmdshell @s, on_output
      

  7.   


    Declare @Vs_sql Varchar(8000),
    @Userip Varchar(30),
    @s Varchar(1000),
    @Ip Varchar(30),
    @Result Varchar
    Declare cur1 cursor
    for Select PosIp from openrowset('SQLOLEDB','192.168.8.50';'sa';'sa'),SQLDB_USER.dbo.table)
    open cur1
    select @Userip=count(*) from openrowset('SQLOLEDB','192.168.8.50';'sa';'sa'),SQLDB_USER.dbo.table)
    while @@FETCH_STATUS=0 and @Userip>1
    begin
    fetch next from cur1 into @Ip
    set @Userip=@Ip-1
    print @Ip
    set @s='''sqlcmd -S '+@Ip+' -U sa -P sa'''
    print (@s)
    set oncount on
    exec @Result=master..xp_cmdshell @s, on_output
    if @Result='0'
    print '正常'
    else
    print '异常'
    这样子,执行完显示的所有IP都是异常。
      

  8.   

    set @s='sqlcmd -S '+@Ip+' -U sa -P sa'这里先改成这样
      

  9.   

    你改成这样试试,我本机测了一下可以的Declare @Vs_sql Varchar(8000),
    @Userip Varchar(30),
    @s Varchar(1000),
    @Ip Varchar(30),
    @Result Varchar(1)
    set @s='sqlcmd -S '+@Ip+' -U sa -P sa'
    print (@s)
    set nocount onEXEC @result= master..xp_cmdshell @s
    if @Result='0'
    print '正常'
    else
    print '异常'
      

  10.   

    exec @Result=master..xp_cmdshell @Ip, on_output这里的on_output是什么意思,这个可以去掉,改成这样试试:exec @Result=master..xp_cmdshell @Ip
      

  11.   

    no_output
    Is an optional parameter, specifying that no output should be returned to the client. 
    If the no_output option is used, only the following will be returned: The command(s) completed successfully.
    没必要用这个选项