Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2000 Forums
 SQL Server Administration (2000)
 db login from backup

Author  Topic 

-Dman100-
Posting Yak Master

210 Posts

Posted - 2004-09-13 : 13:21:33
Is there a way I can get the following T-SQL commands to run automatically when restoring a backup? I have created my DB on the testing server with my login account. When I send my hosting the db backup I was curious if there is a way to have these sp's run automatically so the login account is created automatically? I wasn't sure there was a way to do this.

Use Master
go
-- Creates a new SQL Server login that allows a user to connect to a
server running SQL Server using SQL Server Authentication.
EXEC sp_addlogin 'loginAccountName', 'your_choice', 'YourDB'
go

-- Adds a security account in the current database for a SQL
Server login or Microsoft Windows NT user or group, and enables it to
be granted permissions to perform activities in the database.
EXEC sp_grantdbaccess 'loginAccountName', 'loginAccountName'
go

Use YourDB
Go
Adds a security account as a member of an existing SQL Server
database role in the current database.
EXEC sp_addrolemember 'db_owner', 'loginAccountName'
Go

Thanks.
-D-

n/a
deleted

35 Posts

Posted - 2004-09-13 : 14:20:55
The only way I can think to do this, and I have not tested this at all, would be to create an alart on the some database measure (like restore throughput per second) and have it execute a saved job (with your SQL Code in it) when the troughput gets above 0.
You would need to test the ALOT before implementing it, but it could be a start.

HTH
Paul
Go to Top of Page

Kristen
Test

22859 Posts

Posted - 2004-09-13 : 14:55:38
Schedule a task which check for the Account Name, and if it is missing creates it?

No better idea, sorry!

Kristen
Go to Top of Page

jen
Master Smack Fu Yak Hacker

4110 Posts

Posted - 2004-09-13 : 22:21:06
if you're performing the restore using tsql, you can set up a job and include the adding of account as one of the steps after backup,

if not...

you can create a batch file packaged with the backup file. you can set a trigger to run the file.

just a thought...
Go to Top of Page
   

- Advertisement -