SQL Clone
SQLServerCentral is supported by Redgate
 
Log in  ::  Register  ::  Not logged in
 
 
 


Execute .sql script within a stored procedure without using xp_cmdshell


Execute .sql script within a stored procedure without using xp_cmdshell

Author
Message
juniorDBA13
juniorDBA13
Mr or Mrs. 500
Mr or Mrs. 500 (500 reputation)Mr or Mrs. 500 (500 reputation)Mr or Mrs. 500 (500 reputation)Mr or Mrs. 500 (500 reputation)Mr or Mrs. 500 (500 reputation)Mr or Mrs. 500 (500 reputation)Mr or Mrs. 500 (500 reputation)Mr or Mrs. 500 (500 reputation)

Group: General Forum Members
Points: 500 Visits: 452
Hi,

I want to execute a .sql script within a stored procedure but I want to do it without enabling xp_cmdshell.

Any ideas?
martinkuen
martinkuen
SSC Rookie
SSC Rookie (30 reputation)SSC Rookie (30 reputation)SSC Rookie (30 reputation)SSC Rookie (30 reputation)SSC Rookie (30 reputation)SSC Rookie (30 reputation)SSC Rookie (30 reputation)SSC Rookie (30 reputation)

Group: General Forum Members
Points: 30 Visits: 21
I didn't try this way but it could work. You could use a BULK INSERT and write the content of the .sql file into a table and then execute this content as dynamic SQL.
John Mitchell-245523
John Mitchell-245523
SSC Guru
SSC Guru (108K reputation)SSC Guru (108K reputation)SSC Guru (108K reputation)SSC Guru (108K reputation)SSC Guru (108K reputation)SSC Guru (108K reputation)SSC Guru (108K reputation)SSC Guru (108K reputation)

Group: General Forum Members
Points: 108919 Visits: 18620
juniorDBA13 - Wednesday, December 20, 2017 6:42 AM
Hi,

I want to execute a .sql script within a stored procedure but I want to do it without enabling xp_cmdshell.

Any ideas?

Are you sure that's a good idea? You'd want to make very sure that nobody has access to modify the .sql file, otherwise all sorts of damage could be done.

John

Thom A
Thom A
SSC Guru
SSC Guru (61K reputation)SSC Guru (61K reputation)SSC Guru (61K reputation)SSC Guru (61K reputation)SSC Guru (61K reputation)SSC Guru (61K reputation)SSC Guru (61K reputation)SSC Guru (61K reputation)

Group: General Forum Members
Points: 61026 Visits: 17757
What is the .sql file doing? Why are you wanting to execute SQL from a file in a (shared) file path? Is it so that it can be dynamic? Is it procedurally generated perhaps? There are far safer ways than just executing a .sql file. Like John said, if anyone has access to modify it, they could easily do a huge amount of damage.


Thom~
Excuse my typos and sometimes awful grammar. My fingers work faster than my brain does :-P

Please always remember to encapsulate your code in IFCode Markup. For example [code=sql] [/code].
Click here to read Jeffs Guide on how to post SQL questions, and get swift and helpful answers from the community
Jeff Moden
Jeff Moden
SSC Guru
SSC Guru (695K reputation)SSC Guru (695K reputation)SSC Guru (695K reputation)SSC Guru (695K reputation)SSC Guru (695K reputation)SSC Guru (695K reputation)SSC Guru (695K reputation)SSC Guru (695K reputation)

Group: General Forum Members
Points: 695585 Visits: 45622
Thom A - Thursday, January 4, 2018 3:54 AM
What is the .sql file doing? Why are you wanting to execute SQL from a file in a (shared) file path? Is it so that it can be dynamic? Is it procedurally generated perhaps? There are far safer ways than just executing a .sql file. Like John said, if anyone has access to modify it, they could easily do a huge amount of damage.

+ 1,000,000 to that!


--Jeff Moden

RBAR is pronounced ree-bar and is a Modenism for Row-By-Agonizing-Row.
First step towards the paradigm shift of writing Set Based code:
Stop thinking about what you want to do to a row... think, instead, of what you want to do to a column.
If you think its expensive to hire a professional to do the job, wait until you hire an amateur. -- Red Adair

Helpful Links:
How to post code problems
How to post performance problems
Forum FAQs
Jeff Moden
Jeff Moden
SSC Guru
SSC Guru (695K reputation)SSC Guru (695K reputation)SSC Guru (695K reputation)SSC Guru (695K reputation)SSC Guru (695K reputation)SSC Guru (695K reputation)SSC Guru (695K reputation)SSC Guru (695K reputation)

Group: General Forum Members
Points: 695585 Visits: 45622
juniorDBA13 - Wednesday, December 20, 2017 6:42 AM
Hi,

I want to execute a .sql script within a stored procedure but I want to do it without enabling xp_cmdshell.

Any ideas?


This is a form of "Death by SQL" no matter how you do it. Perhaps if you explained why there's a need to do such a thing and what the script(s) will actually do, we might be able to recommend a much safer method.

--Jeff Moden

RBAR is pronounced ree-bar and is a Modenism for Row-By-Agonizing-Row.
First step towards the paradigm shift of writing Set Based code:
Stop thinking about what you want to do to a row... think, instead, of what you want to do to a column.
If you think its expensive to hire a professional to do the job, wait until you hire an amateur. -- Red Adair

Helpful Links:
How to post code problems
How to post performance problems
Forum FAQs
Go


Permissions

You can't post new topics.
You can't post topic replies.
You can't post new polls.
You can't post replies to polls.
You can't edit your own topics.
You can't delete your own topics.
You can't edit other topics.
You can't delete other topics.
You can't edit your own posts.
You can't edit other posts.
You can't delete your own posts.
You can't delete other posts.
You can't post events.
You can't edit your own events.
You can't edit other events.
You can't delete your own events.
You can't delete other events.
You can't send private messages.
You can't send emails.
You can read topics.
You can't vote in polls.
You can't upload attachments.
You can download attachments.
You can't post HTML code.
You can't edit HTML code.
You can't post IFCode.
You can't post JavaScript.
You can post emoticons.
You can't post or upload images.

Select a forum








































































































































































SQLServerCentral


Search