Click here to monitor SSC
SQLServerCentral is supported by Red Gate Software Ltd.
 
Log in  ::  Register  ::  Not logged in
 
 
 
        
Home       Members    Calendar    Who's On


Add to briefcase

how to run this query in window authentication mode Expand / Collapse
Author
Message
Posted Wednesday, November 19, 2008 2:55 AM
Forum Newbie

Forum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum Newbie

Group: General Forum Members
Last Login: Friday, August 23, 2013 10:45 AM
Points: 6, Visits: 72
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
Post #604973
Posted Monday, November 24, 2008 6:59 AM
SSC Journeyman

SSC JourneymanSSC JourneymanSSC JourneymanSSC JourneymanSSC JourneymanSSC JourneymanSSC JourneymanSSC Journeyman

Group: General Forum Members
Last Login: Monday, March 17, 2014 4:32 PM
Points: 91, Visits: 351
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)
Post #607502
Posted Monday, November 24, 2008 8:33 AM


Right there with Babe

Right there with BabeRight there with BabeRight there with BabeRight there with BabeRight there with BabeRight there with BabeRight there with BabeRight there with Babe

Group: General Forum Members
Last Login: Tuesday, December 2, 2014 8:26 AM
Points: 775, Visits: 1,203
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 ]


SQLServerNewbie

MCITP: Database Administrator SQL Server 2005
Post #607596
Posted Tuesday, November 25, 2008 4:46 AM
SSCrazy

SSCrazySSCrazySSCrazySSCrazySSCrazySSCrazySSCrazySSCrazy

Group: General Forum Members
Last Login: 2 days ago @ 6:03 AM
Points: 2,900, Visits: 3,301
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: SQL Server FineBuild 1-click install and best practice configuration of SQL Server 2014, 2012, 2008 R2, 2008 and 2005. 18 October 2014: now over 31,000 downloads.
Disclaimer: All information provided is a personal opinion that may not match reality.
Concept: "Pizza Apartheid" - the discrimination that separates those who earn enough in one day to buy a pizza if they want one, from those who can not.
Post #608219
« Prev Topic | Next Topic »

Add to briefcase

Permissions Expand / Collapse