SQL Task to Execute a SQL file
Hi, I have a SQL file that is stored on C:\. I would like to know how I would execute the syntax contained in the .sql file via vb.net in a SQL Task object in SSIS? Many Thanks BG
November 22nd, 2010 4:55pm

Since you need help in SSIS I suggest you to visit http://social.msdn.microsoft.com/forums/en-us/sqlintegrationservices/threads/ The question does not look like has anything to do with any class in System.Windows.Forms, the topic of this forum. The following is signature, not part of post Please mark the post answered your question as the answer, and mark other helpful posts as helpful, so they will appear differently to other users who are visiting your thread for the same problem. Visual C++ MVP
Free Windows Admin Tool Kit Click here and download it now
November 23rd, 2010 3:26am

Hi, I will move this thread into SQLSERVER forum. As it has anything about win form. Sincerely, Vin JinPlease remember to click Mark as Answer on the post that helps you, and to click Unmark as Answer if a marked post does not actually answer your question. This can be beneficial to other community members reading the thread.
November 23rd, 2010 10:32pm

Hi BG, If I understand correctly, you have a SQL Server Integration Services(SSIS) package. In the package, there is a Script Task. You want to pick up a SQL Script file from C:\ in the script task, and then execute it. If so, we can read the script file into string, and then use the SQL Server Management Objects(SMO) to execute the script. Below are the steps for your reference: In Script Task, refer to SQL Server SMO object. In the code, use the following code to execute the script file: Dim sr As StreamReader = New StreamReader("C:\script.sql") Dim script As String = sr.ReadToEnd Dim SMOServer As Server = New Server Dim db As Database = SMOServer.Databases("northwind") db.ExecuteNonQuery(script) Another way to execute the script file is that, read the script file into string, then use the SQLCommad to execute the string script in SQL Server. For more information, please see: Database.ExecuteNonQuery Method (String): http://msdn.microsoft.com/en-us/library/ms205782.aspx If you have any more questions, please feel free to ask. Thanks, Jin ChenJin Chen - MSFT
Free Windows Admin Tool Kit Click here and download it now
November 24th, 2010 2:11am

This topic is archived. No further replies will be accepted.

Other recent topics Other recent topics