publicclassVbDeployInstaller{System.Data.SqlClient.SqlConnectionmasterConnection=newSystem.Data.SqlClient.SqlConnection();publicVbDeployInstaller():base(){//This call is required by the Component Designer.InitializeComponent();//Add initialization code after the call to InitializeComponent}privatestringGetSql(stringName){try{// Gets the current assembly.AssemblyAsm=Assembly.GetExecutingAssembly();// Resources are named using a fully qualified name.Streamstrm=Asm.GetManifestResourceStream(Asm.GetName().Name+"."+Name);// Reads the contents of the embedded file.StreamReaderreader=newStreamReader(strm);returnreader.ReadToEnd();}catch(Exceptionex){Interaction.MsgBox("In GetSQL: "+ex.Message);throwex;}}privatevoidExecuteSql(stringDatabaseName,stringSql){System.Data.SqlClient.SqlCommandCommand=newSystem.Data.SqlClient.SqlCommand(Sql,masterConnection);// Initialize the connection, open it, and set it to the "master" databasemasterConnection.ConnectionString=My.Settings.masterConnectionString;Command.Connection.Open();Command.Connection.ChangeDatabase(DatabaseName);try{Command.ExecuteNonQuery();}finally{// Closing the connection should be done in a Finally blockCommand.Connection.Close();}}protectedvoidAddDBTable(stringstrDBName){try{// Creates the database.ExecuteSql("master","CREATE DATABASE "+strDBName);// Creates the tables.ExecuteSql(strDBName,GetSql("sql.txt"));}catch(Exceptionex){// Reports any errors and abort.Interaction.MsgBox("In exception handler: "+ex.Message);throwex;}}publicoverridevoidInstall(System.Collections.IDictionarystateSaver){base.Install(stateSaver);AddDBTable(this.Context.Parameters.Item("dbname"));}}