安装部署SQL Server数据库(ldf与mdf),怎样将ldf和mdf文件考到目标机器后,获得它们的路径,从而在 install 类里用 sp_detach_db 附加数据库? 还有个问题 请帮忙:
http://community.csdn.net/Expert/topic/4322/4322910.xml?temp=.6918299

解决方案 »

  1.   

    http://blog.csdn.net/lihonggen0/archive/2004/05/17/13654.aspx
      

  2.   

    //启动windows服务
    new System.ServiceProcess.ServiceController("MSSQLSERVER").Start();
    //附加数据库
    SqlConnection Connection = new SqlConnection("password=ketong;user id=sa;data source="+SystemInformation.ComputerName);
    SqlCommand Cmd = new SqlCommand("sp_attach_db",Connection);
    Cmd.CommandType = CommandType.StoredProcedure;
    SqlParameter loginname=Cmd.Parameters.Add("@dbname",SqlDbType.NVarChar,20);
    loginname.Value ="yewuyuan";
    SqlParameter nickname=Cmd.Parameters.Add("@filename1",SqlDbType.NVarChar,50);
    nickname.Value =Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location)+"\\yewuyuan.mdf";
    SqlParameter password=Cmd.Parameters.Add("@filename2",SqlDbType.NVarChar,50);
    password.Value =Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location)+"\\yewuyuan.ldf";
    Connection.Open();
    Cmd.ExecuteNonQuery();
    Connection.Close();
      

  3.   

    基本问题已解决,谢谢 zhgroup() 和 koenemy() 
    另:我是在自定义安装对话框里传入 数据库的用户名和密码(用户界面 - 安装 - 启动 - 文本框 (A)),如何能讲密码那个输入框看不到明文...  或则有其他的解决方法这个问题完了就结帖了.. 谢谢各位!
      

  4.   

    http://blog.csdn.net/lihonggen0/archive/2004/05/17/13654.aspx
    这方法我用过,好用
      

  5.   

    回:yezie(椰子.Net)
      我是这样做的 :)
    不过新问题是:
      如何能使输入框看不到明文(密码输入)...  或有其他的解决方法?