Avatar of pradipkkoli
pradipkkoli

asked on 

Want to delete Folder from store procedure

Hi,

Is there any way to delete the folder from Store Procedure in SQL Server 2000.

Kindly provide the reference or the code for the same if avaliable.

Thanks

Pradip
Microsoft SQL Server

Avatar of undefined
Last Comment
pradipkkoli
Avatar of momi_sabag
momi_sabag
Flag of United States of America image

you could use a stored proced called  xp_cmdshell which allows you to pass command to the operating system
these commands run with the privileges of the user that runs the sql server service
so basically you can create a stored prcoedure like this :

create procedure delDir (path varchar(8000)) as
begin
  exec xp_cmdshell 'delete ' + path
end
Avatar of pradipkkoli
pradipkkoli

ASKER

Hi,

I had tried to create the SP

create procedure delDir (@path varchar(8000)) as
begin
  exec xp_cmdshell 'delete ' + @path
end

But there is error, the message is

Server: Msg 170, Level 15, State 1, Procedure delDir, Line 3
Line 3: Incorrect syntax near '+'.
Avatar of momi_sabag
momi_sabag
Flag of United States of America image

try this

create procedure delDir (@path varchar(8000)) as
begin
      declare @stmt varchar(8000)
    set @stmt = 'delete ' + @path
  exec xp_cmdshell @stmt
end
Avatar of pradipkkoli
pradipkkoli

ASKER

tried but got another error

Cannot add rows to sysdepends for the current stored procedure because it depends on the missing object 'xp_cmdshell'. The stored procedure will still be created.

How to add the 'xp_cmdshell' object
Avatar of momi_sabag
momi_sabag
Flag of United States of America image

that means your dba has deleted the xp_cmdshell stored procedure
so you need to contact him and ask him what can you do
basically you could create an extended stored procedure in C language that deletes a file, but i dought that your dba will allow you to do that if he dropped xp_cmdshell
Avatar of matrix_aash
matrix_aash
Flag of United Kingdom of Great Britain and Northern Ireland image

You will need to enable the xp_cmdshell from the SQL Server 2005 Surface Area Configuration.

Click on tab View by Component and enable the xp_cmdshell and you should be ready to go.

Hope this makes sense.

Cheers,

Aash.
Avatar of pradipkkoli
pradipkkoli

ASKER

Hi,

I am using SQL Server 2000, how to proceed in in SQL Server 2000 for the baove step

Pradip
Avatar of matrix_aash
matrix_aash
Flag of United Kingdom of Great Britain and Northern Ireland image

It is enabled in SQL Server 2000 by default.

if you want to add the xp_cmdshell in case its uninstalled, Please use the below command:

exec sp_addextendedproc 'xp_cmdshell','xplog70.dll'

Hope this helps.

Cheers,

Aash.
Avatar of pradipkkoli
pradipkkoli

ASKER

Hi,

Thanks for the answer.

But i m not using local database, i using as a client and db is on the server. On server the command is working but not on my local pc. So what rights on server i need to give.

Thanks
ASKER CERTIFIED SOLUTION
Avatar of matrix_aash
matrix_aash
Flag of United Kingdom of Great Britain and Northern Ireland image

Blurred text
THIS SOLUTION IS ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
Avatar of pradipkkoli
pradipkkoli

ASKER

Thanks for the solution. Thank You.
Microsoft SQL Server
Microsoft SQL Server

Microsoft SQL Server is a suite of relational database management system (RDBMS) products providing multi-user database access functionality.SQL Server is available in multiple versions, typically identified by release year, and versions are subdivided into editions to distinguish between product functionality. Component services include integration (SSIS), reporting (SSRS), analysis (SSAS), data quality, master data, T-SQL and performance tuning.

171K
Questions
--
Followers
--
Top Experts
Get a personalized solution from industry experts
Ask the experts
Read over 600 more reviews

TRUSTED BY

IBM logoIntel logoMicrosoft logoUbisoft logoSAP logo
Qualcomm logoCitrix Systems logoWorkday logoErnst & Young logo
High performer badgeUsers love us badge
LinkedIn logoFacebook logoX logoInstagram logoTikTok logoYouTube logo