Less probable but also possible, please check the language and regional settings of the windows servers running the sql instances.
using bcp to copy between servers gives SQLState 22008
Question
I'm trying to copy data from one database to another (on different servers) whose tables have identical schema, every time I run the below query I get an error saying the following...
"SQLState = 22008 NativeError = 0 Error = [Microsoft][SQL Server Native Client 10.0]Invalid date format"
The query is this...
EXEC sp_configure 'show advanced options', 1
GO
RECONFIGURE
GO
EXEC sp_configure 'xp_cmdshell', 1
GO
RECONFIGURE
GO
DECLARE @MasterServerName varchar(40)
DECLARE @MasterServerUserName varchar(20)
DECLARE @MasterServerPassword varchar(20)
DECLARE @SlaveServerName varchar(40)
DECLARE @SlaveServerUserName varchar(20)
DECLARE @SlaveServerPassword varchar(20)
DECLARE @ExportFile varchar (40)
DECLARE @ExportFile1 varchar (40)
DECLARE @ExportFile2 varchar (40)
DECLARE @ExportFile3 varchar (40)
DECLARE @ExportFile4 varchar (40)
SET @MasterServerName='{SQL_Server_Name}'
SET @MasterServerUserName='{SQL_USER_LOGIN}'
SET @MasterServerPassword='{SQL_USER_PASSWORD}'
SET @SlaveServerName='{SLAVE_NAME}\{SLAVE_INSTANCE}'
SET @SlaveServerUserName='{SLAVE_USER_LOGIN}'
SET @SlaveServerPassword='{SLAVE_USER_PASSWORD}'
-------------------------------------
SET @ExportFile1='C:\ExportTracking1.txt'
SET @ExportFile2='C:\ExportTracking2.txt'
SET @ExportFile3='C:\ExportTracking3.txt'
SET @ExportFile4='C:\ExportTracking4.txt'
DECLARE @BCP varchar(8000)
----------------------------------------------
--Collecting tracking data from the slave server
-----------------------------------------------
SET @BCP =
'bcp "select * FROM <DATABASE_NAME>.dbo.<TABLE_NAME> where ExportID="9999999"" queryoutout '+@ExportFile1+' -c -U'+@SlaveServerUserName+' -P'+@SlaveServerPassword+' -S'+@SlaveServerName+' -C{850}'
PRINT @BCP
EXEC xp_CMDshell @BCP
-----------------------------------------------
--Adding tracking data to the master server
-----------------------------------------------
SET @BCP =
'bcp <DATABASE_NAME>.dbo.<TABLE_NAME> in '+@ExportFile1+' -e C:\error1.txt -c -U'+@MasterServerUserName+' -P'+@MasterServerPassword+' -S'+@MasterServerName+' -C{850}'
PRINT @BCP
EXEC xp_CMDshell @BCP
-----------------------------------------------
EXEC sp_configure 'xp_cmdshell', 0
GO
RECONFIGURE
GO
EXEC sp_configure 'show advanced options', 0
GO
RECONFIGURE
GO
Can anyone please help shed some light on why this error is occurring?
Any input would be greatly appreciated.
Thanks
Lee
Solution
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow