Solved

Reading file properties in SQL Server 2005 !!

Posted on 2007-11-28
4
1,006 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

What is SQL Server and how does it work?

The purpose of this paper is to provide you background on SQL Server. It’s your self-study guide for learning fundamentals. It includes both the history of SQL and its technical basics. Concepts and definitions will form the solid foundation of your future DBA expertise.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

When writing XML code a very difficult part is when we like to remove all the elements or attributes from the XML that have no data. I would like to share a set of recursive MSSQL stored procedures that I have made to remove those elements from …
So every once in a while at work I am asked to export data from one table and insert it into another on a different server.  I hate doing this.  There's so many different tables and data types.  Some column data needs quoted and some doesn't.  What …
This Micro Tutorial hows how you can integrate  Mac OSX to a Windows Active Directory Domain. Apple has made it easy to allow users to bind their macs to a windows domain with relative ease. The following video show how to bind OSX Mavericks to …
Learn how to create flexible layouts using relative units in CSS.  New relative units added in CSS3 include vw(viewports width), vh(viewports height), vmin(minimum of viewports height and width), and vmax (maximum of viewports height and width).

911 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