Run a sql batch file


The following command is only available on a Sql Server instance.

  • sql-run: this command run a batch of sql commands on your Sql Server instance.

The xml attribute named name expects the name of the file containing the Sql commands. The attribute path is the path for the folder containing this file. This path must be relative to the test-suite. The attribute connectionString lets you define the connection-string for the targeted database. This connection-string but me a SqlClient connection-string and cannot be an OleDb or ODBC connection-string (avoid provider or driver parameters).

<setup>
  <sql-run
    name="MyCommands.Sql"
    path="SQL\"
    connectionString="..."
  />
</setup>

If you want, you can also reference a connection-string in the xml attribute named connectionString. If you want to avoid to repeat this connection-string within all your commands, you can create a default value for the connectionString in the settings at the top of your test-suite where the value for the xml attribute apply-to must be set setup-cleanup.

<settings>
  <default apply-to="setup-cleanup">
    <connectionString>Data Source=(local)\SQL2012;Initial Catalog=AdventureWorksDW2012;Integrated Security=true</connectionString>
  </default>
</settings>