1: using System;
2: using System.Collections.Generic;
3: using System.ComponentModel;
4: using System.Configuration.Install;
5:
6: namespace InstallerClassLib
7: {
8: [RunInstaller(true)]
9: public partial class DBInstaller : Installer
10: {
11: public DBInstaller()
12: {
13: InitializeComponent();
14: }
15: public override void Install(
16: System.Collections.IDictionary stateSaver)
17: {
18: base.Install(stateSaver);
19:
20: //File Path ini didapatkan dari
21: //setting CustomActionnya nanti
22: string strSqlFilePath =
23: this.Context.Parameters["args"];
24:
25: //gunakan osql.exe untuk execute
26: //script database yang akan diinstal
27: System.Diagnostics.ProcessStartInfo psi =
28: new System.Diagnostics.ProcessStartInfo(
29: "osql.exe", @"-S .\sqldev2k5 -E -i " +
30: Convert.ToChar(34) + strSqlFilePath
31: + Convert.ToChar(34));
32: //Convert.ToChar(34) digunakan untuk menghasilkan
33: //apostrope (single quote)
34:
35: psi.WindowStyle =
36: System.Diagnostics.ProcessWindowStyle.Normal;
37: psi.UseShellExecute = false;
38:
39: try
40: {
41: System.Diagnostics.Process proses =
42: System.Diagnostics.Process.Start(psi);
43: }
44: catch (Exception ex)
45: {
46: throw new InstallException(ex.Message +
47: strSqlFilePath);
48: }
49: }
50:
51: public override void Uninstall(
52: System.Collections.IDictionary savedState)
53: {
54: base.Uninstall(savedState);
55: }
56:
57: public override void Commit(
58: System.Collections.IDictionary savedState)
59: {
60: base.Commit(savedState);
61: }
62:
63: public override void Rollback(
64: System.Collections.IDictionary savedState)
65: {
66: base.Rollback(savedState);
67: }
68: }
69: }