Celebrate National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Copy SQL database (and ASP.NET user database) from live into test system

Posted on 2010-09-11
14
Medium Priority
?
537 Views
Last Modified: 2012-05-10
Hi Experts,

on my web server I have SQL databases containing my data (named Live) and the ASP.net users (named Live_aspnetdb). These I would like to copy into my test database (named Test and Test_aspnetdb), which reside on the same server.

So far I have restored database backups from Live and Live_aspnetdb to Test and Test_aspnetdb, but after that had to fix access rights manually, because the SQL users that can access the Live db may not access the Test db and vice versa. Having to do this for every such Copy process is pretty time consuming...

What is the best way to quickly copy the contents of the Live dbs into to Test dbs, without having to manually adjust access rights?

Thanks a lot!

Thomas
0
Comment
Question by:Staudte
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 5
  • 4
  • 3
  • +1
14 Comments
 
LVL 8

Expert Comment

by:Mohit Vijay
ID: 33656239
1. You can crate a one time script and can run it always when you move live database to test.

2. Other options is to create a linked server and add production server as linked server and then you can write Insert/update query (one time effort), using this way you dont need to move database files physically.

below is simple example for MySQL to MS-SQL, you can consider it as MS-SQL production to MS-SQL Test

http://www.codeproject.com/KB/database/migrate-mysql-to-mssql.aspx 
0
 

Author Comment

