In the C # code, add a user and attach a database to sqlserver2000.

Source: Internet
Author: User

Use the system stored procedure sp_attach_db to attach the database;
Use the system stored procedure sp_addlogin to add an account

Add User:

1 Public bool adduser (string cusername, string password, string dB)
2 {
3 system. data. sqlclient. sqlconnection ocon = new system. data. sqlclient. sqlconnection ("Data Source = .; initial catalog = Master; Password =; persist Security info = true; user id = sa ");
4 try
5 {
6 ocon. open ();
7}
8 catch
9 {
10 return false;
11}
12 system. Data. sqlclient. sqlcommand oadduser = new system. Data. sqlclient. sqlcommand ();
13 oadduser. commandtype = system. Data. commandtype. text;
14 oadduser. Connection = ocon;
15 oadduser. commandtext = "Exec sp_addlogin '" + cusername + "', '" + password + "', '" + dB + "'";
16 try
17 {
18 int I = oadduser. executenonquery ();
19}
20 catch
21 {
22 return false;
23}
24 if (I = 0)
25 {
26 return false;
27}
28 else
29 {
30 return true;
31}
32
33}

Similar to the attached Database

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.