473,230 Members | 1,294 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,230 software developers and data experts.

Can I carry my existing DB users to a new server and restore???

SD
Hi,

Quick question, I have about 20 users in my local server and database. We
are looking to restore that database to a new server in a new network and
still be able to retain the database users.

We have created all 20 logins in the new server (exact names) but when we
restore the database I do not see the users anymore!

Is there something we can do to preserve them or a script we can run to link
them again?

Thanks a bunch!!!

S


Jul 20 '05 #1
2 2138

"SD" <np****@nowhere.net> wrote in message
news:13******************************@news.teranew s.com...
Hi,

Quick question, I have about 20 users in my local server and database. We
are looking to restore that database to a new server in a new network and
still be able to retain the database users.

We have created all 20 logins in the new server (exact names) but when we
restore the database I do not see the users anymore!

sp_change_users_login is probably what you need.

Is there something we can do to preserve them or a script we can run to link them again?

Thanks a bunch!!!

S

Jul 20 '05 #2
"Greg D. Moore \(Strider\)" <mo****************@greenms.com> wrote in message news:<7J********************@twister.nyroc.rr.com> ...
"SD" <np****@nowhere.net> wrote in message
news:13******************************@news.teranew s.com...
Hi,

Quick question, I have about 20 users in my local server and database. We
are looking to restore that database to a new server in a new network and
still be able to retain the database users.

We have created all 20 logins in the new server (exact names) but when we
restore the database I do not see the users anymore!


sp_change_users_login is probably what you need.

Is there something we can do to preserve them or a script we can run to

link
them again?

Thanks a bunch!!!

S


You can run the following script to generate a create script for all
of your users. It will generate a create statement for each login
using the encrypted password and SID. Replace "MY_DB" in the script
with your database name, then run the script against your source
database. Copy the output of the script to your destination server and
run it. Then, when you restore your database, your users will
automatically be synched with their logins. Hope this helps!

Lisa


--------------
--Description: Scripts logins for one db
--*****IMPORTANT replace MY_DB with the name of the database that
holds the users that you need scripted

----- Begin Script, Create sp_help_revlogin procedure -----
USE master
GO
SET NOCOUNT ON
IF OBJECT_ID ('sp_hexadecimal') IS NOT NULL
DROP PROCEDURE sp_hexadecimal
GO
CREATE PROCEDURE sp_hexadecimal
@binvalue varbinary(256),
@hexvalue varchar(256) OUTPUT
AS
DECLARE @charvalue varchar(256)
DECLARE @i int
DECLARE @length int
DECLARE @hexstring char(16)
SELECT @charvalue = '0x'
SELECT @i = 1
SELECT @length = DATALENGTH (@binvalue)
SELECT @hexstring = '0123456789ABCDEF'
WHILE (@i <= @length)
BEGIN
DECLARE @tempint int
DECLARE @firstint int
DECLARE @secondint int
SELECT @tempint = CONVERT(int, SUBSTRING(@binvalue,@i,1))
SELECT @firstint = FLOOR(@tempint/16)
SELECT @secondint = @tempint - (@firstint*16)
SELECT @charvalue = @charvalue +
SUBSTRING(@hexstring, @firstint+1, 1) +
SUBSTRING(@hexstring, @secondint+1, 1)
SELECT @i = @i + 1
END
SELECT @hexvalue = @charvalue
GO

IF OBJECT_ID ('sp_help_revlogin') IS NOT NULL
DROP PROCEDURE sp_help_revlogin
GO
CREATE PROCEDURE sp_help_MY_DBLogins @login_name sysname = NULL AS
DECLARE @name sysname
DECLARE @xstatus int
DECLARE @binpwd varbinary (256)
DECLARE @txtpwd sysname
DECLARE @tmpstr varchar (256)
DECLARE @SID_varbinary varbinary(85)
DECLARE @SID_string varchar(256)

IF (@login_name IS NULL)
DECLARE login_curs CURSOR FOR

SELECT a.sid, a.name, a.xstatus, a.password FROM
master..sysxlogins a
join MY_DB..sysusers MY_DB on a.sid = MY_DB.sid
WHERE a.srvid IS NULL AND a.name <> 'sa'

