用户 NT 权限/匿名登录的 BCP 导出登录失败 [英] BCP Export Login Failed for User NT Authority/Anonymous Logon

查看:33
本文介绍了用户 NT 权限/匿名登录的 BCP 导出登录失败的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

SQL Server 在线,我正在尝试将数据导出到远程服务器.我正在使用 Windows 身份验证登录 sql server.

SQL Server is online and I'm trying to export data to a remote server. I'm using Windows Authentication to log on sql server.

代码:

declare @sql1 varchar(8000), @asofdate varchar(50)

set @asofdate = convert(varchar,getdate()-1,112) + '.csv'

select @sql1 = 'bcp DB1.dbo.Table1 out C:\exp\test' + @asofdate  + ' -c -t, -T -S'+ '.\SQL2005'
exec master.. xp_cmdshell @sql1

但我收到错误

[Microsoft][ODBC SQL Server 驱动程序][SQL Server]用户NT AUTHORITY\ANONYMOUS LOGON"登录失败.

[Microsoft][ODBC SQL Server Driver][SQL Server]Login failed for user 'NT AUTHORITY\ANONYMOUS LOGON'.

如果我尝试

exec xp_cmdshell 'del C:\exp\*.csv'

代码运行良好.所以我想我确实可以访问 xp_cmdshell.

The code works fine. So I think I do have access to xp_cmdshell.

那我想知道为什么我的 xp_cmdshell 不能用于 bcp 导出?

Then I wonder why my xp_cmdshell doesn't work for bcp export?

感谢您的建议!

推荐答案

您正在将命令传递给外部应用程序.

You're passing off a command to an external application.

此外部应用程序并不真正了解您,也不了解您的命令来自何处.因此,ANONYMOUS LOGON 消息.

This external application doesn't really know you, or where your command came from. Hence the ANONYMOUS LOGON message.

您需要告诉命令以谁的身份执行.看看 BoL 中的 BCP (http://msdn.microsoft.com/en-us/library/ms162802.aspx),您会发现一些您可能希望添加的参数:

You need to tell the command who to execute as. Have a look at BCP in BoL (http://msdn.microsoft.com/en-us/library/ms162802.aspx) and you'll spot a few parameters that you might wish to add:

-T指定 bcp 实用程序使用集成安全性通过可信连接连接到 SQL Server.不需要网络用户的安全凭证、login_id 和密码.如果不指定-T,则需要指定-U和-P才能成功登录.

-U login_id指定用于连接到 SQL Server 的登录 ID.

-P 密码指定登录 ID 的密码.如果未使用此选项,bcp 命令会提示输入密码.如果在没有密码的命令提示符末尾使用此选项,bcp 将使用默认密码 (NULL).

这篇关于用户 NT 权限/匿名登录的 BCP 导出登录失败的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