代码如下,可以安装,但是安装完成后不会自动附加数据库,为什么呀?
using System;
using System.Collections;
using System.Collections.Generic;
using System.ComponentModel;
using System.Configuration.Install;
using System.Linq;
using System.IO;
using IWshRuntimeLibrary;
using System.Windows.Forms;
namespace MaterialParametersManagement
{
    [RunInstaller(true)]
    public partial class MyInstaller : Installer
    {
        public MyInstaller()
        {
            InitializeComponent();
        }        string floderName = "航空材料参数管理系统";        public override void Install(System.Collections.IDictionary stateSaver)
        {
            try
            {                base.Install(stateSaver);
                System.Reflection.Assembly Asm = System.Reflection.Assembly.GetExecutingAssembly();//获取当前程序集信息
                System.IO.FileInfo fileinfo = new System.IO.FileInfo(Asm.Location);//获取当前程序集位置                string dbpath = fileinfo.DirectoryName;//获取文件夹名称
                AttachDB(dbpath);
            }
            catch (Exception e)
            {
                System.Windows.Forms.MessageBox.Show(e.Message);
            }        }
#region 附加数据库 
        private void AttachDB(string DBPath)
        {
            try
            {
                DataBase DBC = new DataBase();
                DataBase.ConnectionString = "Data Source= localhost\\SQLEXPRESS; Initial Catalog=master; Integrated Security=True";
                DBC.DataBaseName = "MaterialDB2005";
                DBC.DataBase_MDF = DBPath + @"\MaterialDB2005.mdf";
                DBC.DataBase_LDF = DBPath + @"\MaterialDB2005_log.ldf";
                MessageBox.Show(DBC.DataBase_MDF);
                DBC.AddDataBase();
            }
            catch
            {
                MessageBox.Show("附加数据库错误!", "错误", MessageBoxButtons.OK, MessageBoxIcon.Error);
                return;
            }
        }
#endregion    }
}