用系统存储过程Sp_attach_db 来附加数据库;
用系统存储过程sp_addlogin 来新增帐号

添加用户:
public bool AddUser(string cUserName,string Password,string DB)
{
 System.Data.SqlClient.SqlConnection oCon=new System.Data.SqlClient.SqlConnection("data source=.;initial catalog=master;password=;persist security info=True;user id=sa");
 try
 {
  oCon.Open();
 }
 catch
 {
  return false;
 }
 System.Data.SqlClient.SqlCommand oAddUser=new System.Data.SqlClient.SqlCommand();
 oAddUser.CommandType=System.Data.CommandType.Text;
 oAddUser.Connection=oCon;
 oAddUser.CommandText="exec sp_addlogin '"+cUserName+"','"+Password+"','"+DB+"'";
 try
 {
  int i= oAddUser.ExecuteNonQuery();
 }
 catch
 {
  return false;
 }
 if(i==0)
 {
  return false;
 }
 else
 {
  return true;
 }
   
}

附加数据库雷同

相关文章:

  • 2021-11-30
  • 2021-08-15
  • 2022-12-23
  • 2022-02-22
  • 2022-12-23
  • 2022-12-23
猜你喜欢
  • 2021-11-24
  • 2021-05-13
  • 2021-08-11
  • 2022-12-23
  • 2021-05-28
  • 2021-10-25
  • 2021-08-19
相关资源
相似解决方案