June 14, 2012 at 3:42 pm
I am using this BCP command to output the data from a table into the file, and getting this error message:
SQLState = 28000, NativeError = 18456
Error = [Microsoft][SQL Server Native Client 10.0][SQL Server]Login failed for user 'domain\username'.
Here's the command I have:
bcp "SELECT * FROM database.dbo.TableName" queryout \\sharedlocation\Test\File.DAT -S"SERVERNAME" -U"domain\username" -P"password" -o"\\sharedlocation\Test\Log.txt"
I do not want to have -T (trusted connection) rather want to have SQL authentication. Am I missing anything in the command? Please help!!
June 14, 2012 at 3:57 pm
How is the ID set up in SQL Server? Is it set up to be a windows authenticated id? If so, putting the network name and the password on the command line isn't going to work. You'll either have to use a trusted connection or set up a separate ID with SQL Server Authentication.
June 14, 2012 at 4:38 pm
Thanks, that worked!
June 14, 2012 at 4:39 pm
It looks like you are passing a domain\windows_acct to what is supposed to be a sql_login
April 29, 2014 at 5:46 am
Hi,
I use this BCP command in a SP and get the same user login error.
I use widows Auth when connecting but have tried SQL server auth as well with the same error.
SP Part is as follows:
...
begin
set @cmd = 'bcp.exe ' +
@dbName + '..' + @tbName + ' in ' +
@filePath + ' -c -U ' + @usr +
' -P ' + @pwd + ' -t ' + @sep
print @cmd --+ '...'
exec xp_cmdShell @cmd
end
and my call to this would be...
Exec uSp_Import_Table 'SampleDB',
'INV_StageTable',
'c:\Test\Aut_2014-04-22.csv',
',',
'MyUserName',
'MyPassword'
and still get the same error.
any ideas?
April 29, 2014 at 6:10 am
you cannot pass a windows username and password. it's just not allowed.
you can pass a SQL username and password, or use the -T for trusted connection, which uses the windows account the SQL instance starts with in services... which may or may not have access to the path for the file in question.
Lowell
April 29, 2014 at 6:14 am
you'd probably be much better off using BULK INSERT over bcp + xp_cmdshell anyway:
--in via bulk insert
BULK INSERT INV_StageTable FROM 'c:\Test\Aut_2014-04-22.csv'
WITH (
DATAFILETYPE = 'char',
FIELDTERMINATOR = ',',
ROWTERMINATOR = '\n',
FIRSTROW = 1
)
Lowell
April 30, 2014 at 12:40 am
Hi,
Thanks Lowell, I'll give that approach a go.
I think i did try it but it was forever complaining about a type mismatch or invalid character.
i think its because the file is originally in Excel Format and saved as a .CSV before dropped into a server directory where a SP finds it
and in that process the DateTime gets saved as 123456.654321 value but i'll have another look.
Thanks a mil.
if i dont come right ill get a shout
Nevarda
Viewing 8 posts - 1 through 7 (of 7 total)
You must be logged in to reply to this topic. Login to reply