Solved

Stored Procedure checking for File existance

Posted on 2002-07-09
10
346 Views
Last Modified: 2012-12-11
Can a stored procedure read a physical drive. I want to make an stored procedure that sets a Boolean value based on the existence of a file on a drive. It would not be located on the same server as SQL. Are there any security issues too. An example would be nice.
0
Comment
Question by:rian
10 Comments
 
LVL 75

Expert Comment

by:Anthony Perkins
ID: 7141472
Please maintain these open questions:

2000 Mapping Error Date: 07/25/2001 01:53PM PST
http://www.experts-exchange.com/win2k/Q_20157467.html
Flex Grid Question Date: 06/06/2002 01:09PM PST  
http://www.experts-exchange.com/visualbasic/Q_20308730.html
FlexGrid Multiple selection Date: 04/16/2002 08:21AM PST
http://www.experts-exchange.com/visualbasic/Q_20290075.html

Thanks,
Anthony

0
 
LVL 18

Expert Comment

by:nigelrivett
ID: 7142009
I usually do it via a dir command but you could also use the file system object.

create procedure spCheck
@filename varchar(128) ,
@fileexists int output
as

select @fileexists = 0
create table #a (s varchar(1000))
declare @sql varchar(1000)
select @sql = 'dir c:\dir\*.*'
insert #a exec xp_cmdshell @sql
if exists (select * from #a where s like '%' + @filename + '%'
select @fileexists = 1

go

You will need permission on the directory for the user context under which xp_cmdshell runs on your system - probably the sql server service.
0
 
LVL 9

Expert Comment

by:miron
ID: 7142308
an extended stored procedure xp_fileexist migth be of help.

execute master.dbo.xp_fileexist 'C:\boot.ini'

output

[File Exists] 1 -- integer
[File is a Directory] 0 --integer
[Parent Directory Exists] 1 --integer
0
 
LVL 142

Expert Comment

by:Guy Hengel [angelIII / a3]
ID: 7142629
>>it would not be located on the same server as SQL
This said, the stored proc can only see local drives to the SQL Server, for drives on other PC it would be an UNC path (\\workstation\C$\), for which the (admin) permissions need to be given
CHeers
0
Enabling OSINT in Activity Based Intelligence

Activity based intelligence (ABI) requires access to all available sources of data. Recorded Future allows analysts to observe structured data on the open, deep, and dark web.

 

Author Comment

by:rian
ID: 7143826
WHat kind of security do I need to setup. I have a server called MAserver which is connected to my machine. However when I do a
execute master.dbo.xp_fileexist '\\maserver\cdrive\config.sys'

it gives me 0,0,0 in all three fields. that file does exist. and I am logged on using query analyzer as sa. plus xp_fileexist is set for public access.
Ofcourse, this procedure will probably be run on individual sql accounts.
0
 
LVL 9

Expert Comment

by:miron
ID: 7145130
Looks like stored procedure is working, it returned zeros, indicative that it was un-able to see the share.

I would verify account running sql server, it need to be domain account, not a local to the machine running sql server, also this account need to have "full control" privilege granted to access the share, where file was checked.

Cheers
0
 

Author Comment

by:rian
ID: 7146463
I am not sure how you can set security setting in Windows for SQL users only. For example, I have a SQL user called joe with password joeb and when the user logs on, the sql connection is made with his username and password.
0
 
LVL 9

Accepted Solution

by:
miron earned 100 total points
ID: 7148212
sql users authenticated via sql server authentication are not the ones you need to worry when connecting to remote share. Please ,try to find account, Windows account that is running sql server, then everything will be clear.
0
 

Expert Comment

by:CleanupPing
ID: 9280174
rian:
This old question needs to be finalized -- accept an answer, split points, or get a refund.  For information on your options, please click here-> http:/help/closing.jsp#1
EXPERTS:
Post your closing recommendations!  No comment means you don't care.
0

Featured Post

Control application downtime with dependency maps

Visualize the interdependencies between application components better with Applications Manager's automated application discovery and dependency mapping feature. Resolve performance issues faster by quickly isolating problematic components.

Join & Write a Comment

Everyone has problem when going to load data into Data warehouse (EDW). They all need to confirm that data quality is good but they don't no how to proceed. Microsoft has provided new task within SSIS 2008 called "Data Profiler Task". It solve th…
Load balancing is the method of dividing the total amount of work performed by one computer between two or more computers. Its aim is to get more work done in the same amount of time, ensuring that all the users get served faster.
Familiarize people with the process of utilizing SQL Server functions from within Microsoft Access. Microsoft Access is a very powerful client/server development tool. One of the SQL Server objects that you can interact with from within Microsoft Ac…
Viewers will learn how the fundamental information of how to create a table.

708 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

20 Experts available now in Live!

Get 1:1 Help Now