Solved

Reading file properties in SQL Server 2005 !!

Posted on 2007-11-28
4
997 Views
Last Modified: 2012-06-27
Hi,

I have a file (ABC.txt) file in C:\Temp folder. I want to read this file properties and place them in a SQL Server database table. Can you please let me know how can i read its properties ?

Appreciate your time and patience !

Thanks
0
Comment
Question by:kishore_peddi
  • 2
4 Comments
 
LVL 18

Accepted Solution

by:
Yveau earned 500 total points
ID: 20368204
When you access another subsystem, you cannot do that by regular SQL code.
So what you might need here (and that is really not a good idea from security standpoint) is use the xp_cmdshell procedure. That way you can run 'DOS' commands and do an 'attrib' or 'dir' of the files.

First enable xp_cmdshell (off by default)

Hope this helps ...

sp_configure 'show advanced options',1

go

reconfigure

go
 

sp_configure 'xp_cmdshell',1

go

reconfigure

go
 

exec xp_cmdshell 'dir C:\'
 

sp_configure 'xp_cmdshell',0

go

reconfigure

go
 

sp_configure 'show advanced options',0

go

reconfigure

go
 
 

--

Open in new window

0
 
LVL 30

Expert Comment

by:nmcdermaid
ID: 20370677
You can write a vb.Net console app and link it to a stored proc and do it that way also.
0
 

Author Comment

by:kishore_peddi
ID: 20371782
Yveau,

Can you just clarify one point please ?

use sample  -- (sample - is my database)
go

sp_configure 'show advanced options',1
go
reconfigure
go
 
sp_configure 'xp_cmdshell',1
go
reconfigure
go
 
exec xp_cmdshell 'dir C:\'  -- (xp_cmdshell => In which database this is residing ? in MASTER or sample)
go            
 
sp_configure 'xp_cmdshell',0
go
reconfigure
go
 
sp_configure 'show advanced options',0
go
reconfigure
go
0
 
LVL 18

Expert Comment

by:Yveau
ID: 20383871
master
0

Featured Post

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

Suggested Solutions

This article will describe one method to parse a delimited string into a table of data.   Why would I do that you ask?  Let's say that you need to pass multiple parameters into a stored procedure to search for.  For our sake, we'll say that we wa…
Use this article to create a batch file to backup a Microsoft SQL Server database to a Windows folder.  The folder can be on the local hard drive or on a network share.  This batch file will query the SQL server to get the current date & time and wi…
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…
This tutorial demonstrates a quick way of adding group price to multiple Magento products.

746 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

16 Experts available now in Live!

Get 1:1 Help Now