onebite2
asked on
SQL Server 2005/2008
Here is the sql i used.
--Create the table to store file list
CREATE TABLE myFileList (FileNumber INT IDENTITY,FileName VARCHAR(256))
--Insert file list from directory to SQL Server
DECLARE @Path varchar(1024)
SET @Path = 'dir C:\ExcelFiles'
DECLARE @Command varchar(1024)
SET @Command = @Path + ' /A-D /B'
INSERT INTO myFileList
EXEC MASTER.dbo.xp_cmdshell @Command
--Check the list
SELECT * FROM myFileList
GO
--Clean up
DROP TABLE myFileList
GO
When i execute above sql, I get file not found.
I'm sure i did execute same or similar sql below and always worked.
Not sure why it isn't working now.
FYI: C:\ExcelFiles is local to workstation not on sql server and has bunch of excel files.
Maybe it's looking for something on sql server ????
--Create the table to store file list
CREATE TABLE myFileList (FileNumber INT IDENTITY,FileName VARCHAR(256))
--Insert file list from directory to SQL Server
DECLARE @Path varchar(1024)
SET @Path = 'dir C:\ExcelFiles'
DECLARE @Command varchar(1024)
SET @Command = @Path + ' /A-D /B'
INSERT INTO myFileList
EXEC MASTER.dbo.xp_cmdshell @Command
--Check the list
SELECT * FROM myFileList
GO
--Clean up
DROP TABLE myFileList
GO
When i execute above sql, I get file not found.
I'm sure i did execute same or similar sql below and always worked.
Not sure why it isn't working now.
FYI: C:\ExcelFiles is local to workstation not on sql server and has bunch of excel files.
Maybe it's looking for something on sql server ????
Map a drive on the sql server to the computer your looking for. then you can set your path to M:\ExcelFiles. (if M is the drive letter you choose to map the workstation to.
Map a drive on the sql server to the computer your looking for. then you can set your path to M:\ExcelFiles
Have you ever tried that? Reason I ask is because you may find that since SQL Server is running as service it will not recognize any mapped drives. Then of course you have the small detail of security, but that is another story...
Have you ever tried that? Reason I ask is because you may find that since SQL Server is running as service it will not recognize any mapped drives. Then of course you have the small detail of security, but that is another story...
ASKER
Sql Server is installed locally on my workstation. How would i map a drive on the sql server to the computer your looking for.. I think i kinda have an idea if sql server installed on different or remote server but what if a sql instance exists locally.
I did different paths on c/d drives, sometimes i keep getting messages like "file not found", sometimes "Access is denied" and sometimes "The system cannot find the path specified"
Does it tell you something????
Again my question "How would i map a drive on the sql server to the computer your looking for"
I did different paths on c/d drives, sometimes i keep getting messages like "file not found", sometimes "Access is denied" and sometimes "The system cannot find the path specified"
Does it tell you something????
Again my question "How would i map a drive on the sql server to the computer your looking for"
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
The command is executed on the sql server. So what you're seeing is a dir on your sql servers c: drive not your workstation drive.
/peter