ELSE
DECLARE login_curs CURSOR FOR
SELECT a.sid, a.name, a.xstatus, a.password FROM
master..sysxlogins a
join MY_DB..sysusers MY_DB on a.sid = MY_DB.sid
WHERE a.srvid IS NULL AND a.name <> 'sa'
OPEN login_curs
FETCH NEXT FROM login_curs INTO @SID_varbinary, @name, @xstatus,
@binpwd
IF (@@fetch_status = -1)
BEGIN
--PRINT 'No login(s) found.'
CLOSE login_curs
DEALLOCATE login_curs
RETURN -1
END
PRINT ''
PRINT 'DECLARE @pwd sysname'
WHILE (@@fetch_status <> -1)
BEGIN
IF (@@fetch_status <> -2)
BEGIN
PRINT ''
IF (@xstatus & 4) = 4
BEGIN -- NT authenticated account/group
IF (@xstatus & 1) = 1
BEGIN -- NT login is denied access
SET @tmpstr = 'EXEC master..sp_denylogin ''' + @name + ''''
PRINT @tmpstr
END
ELSE BEGIN -- NT login has access
SET @tmpstr = 'EXEC master..sp_grantlogin ''' + @name + ''''
PRINT @tmpstr
END
END
ELSE BEGIN -- SQL Server authentication
IF (@binpwd IS NOT NULL)
BEGIN -- Non-null password
EXEC sp_hexadecimal @binpwd, @txtpwd OUT
IF (@xstatus & 2048) = 2048
SET @tmpstr = 'SET @pwd = CONVERT (varchar(256), ' + @txtpwd
+ ')'
ELSE
SET @tmpstr = 'SET @pwd = CONVERT (varbinary(256), ' +
@txtpwd + ')'
PRINT @tmpstr
EXEC sp_hexadecimal @SID_varbinary,@SID_string OUT
SET @tmpstr = 'EXEC master..sp_addlogin ''' + @name
+ ''', @pwd, @sid = ' + @SID_string + ', @encryptopt = '
END
ELSE BEGIN
-- Null password
EXEC sp_hexadecimal @SID_varbinary,@SID_string OUT
SET @tmpstr = 'EXEC master..sp_addlogin ''' + @name
+ ''', NULL, @sid = ' + @SID_string + ', @encryptopt = '
END
IF (@xstatus & 2048) = 2048
-- login upgraded from 6.5
SET @tmpstr = @tmpstr + '''skip_encryption_old'''
ELSE
SET @tmpstr = @tmpstr + '''skip_encryption'''
PRINT @tmpstr
END
END
FETCH NEXT FROM login_curs INTO @SID_varbinary, @name, @xstatus,
@binpwd
END
CLOSE login_curs
DEALLOCATE login_curs
RETURN 0
GO
----- End Script -----
--
EXEC master..sp_help_MY_DBLogins
--drop proc sp_help_MY_DBLogins
Jul 20 '05 #3

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

Similar topics

1
by: Hai-Chu Hsu | last post by:
Hi, I want to restore my databases from the old SQL Server installation into a new installation of SQL Server. My new installation of SQL Server has different data path from the old...
2
by: SD | last post by:
Hi, Quick question, I have about 20 users in my local server and database. We are looking to restore that database to a new server in a new network and still be able to retain the database...
1
by: Philipp | last post by:
Hey @ all, I have a question: It is possible to convert an existing SQL Server 2000 Database to SQL Server 2005? best wishes!
2
by: Stefan Schneider | last post by:
Hi, I have to copy an existing database from one Windows-Server to another one. The source database is a 8.1.0 database on a Windows 2000 Server, the destination database will be a newer 8.x...
0
by: Takpol | last post by:
Hello, I have several archived filegroups that have data in them partitioned based on the date. These filegroups have been removed from database after archival. For example two months ago....
5
by: HSP | last post by:
hi. i need to restore an old database. The db was backed up using a DLT drive, using 2 volumes. The content for the tapes was copied to file onto Solaris machine using rsh and dd (for backup...
4
by: Kittikun | last post by:
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...
5
by: smoi | last post by:
Hi all, My manager ask me to do backup for 3 database and restore them in a new server. I did the backup for the 3 database into BAK file. Then in the new server, when I did the restore in SQL...
4
by: Christian Maslen | last post by:
Hi All, I understand in older versions of DB2/UDB this was not possible. The following article explains how I might do this ...
0
by: VivesProcSPL | last post by:
Obviously, one of the original purposes of SQL is to make data query processing easy. The language uses many English-like terms and syntax in an effort to make it easy to learn, particularly for...
3
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 3 Jan 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). For other local times, please check World Time Buddy In...
0
by: jianzs | last post by:
Introduction Cloud-native applications are conventionally identified as those designed and nurtured on cloud infrastructure. Such applications, rooted in cloud technologies, skillfully benefit from...
0
by: abbasky | last post by:
### Vandf component communication method one: data sharing ​ Vandf components can achieve data exchange through data sharing, state sharing, events, and other methods. Vandf's data exchange method...
0
by: stefan129 | last post by:
Hey forum members, I'm exploring options for SSL certificates for multiple domains. Has anyone had experience with multi-domain SSL certificates? Any recommendations on reliable providers or specific...
0
Git
by: egorbl4 | last post by:
Скачал я git, хотел начать настройку, а там вылезло вот это Что это? Что мне с этим делать? ...
0
by: MeoLessi9 | last post by:
I have VirtualBox installed on Windows 11 and now I would like to install Kali on a virtual machine. However, on the official website, I see two options: "Installer images" and "Virtual machines"....
0
by: DolphinDB | last post by:
The formulas of 101 quantitative trading alphas used by WorldQuant were presented in the paper 101 Formulaic Alphas. However, some formulas are complex, leading to challenges in calculation. Take...
0
by: Aftab Ahmad | last post by:
So, I have written a code for a cmd called "Send WhatsApp Message" to open and send WhatsApp messaage. The code is given below. Dim IE As Object Set IE =...

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.