Click here to monitor SSC
SQLServerCentral is supported by Red Gate Software Ltd.
 
Log in  ::  Register  ::  Not logged in
 
 
 
        
Home       Members    Calendar    Who's On


Add to briefcase

restore database without overwriting users Expand / Collapse
Author
Message
Posted Tuesday, March 26, 2013 8:18 AM
Grasshopper

GrasshopperGrasshopperGrasshopperGrasshopperGrasshopperGrasshopperGrasshopperGrasshopper

Group: General Forum Members
Last Login: Monday, August 26, 2013 9:15 AM
Points: 19, Visits: 25
I am receiving a daily download of a database and restoring it locally to do some custom reporting on. I have this working from Batch files running nightly.

The problem I have is that when I restore the database, it also overwrites the local users of the database which includes a user I added to access the tables from Visual Studio.

How can I restore a database, but leave the local users tables alone?

Thank you in advance.
Post #1435520
Posted Tuesday, March 26, 2013 8:21 AM


SSCertifiable

SSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiable

Group: General Forum Members
Last Login: Today @ 5:57 AM
Points: 5,100, Visits: 4,842
You can't

SQL needs to restore the database as it was at the time of backing it up.

To do what you need to do add another script to your batch which creates the login and user and assigned the necessary permissions.




Want an answer fast? Try here
How to post data/code for the best help - Jeff Moden
Need a string splitter, try this - Jeff Moden
How to post performance problems - Gail Shaw
CrossTabs-Part1 & Part2 - Jeff Moden
SQL Server Backup, Integrity Check, and Index and Statistics Maintenance - Ola Hallengren
Managing Transaction Logs - Gail Shaw
Troubleshooting SQL Server: A Guide for the Accidental DBA - Jonathan Kehayias and Ted Krueger

Post #1435523
Posted Tuesday, March 26, 2013 11:46 AM
Grasshopper

GrasshopperGrasshopperGrasshopperGrasshopperGrasshopperGrasshopperGrasshopperGrasshopper

Group: General Forum Members
Last Login: Monday, August 26, 2013 9:15 AM
Points: 19, Visits: 25
I am still basic newbie to sql(1 year) how can I create accounts and permissions on a db from dos batch file? If you have a basic example I can take it from there.

Thank you.

Steve
Post #1435644
Posted Wednesday, March 27, 2013 2:54 AM
Mr or Mrs. 500

Mr or Mrs. 500Mr or Mrs. 500Mr or Mrs. 500Mr or Mrs. 500Mr or Mrs. 500Mr or Mrs. 500Mr or Mrs. 500Mr or Mrs. 500

Group: General Forum Members
Last Login: Yesterday @ 12:42 PM
Points: 531, Visits: 2,074
When restoring a database from one SS instance to another there is two things I generally do from a script:

sp_changedbowner 'USERNAME'

sp_revokedbaccess 'USERNAME'
sp_grantdbaccess 'USERNAME'

These are needed in order to match the user SIDs for the new instance.
Post #1435799
Posted Wednesday, March 27, 2013 3:05 AM


SSCertifiable

SSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiable

Group: General Forum Members
Last Login: Today @ 5:57 AM
Points: 5,100, Visits: 4,842
shathaway 77080 (3/26/2013)
I am still basic newbie to sql(1 year) how can I create accounts and permissions on a db from dos batch file? If you have a basic example I can take it from there.

Thank you.

Steve


The login will already exist, so you need to change the context to the database.

USE databasename
GO

Then create the user

CREATE USER username FOR LOGIN loginname
GO

Then create the permissions you need, eg, db_owner

EXEC sp_addrolemember 'db_owner', 'username'
GO




Want an answer fast? Try here
How to post data/code for the best help - Jeff Moden
Need a string splitter, try this - Jeff Moden
How to post performance problems - Gail Shaw
CrossTabs-Part1 & Part2 - Jeff Moden
SQL Server Backup, Integrity Check, and Index and Statistics Maintenance - Ola Hallengren
Managing Transaction Logs - Gail Shaw
Troubleshooting SQL Server: A Guide for the Accidental DBA - Jonathan Kehayias and Ted Krueger

Post #1435802
« Prev Topic | Next Topic »

Add to briefcase

Permissions Expand / Collapse