0

I am using Microsoft Visual Studio 2010 currently. I have a .sql file on my computer which has a lot of sql statements of code in it. Basically has three create table statements, multiple insert into statements, multiple alter table statements,adding foreign keys, etc.

I want to know is there a way that I can load that .sql file into an Execute SQL Task. Or how is it possible, in SSIS, that I can execute this long .sql file? I feel like an Execute SQL Task is involved, but I don't know for sure. This was the Execute SQL Task I tried before to no avail. enter image description here

Any help would be appreciated.

I have some screenshots basically to show how long of a file I'm talking about...and it goes longer than what is shown.

enter image description here

enter image description here

2
  • Edited to include Execute SQL Task I tried to no avail.
    – smul86
    Apr 15, 2016 at 6:14
  • If you run your ETL_Diagram.sql file in SSMS (or execute via sqlcmd) does it run successfully? Your error message leads me to believe there's something incorrect in it
    – billinkc
    Apr 15, 2016 at 14:29

2 Answers 2

2

Execute SQL Task will be what runs commands.

Change the SQL Source type from the default of "Direct Input" to "File Connection"

Then in the FileConnection property, specify a file connection manager that points to MyFile.sql

That said, you can just run the above file(s) in SSMS, or sqlcmd if you prefer a command line

3
  • See I tried that. I have the File Connection that points to ETL_Diagram.sql I get the following error "[Execute SQL Task] Error: Executing the query "" failed with the following error: "". Possible failure reasons: Problems with the query, "ResultSet" property not set correctly, parameters not set correctly, or connection not established correctly." Added a photo above to show.
    – smul86
    Apr 15, 2016 at 6:08
  • 1
    Then it sounds like you did successfully get the Task to run the file, and now you have not properly configured the task to handle the results of the file. I don't see anything in the screenshot that would be a problem, but it could be something further down in the file. Apr 15, 2016 at 13:31
  • Threw all the code into a SP and just executed the SP inside the Execute SQL Task which worked. Couldn't get the File Connection to work, not sure why.
    – smul86
    Apr 16, 2016 at 23:29
1

does the sql file contain parameterised insert statements? if so you need to have map the parameters and check that the source to which you are connecting is accessible and the structure of the tables are same as well

1
  • Nope, no parameterized insert statements in there.
    – smul86
    Apr 15, 2016 at 7:01

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.