Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

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

Posted on 2010-09-11
14
Medium Priority
?
542 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
  • 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
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

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

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

Question has a verified solution.

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

Ever wondered why sometimes your SQL Server is slow or unresponsive with connections spiking up but by the time you go in, all is well? The following article will show you how to install and configure a SQL job that will send you email alerts includ…
An alternative to the "For XML" way of pivoting and concatenating result sets into strings, and an easy introduction to "common table expressions" (CTEs). Being someone who is always looking for alternatives to "work your data", I came across this …
Familiarize people with the process of retrieving data from SQL Server using an Access pass-thru query. Microsoft Access is a very powerful client/server development tool. One of the ways that you can retrieve data from a SQL Server is by using a pa…
Viewers will learn how the fundamental information of how to create a table.

963 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