by:Staudte
ID: 33656257
Thanks for the quick reply. I don't really understand how your 1) would help me - it's obvious I have to create some kind of script, but which - unless you mean that the key statement of 2) is the core of that script (SELECT * INTO testMySQL.dbo.shoutbox FROM openquery(MYSQL, 'SELECT * FROM tigerdb.shoutbox'). The problem with that SELECT is (as far as I understand) that it doesn't remove any old data from my test database first. This, on the other hand, could be tricky because of relationships. Also, it would quite likely not carry over all autoincrement IDs untouched, which would damage the consistency of the database.

Or am I missing a point?
0
 
LVL 8

Expert Comment

by:Mohit Vijay
ID: 33656278
It will be best if you Truncate Data from each destination table when you are moving data from one to other.
0
Will your db performance match your db growth?

In Percona’s white paper “Performance at Scale: Keeping Your Database on Its Toes,” we take a high-level approach to what you need to think about when planning for database scalability.

 

Author Comment

by:Staudte
ID: 33656775
Well, I can't Truncate the ASP.net user databases, as there are foreign key relationships in the data structure. Using Delete doesn't reset a autoincrement IDs.

Isn't there a way to copy the databases on a database or table level, rather than per record (as in a Select * Into statement)?
0
 
LVL 75

Expert Comment

by:Anthony Perkins
ID: 33657112
Consider purchasing a copy of Red-Gate's SQL Data Compare to do this:
SQL Data Compare™
http://www.red-gate.com/products/SQL_Data_Compare/index.htm
0
 
LVL 43

Expert Comment

by:Eugene Z
ID: 33657201
you probably had "orphaned users" problem
see
Resolve Orphaned Users
 http://support.microsoft.com/kb/274188/
 http://www.sqlteam.com/forums/topic.asp?TOPIC_ID=12615
more
How to move databases between computers that are running SQL Server
http://support.microsoft.com/kb/314546 
0
 
LVL 75

Expert Comment

by:Anthony Perkins
ID: 33975620
>>acperkins' suggestions costs several hundered dollars<<
Then I can only assume you do not value your time or your data very much ...

Next time, please do not abandon the question for over a month, just because you did not like the responses.
0
 
LVL 43

Expert Comment

by:Eugene Z
ID: 33979025
Staudte:
You have never posted what is your sql server version and SP
you need to make sure you have a fresh SP:
If you restore on the same server db - you should have no problem - and no need to fix db user.
0
 

Author Comment

by:Staudte
ID: 33980225
Dear All,

sorry for having been unresponsive. Let me clarify my reasons: This is a non-profit project into which I have invested hundreds of hours and where only extremely limited budget is available. Technically, I have (simplified):

DB_Live and DB_live_aspnetdb with user DB_Live_User
DB_Test and DB_test_aspnetdb with user DB_Test_User
DB_Dev and DB_dev_aspnetdb with user DB_Dev_User

Occasionally (every couple of weeks) I back up DB_Live and restore to DB_Dev and DB_Test using a SQL Backup Tool (dbsave). After that, the DB_Test_User and DB_Dev_User have lost rights to access their databases, while DB_Live_User can access all three. I have to manually remove DB_Live_User's rights from the two copies and reassing the other two users to their corresponding db's. There's nothing really incorrect or defective with the way the restore is handled, there are no orphaned users, just incorrect access rights.

I just want to copy the _data_, not access rights, from one DB to another. Also, I do value my time, but I don't throw money out for a tool that does something the already available environment should be very qualified to to. And  @EugeneZ, I just assumed that if I was posting in MS SQL 2008 zones and reference asp.net, it would be clear that I'm dealing with MS SQL 2008 - sorry for overlooking the general rule to clarify the environment. I'm using Windows 2008, MS SQL 2008 Express 10.0.2531.

Reconsidering the scenario, I fell that I need to look into SQL commands that do the following:

Back-Up a database into a file.
Restore the file into another database on the same server
(if still needed) Remove access rights from one user and add rights to another.

I'll put these commands into a SQL procedure file and invoke it manually using Management Studio as required.

Thanks again for taking your time looking into this.
0
 
LVL 75

Accepted Solution

by:
Anthony Perkins earned 1000 total points
ID: 33984572
>>there are no orphaned users, just incorrect access rights.<<
That is exactly what is going on.  But don't take my word for it, next time it happens execute the following from the database and you will see for yourself:

EXEC sp_change_users_login 'Report'

>>I have to manually remove DB_Live_User's rights from the two copies and reassing the other two users to their corresponding db's. <<
Totally unnecessary. all you have to do is run sp_change_users_login with Auto_Fix, but if that what you like doing more power to you ...
0
 
LVL 43

Expert Comment

by:Eugene Z
ID: 33988529
sometimes people post Oracle questions in  MS SQL Server, SQL Server 2008 Zones ...
0
 

Author Comment

by:Staudte
ID: 33993824
Please excuse my ignorance, but I don't get it to work.

I have restored the Live db into my Dev db and, as a result, the live user has access rights to liveDb (as before) and to devDb (expected, but not intended).

In SQL Server Management Studio I select the devDb and execute

USE [Jufo-Dev]
EXEC sp_change_users_login 'Report'
GO

That gives me a one-line-table with "Jufo" and a UserSID ("Jufo" is not a current username, they are called "Jufo-Live", "Jufo-Dev" and "Jufo-Test").

Doing a

USE [Jufo-Dev]
EXEC sp_change_users_login 'Auto_Fix', 'jufo-dev'
GO

returns a message, that 0 orphaned users were repaired.

The access rights have not changed after that procedure.

0
 

Author Comment

by:Staudte
ID: 33993835
This question is progressing well now, attempting to delete it was my mistake. Please ignore this request and leave it open.
0
 
LVL 43

Assisted Solution

by:Eugene Z
Eugene Z earned 1000 total points
ID: 33997446
--make sure your slq login for the orphaned  db user is present on the sql server
EXEC sp_change_users_login 'Update_One' ,'yourORPHdbuser','yoursqllogin'
for more check BOL examples @:
sp_change_users_login
http://msdn.microsoft.com/en-us/library/ms174378.aspx
0

Featured Post

Comprehensive Backup Solutions for Microsoft

Acronis protects the complete Microsoft technology stack: Windows Server, Windows PC, laptop and Surface data; Microsoft business applications; Microsoft Hyper-V; Azure VMs; Microsoft Windows Server 2016; Microsoft Exchange 2016 and SQL Server 2016.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Why is this different from all of the other step by step guides?  Because I make a living as a DBA and not as a writer and I lived through this experience. Defining the name: When I talk to people they say different names on this subject stuff l…
Windocks is an independent port of Docker's open source to Windows.   This article introduces the use of SQL Server in containers, with integrated support of SQL Server database cloning.
This video shows, step by step, how to configure Oracle Heterogeneous Services via the Generic Gateway Agent in order to make a connection from an Oracle session and access a remote SQL Server database table.
Viewers will learn how to use the SELECT statement in SQL and will be exposed to the many uses the SELECT statement has.

730 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question