ExecuteSqlScripts – Executing an array of script files

ExecuteSqlScripts – Executing an array of script files

' Execute an array of sql script files with batch statements,'  by using the same SqlCommand object'  - connString is the connection string for the destination database'' Example:'   Dim connString As String = "server=(local);Persist Security ' Info=False;Integrated Security=SSPI;database=TestDB"'   Dim script1 As String = "C:ScriptsCreateDbTables.sql"'   Dim script2 As String = "C:ScriptsCreateDbSprocs.sql"'   Dim script3 As String = "C:ScriptsInsertData.sql"'   ExecuteSqlScripts(connString, script1, script2, script3)Sub ExecuteSqlScripts(ByVal connString As String, ByVal ParamArray scriptFiles() _    As String)    ' open the connection and create a command that uses it    Dim cn As New SqlConnection(connString)    Dim cmd As New SqlCommand    Try        cn.Open()        cmd.Connection = cn        Dim scriptFile As String        For Each scriptFile In scriptFiles            ' get the content of the script file            Dim sr As System.IO.StreamReader = Nothing            Try                sr = New System.IO.StreamReader(scriptFile)                ' use the script file's content as CommandText for the command                 ' created above                cmd.CommandText = sr.ReadToEnd()            Catch ex As Exception                Throw ex            Finally                If Not sr Is Nothing Then sr.Close()            End Try            ' execute this script            cmd.ExecuteNonQuery()        Next    Catch ex As Exception        Throw ex    Finally        cn.Close()    End TryEnd Sub

Share the Post:
Heading photo, Metadata.

What is Metadata?

What is metadata? Well, It’s an odd concept to wrap your head around. Metadata is essentially the secondary layer of data that tracks details about the “regular” data. The regular

XDR solutions

The Benefits of Using XDR Solutions

Cybercriminals constantly adapt their strategies, developing newer, more powerful, and intelligent ways to attack your network. Since security professionals must innovate as well, more conventional endpoint detection solutions have evolved

AI is revolutionizing fraud detection

How AI is Revolutionizing Fraud Detection

Artificial intelligence – commonly known as AI – means a form of technology with multiple uses. As a result, it has become extremely valuable to a number of businesses across

AI innovation

Companies Leading AI Innovation in 2023

Artificial intelligence (AI) has been transforming industries and revolutionizing business operations. AI’s potential to enhance efficiency and productivity has become crucial to many businesses. As we move into 2023, several

data fivetran pricing

Fivetran Pricing Explained

One of the biggest trends of the 21st century is the massive surge in analytics. Analytics is the process of utilizing data to drive future decision-making. With so much of