如何编写xp_cmdshell在sql server中创建文本文件? [英] how to write xp_cmdshell to create text file in sql server?
本文介绍了如何编写xp_cmdshell在sql server中创建文本文件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
Iam执行一个查询但给出错误判断..
Iam executing one query but giving error statment..
declare @cmd varchar(1000)
select @cmd = 'osql -U -P -S -Q"select * from master..sysobjects" -o"c:\osqloutput.txt" -w500'
exec master..xp_cmdshell @cmd
错误是这样的
输出
错误:参数-U的使用无效。
NULL
-----------------------------------
一个人尝试
master..xp_cmdshell'bcp sava..select * from tbl_fs_mst out D:\ file.bcp -S -U -P -c'
错误是这样的
error is like this
output
Error: Invalid usage of parameter -U.
NULL
-----------------------------------
one mor iam trying
master..xp_cmdshell 'bcp sava..select * from tbl_fs_mst out D:\file.bcp -S -U -P -c '
error is like this
Copy direction must be either 'in', 'out' or 'format'.
usage: bcp {dbtable | query} {in | out | queryout | format} datafile
[-m maxerrors] [-f formatfile] [-e errfile]
[-F firstrow] [-L lastrow] [-b batchsize]
[-n native type] [-c character type] [-w wide character type]
[-N keep non-text native] [-V file format version] [-q quoted identifier]
[-C code page specifier] [-t field terminator] [-r row terminator]
[-i inputfile] [-o outfile] [-a packetsize]
[-S server name] [-U username] [-P password]
[-T trusted connection] [-v version] [-R regional enable]
[-k keep null values] [-E keep identity values]
[-h "load hints"] [-x generate xml format file]
[-d database name]
NULL
推荐答案
你没有' t在-U
之后提供用户登录(无空格)。
因为你没有提供密码,你也会遇到-P
的问题(也没有空间)。
NB都区分大小写。
然后你会遇到<$ c的问题$ c> -S 因为你还没有提供服务器名称。
注意osql是要从SQL Server中删除的未来的时间 - sqlcmd [ ^ ]现在是推荐的命令行实用程序
You haven't supplied the user login after the-U
(no space).
You will also get a problem with the-P
as you haven't supplied the password (also no space).
NB both are case-sensitive.
You will then get an issue with the-S
as you haven't supplied the server name.
Note that osql is to be removed from SQL Server at some time in the future - sqlcmd[^] is now the recommended command-line utility
这篇关于如何编写xp_cmdshell在sql server中创建文本文件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文