File does not exist error
From: singth_my (singth_my_at_discussions.microsoft.com)
Date: 01/24/05
- Next message: Aaron [SQL Server MVP]: "Re: File does not exist error"
- Previous message: Aaron [SQL Server MVP]: "Re: Extended Stored Procedure"
- Next in thread: Aaron [SQL Server MVP]: "Re: File does not exist error"
- Reply: Aaron [SQL Server MVP]: "Re: File does not exist error"
- Reply: Anith Sen: "Re: File does not exist error"
- Messages sorted by: [ date ] [ thread ]
Date: Sun, 23 Jan 2005 20:17:01 -0800
I have this sql statement:
use Northwind
set @in_table = 'ship_test'
set @in_data_file = 'C:\data.txt'
Set @in_format_file = 'C:\data.fmt'
DECLARE @SQL_STRING AS [nvarchar](4000)
SET @SQL_STRING =
'BULK INSERT ' + @in_table + '
FROM ''@data_file''
WITH (
FORMATFILE=''@format_file'',
CHECK_CONSTRAINTS
)'
EXEC sp_ExecuteSql
@SQL_STRING,
N'@data_file nvarchar(200), @format_file nvarchar(200)', @in_data_file,
@in_format_file
When execute, it gives
"Server: Msg 4860, Level 16, State 1, Line 1
Could not bulk insert. File '@data_file' does not exist."
But if I use the following:
BULK INSERT ship_test
FROM 'C:\data.txt'
WITH
(
FORMATFILE='c:\data.fmt',
CHECK_CONSTRAINTS
)
The query will execute successfully.
Even if I change the first query to the following:
use Northwind
set @in_table = 'ship_test'
set @in_data_file = 'C:\data.txt'
Set @in_format_file = 'C:\data.fmt'
DECLARE @SQL_STRING AS [nvarchar](4000)
SET @SQL_STRING =
'BULK INSERT ' + @in_table + '
FROM ''' + @in_data_file + '''
WITH (FORMATFILE=''' + @in_format_file + ''',
CHECK_CONSTRAINTS)'
EXEC sp_ExecuteSql @SQL_STRING
The query will run successfully.
Anyone have any idea ? Is this one of the limitation of using "bulk insert"
and "sp_executesql" together ?
- Next message: Aaron [SQL Server MVP]: "Re: File does not exist error"
- Previous message: Aaron [SQL Server MVP]: "Re: Extended Stored Procedure"
- Next in thread: Aaron [SQL Server MVP]: "Re: File does not exist error"
- Reply: Aaron [SQL Server MVP]: "Re: File does not exist error"
- Reply: Anith Sen: "Re: File does not exist error"
- Messages sorted by: [ date ] [ thread ]
Relevant Pages
|