November 19, 2008 at 2:55 am
how to run this query in window authentication mode can any one give the suggestion
EXEC master..xp_cmdshell 'bcp "SELECT * FROM [company]" queryout d:\mushi.txt"" -U --- -P -- -c -t
November 24, 2008 at 6:59 am
bcp /?
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]
-T will use windows authentication (aka trusted connection)
November 24, 2008 at 8:33 am
or use SQLCMD with the -E flag?
http://msdn.microsoft.com/en-us/library/ms162773.aspx
sqlcmd
[{ { -U login_id [ -P password ] } | –E trusted connection }]
[ -z new password ] [ -Z new password and exit]
[ -S server_name [ \ instance_name ] ] [ -H wksta_name ] [ -d db_name ]
[ -l login time_out ] [ -A dedicated admin connection ]
[ -i input_file ] [ -o output_file ]
[ -f ] ]
[ -u unicode output ] [ -r [ 0 | 1 ] msgs to stderr ]
[ -R use client regional settings ]
[ -q "cmdline query" ] [ -Q "cmdline query" and exit ]
[ -e echo input ] [ -t query time_out ]
[ -I enable Quoted Identifiers ]
[ -v var = "value"...] [ -x disable variable substitution ]
[ -h headers ][ -s col_separator ] [ -w column_width ]
[ -W remove trailing spaces ]
[ -k [ 1 | 2 ] remove[replace] control characters ]
[ -y display_width ] [-Y display_width ]
[ -b on error batch abort ] [ -V severitylevel ] [ -m error_level ]
[ -a packet_size ][ -c cmd_end ]
[ -L [ c ] list servers[clean output] ]
[ -p [ 1 ] print statistics[colon format]]
[ -X [ 1 ] ] disable commands, startup script, enviroment variables [and exit]
[ -? show syntax summary ]
November 25, 2008 at 4:46 am
If you cannot get your query to work, try the following troubleshooting:
1) You are running a Windows command - bcp - so try running this outside SQL Server. If the command syntax is wrong, it is often easier to get diagnostic information when you run in a Command window than when you run in SQL Server.
2) When you know you have working syntax, try it in SQL Server using an account with sysadmin authority, and look at any SQL Server diagnostics. When you can get the command to work with a sysadmin account you then know you have a process that can work.
3) If you want to run the command using a non-sysadmimn account, log on using that account and try the command. Again look at the SQL Server diagnostics and fix any issues.
The use of xp_cmdshell within SQL Server 2005 or above requires some configuration. The full details are in Books Online (BOL), so I will just give an outline here.
a) Enable xp_cmdshell option within SQL Server.
b) If an account that is not sysadmin is to use xp_cmdshell, you must configure the xp_cmdshell proxy. A single xp_cmdshell proxy is used for allnon-sysadmin use of xp_cmdshell on the SQL instance, and any Windows file permisions that may be needed must be granted to the proxy account.
c) You must grant execute rights to xp_cmdshell for any account that uses it.
The xp_cmdshell proxy account must have Windows execute rights on any program folder containing the commands you execute. Often the proxy account will not have this right on the program folder containging the bcp command, so this right must be granted in Windows. For some sites you may also need to grant execute rigts to cmd.exe in the Windows \system32 folder.
Original author: https://github.com/SQL-FineBuild/Common/wiki/ 1-click install and best practice configuration of SQL Server 2019, 2017 2016, 2014, 2012, 2008 R2, 2008 and 2005.
When I give food to the poor they call me a saint. When I ask why they are poor they call me a communist - Archbishop Hélder Câmara
Viewing 4 posts - 1 through 3 (of 3 total)
You must be logged in to reply to this topic. Login to reply