日期:2014-05-18 浏览次数:20572 次
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=123456;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+"'"; int i=oAddUser.ExecuteNonQuery(); if(i==0) { return false; } else { return true; } } private void button1_Click(object sender, EventArgs e) { AddUser("abcde","1234","master"); }
CREATE LOGIN [BaseUser] WITH PASSWord=N'baseuser', DEFAULT_DATABASE=[TRS], CHECK_EXPIRATION=OFF, CHECK_POLICY=OFF GO
------解决方案--------------------