 <p>You can add the reference to these 2 SMO dll</p> <pre><code>using Microsoft.SqlServer.Management.Smo; using Microsoft.SqlServer.Management.Common; </code></pre> <p>and then run the command directly by reading all of sql.</p> <pre><code>string scriptToRun = File.ReadAllText("Filepath"); using (SqlConnection conn = new SqlConnection("Yourconnectionstring")) { Server server = new Server(new ServerConnection(conn)); server.ConnectionContext.ExecuteNonQuery(scriptToRun); } </code></pre>