Tuesday, March 20, 2012

Bulk Insert Problem

Hi to All!
I am trying to use the 'Bulk Insert' command to load a data file into a
MS-SQL db. The line I am using is:
BULK INSERT Data..tbl_load
FROM 'C:\Data\data.txt'
WITH (
DATAFILETYPE = 'char',
FIELDTERMINATOR = '\t',
ROWTERMINATOR = '\n'
)
Sql Server is giving error:
Server: Msg 4861, Level 16, State 1, Line 1
Could not bulk insert because file 'C:\Data\data.txt'
could not be opened. Operating system error code 3(error not found).
What is the problem in script
*** Sent via Developersdex http://www.examnotes.net ***Hi
Can you show us the text's file structure and data?
"Ghulam Farid" <gfaryd@.yahoo.com> wrote in message
news:Or$4xS$HGHA.3460@.TK2MSFTNGP12.phx.gbl...
> Hi to All!
> I am trying to use the 'Bulk Insert' command to load a data file into a
> MS-SQL db. The line I am using is:
> BULK INSERT Data..tbl_load
> FROM 'C:\Data\data.txt'
> WITH (
> DATAFILETYPE = 'char',
> FIELDTERMINATOR = '\t',
> ROWTERMINATOR = '\n'
> )
>
> Sql Server is giving error:
> Server: Msg 4861, Level 16, State 1, Line 1
> Could not bulk insert because file 'C:\Data\data.txt'
> could not be opened. Operating system error code 3(error not found).
> What is the problem in script
>
> *** Sent via Developersdex http://www.examnotes.net ***|||There is only one column in the text file and data type is "char"
sample data is like
ASU0028010180
ASU0038010181
ASU0028010182
ASU0028010183
ASU0028010184
*** Sent via Developersdex http://www.examnotes.net ***|||two things that I can think of:
Does the account that SQL Server runs with has read permissions on that file
?
The contents of the file is not encrypted, right?
"Ghulam Farid" wrote:

> There is only one column in the text file and data type is "char"
> sample data is like
>
> ASU0028010180
> ASU0038010181
> ASU0028010182
> ASU0028010183
> ASU0028010184
>
> *** Sent via Developersdex http://www.examnotes.net ***
>|||I tried to do some testing
create table ww
(
col1 int,
col2 varchar(50),
col3 varchar (50)
)
insert into ww values (47,'ReadyShip','(503)888-999')
insert into ww values (48,'MyShipper','(503)1212-454')
insert into ww values (49,'ReadyShip','(45)888-999')
insert into ww values (50,'MyShipper','(545)1212-454')
xp_cmdshell 'bcp database.dbo.ww out c:\file.fil -c -t, -SSRV -Usa -PRRR'
BULK INSERT ww FROM 'c:\file.fil' WITH (FIELDTERMINATOR = ',')
"Ghulam Farid" <gfaryd@.yahoo.com> wrote in message
news:eMePaj$HGHA.1760@.TK2MSFTNGP10.phx.gbl...
> There is only one column in the text file and data type is "char"
> sample data is like
>
> ASU0028010180
> ASU0038010181
> ASU0028010182
> ASU0028010183
> ASU0028010184
>
> *** Sent via Developersdex http://www.examnotes.net ***|||From the command-prompt, I entered:
NET HELPMSG 3
The result was:
The system cannot find the path specified.
I suggest you check to ensure 'C:\Data\data.txt' exists at the specified
location on the SQL Server. Note that the path is accessed from the server
rather than the client. Of the file resides on the client machine, you'll
need to create a share and assign file/share permissions to the SQL Server
service in order to BULK INSERT from a network location.
Hope this helps.
Dan Guzman
SQL Server MVP
"Ghulam Farid" <gfaryd@.yahoo.com> wrote in message
news:Or$4xS$HGHA.3460@.TK2MSFTNGP12.phx.gbl...
> Hi to All!
> I am trying to use the 'Bulk Insert' command to load a data file into a
> MS-SQL db. The line I am using is:
> BULK INSERT Data..tbl_load
> FROM 'C:\Data\data.txt'
> WITH (
> DATAFILETYPE = 'char',
> FIELDTERMINATOR = '\t',
> ROWTERMINATOR = '\n'
> )
>
> Sql Server is giving error:
> Server: Msg 4861, Level 16, State 1, Line 1
> Could not bulk insert because file 'C:\Data\data.txt'
> could not be opened. Operating system error code 3(error not found).
> What is the problem in script
>
> *** Sent via Developersdex http://www.examnotes.net ***|||Consider that the BULK INSERT.. command processes on the database server, so
the file data.txt would need to exist on the server HD. However, the bulk
copy DOD command (BCP.EXE) processes on the machine that it is executed on.
BCP.EXE is what you would need to use when bulk copying from a local
workstation to SQL Server.
"Ghulam Farid" <gfaryd@.yahoo.com> wrote in message
news:Or$4xS$HGHA.3460@.TK2MSFTNGP12.phx.gbl...
> Hi to All!
> I am trying to use the 'Bulk Insert' command to load a data file into a
> MS-SQL db. The line I am using is:
> BULK INSERT Data..tbl_load
> FROM 'C:\Data\data.txt'
> WITH (
> DATAFILETYPE = 'char',
> FIELDTERMINATOR = '\t',
> ROWTERMINATOR = '\n'
> )
>
> Sql Server is giving error:
> Server: Msg 4861, Level 16, State 1, Line 1
> Could not bulk insert because file 'C:\Data\data.txt'
> could not be opened. Operating system error code 3(error not found).
> What is the problem in script
>
> *** Sent via Developersdex http://www.examnotes.net ***|||Or run the BCP.exe command from the client machine.
"Dan Guzman" <guzmanda@.nospam-online.sbcglobal.net> wrote in message
news:OhbSbGCIGHA.3944@.tk2msftngp13.phx.gbl...
> From the command-prompt, I entered:
> NET HELPMSG 3
> The result was:
> The system cannot find the path specified.
> I suggest you check to ensure 'C:\Data\data.txt' exists at the specified
> location on the SQL Server. Note that the path is accessed from the
> server rather than the client. Of the file resides on the client machine,
> you'll need to create a share and assign file/share permissions to the SQL
> Server service in order to BULK INSERT from a network location.
> --
> Hope this helps.
> Dan Guzman
> SQL Server MVP
> "Ghulam Farid" <gfaryd@.yahoo.com> wrote in message
> news:Or$4xS$HGHA.3460@.TK2MSFTNGP12.phx.gbl...
>

No comments:

Post a Comment