Please start any new threads on our new
site at https://forums.sqlteam.com. We've got lots of great SQL Server
experts to answer whatever question you can come up with.
| Author |
Topic |
|
k006b
Starting Member
10 Posts |
Posted - 2005-01-21 : 15:24:06
|
| Dear All,I am importing all the files from a particular folder to a table on my database KB. It is working perfectly if i use it on the same system where the DB exists and not working from the network.USE TESTDB--Table Creation Starts hereCreate table Account([ID] int IDENTITY PRIMARY KEY, Name Varchar(100), AccountNo varchar(100), Balance money)Create table logtable (id int identity(1,1), Query varchar(1000), Importeddate datetime default getdate())--Table Creation ends here---Stored Procedure Starts hereCreate procedure usp_ImportMultipleFiles @filepath varchar(500), @pattern varchar(100), @TableName varchar(128)asset quoted_identifier offdeclare @query varchar(1000)declare @max1 intdeclare @count1 intDeclare @filename varchar(100)set @count1 =0create table #x (name varchar(200))set @query ='master.dbo.xp_cmdshell "dir '+@filepath+@pattern +' /b"'insert #x exec (@query)delete from #x where name is NULLselect identity(int,1,1) as ID, name into #y from #x drop table #xset @max1 = (select max(ID) from #y)--print @max1--print @count1While @count1 <= @max1beginset @count1=@count1+1set @filename = (select name from #y where [id] = @count1)set @query ='BULK INSERT '+ @Tablename + ' FROM "'+ @Filepath+@Filename+'" WITH ( FIELDTERMINATOR = ",",ROWTERMINATOR = "\n")'--print @queryexec (@query)insert into logtable (query) select @queryenddrop table #y--sp ends hereExec usp_ImportMultipleFiles 'c:\myimport\', '*.csv', 'Account'If i use the above Exec likeExec usp_ImportMultipleFiles '\\kb-02\C$\MyImport\', '*.csv', 'Account'I am getting the following error:Could not bulk insert because file '\\kb-02\C$\MyImport\Access is denied.' could not be opened. Operating system error code 5(Access is denied.).C Drive and MyImport folder is shared on system kb-02Would appreciate your valuable HELP.thanking your valuable help in advance.K006B |
|
|
tkizer
Almighty SQL Goddess
38200 Posts |
Posted - 2005-01-21 : 16:26:28
|
| So the account that runs this code, does it have access to that share? Just because a share exists doesn't mean that everyone has access to it. And can the database server get to that share? BULK INSERT runs from the database server and not from the client.Tara |
 |
|
|
k006b
Starting Member
10 Posts |
Posted - 2005-01-24 : 10:50:49
|
| Dear Tara,Thanks for your quick reply,I am using an administrator account on the client machine and using sa account on sql server query analyzer. The folder where the sql script is lying is a shared folder. But i can manage to run this script on the server itself till i get a PERMANENT solution. Another problem is this script is working perfectly on Sqlserver7.0 and giving error on sqlserver 2000. Would appreciate if you could give me the correct syntax to get the following output.set @query ='BULK INSERT '+ @Tablename + ' FROM "'+ @Filepath+@Filename+'" WITH ( FIELDTERMINATOR = ",",ROWTERMINATOR = "\n")'if i use the above line on the script it is returing error near comma(,) on sqlserver2000 whereas the same script is working perftly without any problems.I should get the following EXACTLY if i run the script.BULK INSERT kbAccount FROM 'c:\myimport\a.csv' WITH ( FIELDTERMINATOR = ',' ,ROWTERMINATOR = '\n')BULK INSERT kbAccount FROM 'c:\myimport\b.csv' WITH ( FIELDTERMINATOR = ',' ,ROWTERMINATOR = '\n')BULK INSERT kbAccount FROM 'c:\myimport\c.csv' WITH ( FIELDTERMINATOR = ',' ,ROWTERMINATOR = '\n')a.csv,b.csv,c.csv are the files available on c:\myimport folder on server where the sqlserver2000 is installed.I am facing problems because of single quotes.thanks in advanceK006B |
 |
|
|
tkizer
Almighty SQL Goddess
38200 Posts |
Posted - 2005-01-24 : 12:46:18
|
| Run:PRINT @query to see what your code is doing. Just because a share is setup doesn't mean that permissions have been set. I would try Windows Authentication from Query Analyzer rather than sa. Make sure to login with a domain account that has permissions on the share, preferably one that also has local admin on the db server.Tara |
 |
|
|
|
|
|
|
|