473,396 Members | 1,766 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

Backup users

I am currently using the BACKUP DATABASE method to backup my database.
Everything works fine, except for users. I created various users with
sp_addlogin to access this database and they are located in the xlogins
table. The problem is for example, if I backup, remove some users and
do a restore, i won't have them back because i just backup the
database.

So the question is, how can I backup specific users and restore them ?
Do I have to do it manually ? It seems I can't alter the xlogin table
so I'm pretty confused.

Feb 22 '06 #1
4 12217
Kittikun (ki******@gmail.com) writes:
I am currently using the BACKUP DATABASE method to backup my database.
Everything works fine, except for users. I created various users with
sp_addlogin to access this database and they are located in the xlogins
table. The problem is for example, if I backup, remove some users and
do a restore, i won't have them back because i just backup the
database.

So the question is, how can I backup specific users and restore them ?
Do I have to do it manually ? It seems I can't alter the xlogin table
so I'm pretty confused.


Not really sure that I understand your question. If you decide to drop
a login from the server, you have probably decided to do for good. Why
would you have thst login back if you reture a database?

If you restore the database on a different server, then there is a problem,
because the users in the database will not match the logins. In this case
you can use sp_change_users_login to map users back to logins. For details
on this procedure, please look in Books Online.
--
Erland Sommarskog, SQL Server MVP, es****@sommarskog.se

Books Online for SQL Server 2005 at
http://www.microsoft.com/technet/pro...ads/books.mspx
Books Online for SQL Server 2000 at
http://www.microsoft.com/sql/prodinf...ons/books.mspx
Feb 22 '06 #2
Well, I am making an application that allow users to create new users
with different rights and privileges. Each new user have an sql user
account in the database and are registered in a custom table.

So when I make a backup, the custom table will contains all the logins.
If after I remove some users with my application, the sql user will be
removed and the table will be updated. But, if I restore the backup,
the table will contain the deleted users and the sql accounts won't
exist so they won't be usable.

I don't know the clear password so I can't use sp_change_users_login or
sp_add_user.

So to backup/restore sql user account I tried the following thing

1) Make a copy of my users with

use test
go

SELECT * INTO x FROM master.dbo.syslogins

2) To restore them afterward

use master
go

exec sp_configure 'allow updates', 1
RECONFIGURE WITH OVERRIDE
go

insert syslogins select * from test.dbo.x
exec sp_configure 'allow updates', 0
RECONFIGURE WITH OVERRIDE
go

Thought it may have been a good idea but I get an "Update or insert of
view or function 'syslogins' failed because it contains a derived or
constant field." error.

Maybe I am looking on the wrong path...

Feb 23 '06 #3
Kittikun (ki******@gmail.com) writes:
Well, I am making an application that allow users to create new users
with different rights and privileges. Each new user have an sql user
account in the database and are registered in a custom table.

So when I make a backup, the custom table will contains all the logins.
If after I remove some users with my application, the sql user will be
removed and the table will be updated. But, if I restore the backup,
the table will contain the deleted users and the sql accounts won't
exist so they won't be usable.

I don't know the clear password so I can't use sp_change_users_login or
sp_add_user.
First permit me to straighten up some terminology.

The entity that connects to SQL Server is a *login* (or in SQL 2005
speak a "server principal".)

A login can be given access to a database, and is then mapped to
*user* in that database. ("database principal" in SQL 2005.)

When you take a backup of the database, you will get the *users*,
because the users are stored in the database, more precisely in
the sysusers table.

Normally, a login "joe" maps to a user "joe" in a database, but
there is law about this. A very exceptions is when the login owns the
database. In this case the login's user in the database is "dBo".

Anyway, what I still don't understand is why you remove these logins,
if you think you may need them again.

But if you need to recreate them you can. The fact that you don't know
the password is not an issue - just invent one. Once you have the
login, you can use sp_change_users_login. (And there is no reason to
use sp_adduser.) Of course, if the dropped login what to retain their
passwords, they can't do that.
exec sp_configure 'allow updates', 1
RECONFIGURE WITH OVERRIDE
go

insert syslogins select * from test.dbo.x
exec sp_configure 'allow updates', 0
RECONFIGURE WITH OVERRIDE
go

Thought it may have been a good idea but I get an "Update or insert of
view or function 'syslogins' failed because it contains a derived or
constant field." error.


syslogins is a view, the table is sysxlogins. But I have no idea
whether it works to do this. It certainly isn't supported.
--
Erland Sommarskog, SQL Server MVP, es****@sommarskog.se

Books Online for SQL Server 2005 at
http://www.microsoft.com/technet/pro...ads/books.mspx
Books Online for SQL Server 2000 at
http://www.microsoft.com/sql/prodinf...ons/books.mspx
Feb 23 '06 #4
Well I think I will give up this feature. Thank you for all you replies.

Feb 27 '06 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: newbiegca_sqlsever2000 | last post by:
Question 1 3 GHZ CPU (Intel pentium 4) single cpu + 2 GB Memory + SCSI HDD Database size 10 GB - How long will full database backup take if the backup is writing a file to the hard disk...
6
by: aj | last post by:
I currently have 2 official DB2 Workgroup Edition licenses for my 2 v8 production servers. I also have tech support/software upgrade agreements in place for both servers. I am interested in...
3
by: rdemyan via AccessMonster.com | last post by:
I'm thinking about providing a relatively easy method for users to restore the front end from a backup. The purpose is to allow for restoring if the front end becomes corrupt. Here are some...
2
by: mike_dba | last post by:
I have recently upgraded from SuSe 8 to 9 (kernel 2.4 to kernel 2.6). I am running DB2 8.1 FP 11 (aka 8.2 FP 4). I have had slowdowns that I suspect are related to the fact that an online backup...
10
by: Konstantin Andreev | last post by:
Hello. Some time ago I asked in this conference, - How to use an ONLINE BACKUP to restore database onto another system? - but got no answers. Therefore I can conclude it is not possible. But......
6
by: javelin | last post by:
I'm having difficulty searching for an answer to this challenge. Can someone give me a clue on the right keywords to use to find a discussion on this subject? All of the ones I saw appear to touch...
3
by: Robertf987 | last post by:
Well, I think I've described what I want to do in the title here. In the database, I have two main tables that contain the main data for the database. One for group expenditures, another for...
1
by: esource | last post by:
We have a existing backup, re-index job that runs at night on an existing database that is now accessed by web users 24/7. Problem is that one of the steps is to kill all users before backup...
11
by: limperger | last post by:
Hello everyone! At my workplace, there is a database shared by many users (not the one I have been mentioning in other posts, but a new one!!). It is a single mdb with no front or back-end copies...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.