我把数据库文件mydata.sql也发送安装的应用文件夹中,但在安装的过程中出现找不到文件?
 我也做了个安装类,  public InstallerMySample()
        {
            InitializeComponent();
        }
         public override void Install(System.Collections.IDictionary stateSaver)
        {
            //数据库安装程序入口
            _saPassword = this.Context.Parameters["pwd"];
            _dataBaseName = this.Context.Parameters["dbname"];
            _targetPath = this.Context.Parameters["targetdir"];
            _servername = this.Context.Parameters["server"];
            _username = this.Context.Parameters["user"];            iis = this.Context.Parameters["iis"];
            port = this.Context.Parameters["port"];
            //添加数据库
            AddDBTable();
.......
private void ExcuteScript()
        {
            try
            {
                Process sqlProcess = new Process();
                //调用osql必须在目标机,也就是安装的机子上要有安装SQLServer服务器
                //不然找不到这个命令
                sqlProcess.StartInfo.FileName = "osql.exe";
                //如下所指的SQL脚本文件是打包打安装项目的文件名,
                //targetPath就是在安装界面用户指定的安装目录
                sqlProcess.StartInfo.Arguments = string.Format("-U {0} -P{1} -d {2} -S {3} -i {4}mydata.sql",
                    _username, _saPassword, _dataBaseName, _servername, _targetPath);                sqlProcess.StartInfo.WindowStyle = ProcessWindowStyle.Hidden;
                sqlProcess.Start();
                sqlProcess.WaitForExit();
                sqlProcess.Close();
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }

解决方案 »

  1.   

    private void ExecuteSql(string conn,string DatabaseName,string Sql)
      {
       SqlConnection mySqlConnection=new SqlConnection(conn);  
       SqlCommand Command=new SqlCommand(Sql, mySqlConnection);  
       mySqlConnection.Open();  
       mySqlConnection.ChangeDatabase(DatabaseName);  
       try
       {
        Command.ExecuteNonQuery();
       }  
       finally
       { 
        mySqlConnection.Close();
       }
      }
    string connstr = String.Format("data source={0};user id={1};password={2};persist security info=false;packet size=4096", Context.Parameters["server"],Context.Parameters["user"], Context.Parameters["pwd"]); 
        ExecuteSql(connstr, "master", "CREATE DATABASE " +Context.Parameters["dbname"]);   
        Process sqlprocess=new System.Diagnostics.Process();
        sqlprocess.StartInfo.FileName = "osql.exe ";  
        sqlprocess.StartInfo.Arguments = String.Format(" -U {0} -P {1} -d {2} -i {3}db.sql", Context.Parameters["user"], Context.Parameters["pwd"],Context.Parameters["dbname"],Context.Parameters["targetdir"]);
        sqlprocess.StartInfo.WindowStyle = ProcessWindowStyle.Hidden;
        sqlprocess.Start();  
        sqlprocess.WaitForExit(); 
        sqlprocess.Close();
    参考
    参考
      

  2.   

    值不能为空.参数名: steam
    code:
    protected void AddDBTable(string strDBName)
            {            try
                {                //Create the database.                ExecuteSql("master", "CREATE DATABASE " + strDBName);                // Create the tables.                ExecuteSql(strDBName, GetSql("mydata.sql"));               // ExecuteSql(strDBName, GetSql("Fuction.sql"));               // ExecuteSql(strDBName, GetSql("View.sql"));            }            catch (Exception ex)
                {                throw ex;            }        }
      private string GetSql(string strName)
            {            try
                {                Assembly Asm = Assembly.GetExecutingAssembly();                Stream strm = Asm.GetManifestResourceStream(Asm.GetName().Name + "." + strName);                StreamReader reader = new StreamReader(strm);                return reader.ReadToEnd();            }            catch (Exception ex)
                {                throw ex;            }        }
      

  3.   

    在主页写如果写
    protected void Page_Load(object sender, EventArgs e)
        {
            Assembly Asm = Assembly.GetExecutingAssembly();        Response.Write(Asm.GetName().Name + "." + "strName");
            
        }
    得到结果:App_Web_9jyxd8us.strName 
    这是什么原因?
      

  4.   

    要确认好服务器是否有相应版本的数据库。光是引用sql的dll是不够的,因为这些dll中还可能调用其他的dll进行操作。
      

  5.   

    我数据库是sql2000,执行到一半就停,但库己建立,里面没有表,也就是没有mydata.sql执行的结果
      

  6.   

    试将自定义操作->安装->主输出->属性的CustomActionData路径的[targetdir]属性设为指定要读取的文件就行了