views:

16

answers:

1

I have tried many things, but I'm still not getting this to work. Here's the code:

bcp RFID.dbo.ResultsDump format nul -t, -c -x -f C:\RFID.xml -S"ALBERTLAST-PC\SQLEXPRESS" -UAlbert Last -P -T

All I want to do is create an XML format file from ResultsDump table, and the above statement doesn't even work. My username is "Albert Last" where Last is my last name, yet this is what the above statement returns:

bcp:  unknown option A
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]
NULL

It's thinking that I am asking for option A, because when I put square brackets around Albert Last, here's what I get:

bcp:  unknown option [

I've also tried this WITHOUT specifying server name, username, or password, with just -T. This is what I get:

SQLState = 37000, NativeError = 4060
Error = [Microsoft][SQL Native Client][SQL Server]Cannot open database "RFID" requested by the login. The login failed.
SQLState = 28000, NativeError = 18456
Error = [Microsoft][SQL Native Client][SQL Server]Login failed for user 'NT AUTHORITY\NETWORK SERVICE'.
NULL

I've looked everywhere online and have not seen a similar problem before, and I'm beginning to think that this is just a simple mistake that I'm not catching.

Can somebody help?? Or if there is a way to generate format xml file RFID.xml from table ResultsDump without bcp, that would be greatly appreciated! Thanks in advance!

+1  A: 

Can you try if the following works:

-U"Albert Last"

I can vaguely remember that I have done it this way a long time ago.

The error you see in your comment has something to do with your format file (c:\RFID.xml), not with your username. Possibly you do not have write access to c:\? Can you try it with a relative path, just RFID.xml? And make sure you then run the bcp command from a location where you have write access.

Ronald Wildenberg
Tried that before, but now it doesn't think I specified the correct username: SQLState = S1000, NativeError = 0Error = [Microsoft][SQL Native Client]Format file could not be opened. Invalid name specified or access denied.NULLUnless I'm interpreting the output incorrectly?
Think Blue Crew
I updated my answer with some additional info.
Ronald Wildenberg
Doesnt -T already give me access? In either case, I tried RFID.xml instead of c:\RFID.xml and I get the same error (Invalid name specified or access denied). How do I know if I have write access to the folder I am running the SQL statements out of? Sorry about all the questions, and thanks for your patience.
Think Blue Crew
You should either specify -T or -U and -P, not both. -T tells bcp that you are using a trusted connection. This means nothing more than that it will connect to SQL Server using the credentials of the user running bcp. From what folder are you running bcp?
Ronald Wildenberg