And to make the post the a bit more on topic:
You may as well throw the code into an Installation Component
NET Framework Class Library: Installer Class
http://msdn.microsoft.com/library/d...emconfigurationinstallinstallerclasstopic.asp
---------------------------------------------------------------------------
using System;
using System.Collections;
using System.ComponentModel;
using System.Configuration.Install;
using System.Diagnostics;
namespace InstallNorthwind {
// i.e .invoke this class during execution
// of the assembly
[RunInstaller(true)]
public class InstallNorthwind : System.Configuration.Install.Installer {
private System.ComponentModel.Container components = null;
public InstallNorthwind() {
InitializeComponent();
}
protected override void Dispose( bool disposing ) {
if( disposing ) {
if(components != null) {
components.Dispose();
}
}
base.Dispose( disposing );
}
#region Component Designer generated code
private void InitializeComponent() {
components = new System.ComponentModel.Container();
}
#endregion
public override void Install(
System.Collections.IDictionary savedState
){
// call the Install() method of the base class
base.Install( savedState );
string strSqlFilePath = this.Context.Parameters["Args"];
// Run the osql process to run the database script
ProcessStartInfo psi =
new ProcessStartInfo(
"osql.exe ",
"-E -i " + "\"" + strSqlFilePath + "\""
);
psi.WindowStyle = ProcessWindowStyle.Hidden;
try {
Process p = Process.Start( psi );
p.WaitForExit();
} catch (Exception e){
// throw an install exception with
// the original exception message
throw new InstallException( e.Message );
}
}
public override void Commit(
System.Collections.IDictionary savedState
){
base.Commit( savedState );
}
public override void Rollback(
System.Collections.IDictionary savedState
){
base.Rollback( savedState );
}
public override void Uninstall(
System.Collections.IDictionary savedState
){
base.Uninstall( savedState );
}
}
}