• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 545
  • Last Modified:

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

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
Staudte
Asked:
Staudte
  • 5
  • 4
  • 3
  • +1
2 Solutions
 
Mohit VijayCommented:
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
 
StaudteAuthor Commented:
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
 
Mohit VijayCommented:
It will be best if you Truncate Data from each destination table when you are moving data from one to other.
0
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.

 
StaudteAuthor Commented:
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
 
Anthony PerkinsCommented:
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
 
Eugene ZCommented:
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
 
Anthony PerkinsCommented:
>>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
 
Eugene ZCommented:
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
 
StaudteAuthor Commented:
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
 
Anthony PerkinsCommented:
>>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
 
Eugene ZCommented:
sometimes people post Oracle questions in  MS SQL Server, SQL Server 2008 Zones ...
0
 
StaudteAuthor Commented:
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
 
StaudteAuthor Commented:
This question is progressing well now, attempting to delete it was my mistake. Please ignore this request and leave it open.
0
 
Eugene ZCommented:
--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

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

  • 5
  • 4
  • 3
  • +1
Tackle projects and never again get stuck behind a technical roadblock.
Join Now