December 2, 2009 at 7:36 am
hi evryone,
i met a problem,
i want to use T-SQL to call BCP.exe to load local txt file into a Table.
in DOS windows it runs ok.
but when i use T-SQL to call it,it donesn't work.
T-SQL command are:
cmdexec and
exec master..xp_cmdshell ' .......'
the local user is sa ,what's wrong with it?
thanks
December 2, 2009 at 7:41 am
First, not really sure. Can you show us the entire command and the full error message you are receiving?
Second, have you looked at using BULK INSERT to accomplish the import?
December 2, 2009 at 7:52 am
exec master..xp_cmdshell 'bcp.exe L_Staging.dbo.DID_Data in "c:test_20091118.txt" -f "bcp_DID.fmt" -S "qa-01" -U "sa" -P "Ssssssss"'
SQLState = 08001, NativeError = 2
Error = [Microsoft][SQL Server Native Client 10.0]Named Pipes Provider: Could not open a connection to SQL Server [2].
SQLState = 08001, NativeError = 2
Error = [Microsoft][SQL Server Native Client 10.0]A network-related or instance-specific error has occurred while establishing a connection to SQL Server. Server is not found or not accessible. Check if instance name is correct and if SQL Server is config
ured to allow remote connections. For more information see SQL Server Books Online.
SQLState = S1T00, NativeError = 0
Error = [Microsoft][SQL Server Native Client 10.0]Login timeout expired
NULL
December 2, 2009 at 1:22 pm
hi there,
I have solved this problem.
1, create a bat file in DOS root,inside content the sentence to run BCP script.
2, create a task Schedule to run the bat file in some special time.
it passed.
thanks everyone.
December 2, 2009 at 6:25 pm
On the other hand, you could do this with BULK INSERT through T-SQL without ever going near xp_CmdShell.
--Jeff Moden
Change is inevitable... Change for the better is not.
December 2, 2009 at 10:11 pm
thanks Jeff,
I must use that, because it is a part of promotion of OLD system to new system in our company.
i have to use those old code, the change less the better.
or that mean big project waiting.
thanks.
December 3, 2009 at 8:14 am
The other neat part BULK INSERT is that you can use a "trusted connection"... no need for a user name or password in clear code. Post back if you run into problems.
--Jeff Moden
Change is inevitable... Change for the better is not.
Viewing 7 posts - 1 through 6 (of 6 total)
You must be logged in to reply to this topic. Login to reply