January 8, 2008 at 5:00 am
I need to read a file system to extract and copy some file and directory. To do so I use some Extended Stored Procedures.
I use xp_dirtree to do this but I can't reach the server where I have files.
I use "\\MACHINE_NAME\SHARENAME" but the result set is empty (0 row(s) affected).
I try with xp_cmdshell but I have the same result.
Can someone help me?
Thanks.
January 8, 2008 at 5:10 am
Execute the following command which will give you idea about your database files. Execute the query with the respective database to find the related files.
select name, filename from sysfiles
Hope this is what are you looking for?
---------------------------------------------------
"Thare are only 10 types of people in the world:
Those who understand binary, and those who don't."
January 8, 2008 at 5:31 am
I have to reach another server to copy a lot of file (100 files for 1 GB). I try with
EXEC xp_dirtree "\\machine\shrarename" but I obtain "system cannot find path specified". Is the code correct? Have I forget some configuration?
Thanks.
January 8, 2008 at 7:39 am
First thing that comes to my mind is permissions. Where are you executing it from and do you have access as that user? I run from my workstation via query analyzer to server1 with the cmd EXEC xp_dirtree '\\server2\share' and it returns as expected. From my workstation I can access server2 as well. both servers use windows auth, which is how I am logged in on my wrkst.
Hope that helps.
January 8, 2008 at 7:47 am
Sounds like your Service Account does not have permissions to the share. Do you have the service account running under a local account or domain account? Go to SQL Server Configuration Manager and open up the properties of your SQL Instance to check. You have to give the current account permissions or use an account with the needed permissions.
January 8, 2008 at 7:48 am
One thing you can do (even if it's not a secure way) is to map this share using particular credential:
exec @Return = master..xp_cmdshell 'net use mapletter: \\server2\sharename pwd /user:domainname\username'
... and after work to delete map ...
exec @Return = master..xp_cmdshell 'net use mapletter: /delete'
January 8, 2008 at 3:43 pm
Not sure if this will help but try to check if the file exists then if
it exists do the copy
declare @Path varchar(128) ,
@FileName varchar(128)
select @Path = 'C:\' ,
@FileName = 'myfile.txt'
declare @i int
declare @File varchar(1000)
select @File = @Path + @FileName
exec master..xp_fileexist @File, @i out
if @i = 1
declare @cmd varchar (100)
select @cmd = 'copy C:\myfile.txt C:\myfile1.txt'
exec master..xp_cmdshell @cmd
else
print 'not exists'
January 8, 2008 at 6:02 pm
July (1/8/2008)
I have to reach another server to copy a lot of file (100 files for 1 GB). I try withEXEC xp_dirtree "\\machine\shrarename" but I obtain "system cannot find path specified". Is the code correct? Have I forget some configuration?
Thanks.
SQL Server must be logged in as a user that can "see" the directory.
--Jeff Moden
Change is inevitable... Change for the better is not.
Viewing 8 posts - 1 through 7 (of 7 total)
You must be logged in to reply to this topic. Login to reply