Staudte
asked on
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
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
ASKER
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?
Or am I missing a point?
It will be best if you Truncate Data from each destination table when you are moving data from one to other.
ASKER
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)?
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)?
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
SQL Data Compare™
http://www.red-gate.com/products/SQL_Data_Compare/index.htm
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
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
>>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.
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.
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.
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.
ASKER
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.
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.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
sometimes people post Oracle questions in MS SQL Server, SQL Server 2008 Zones ...
ASKER
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.
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.
ASKER
This question is progressing well now, attempting to delete it was my mistake. Please ignore this request and leave it open.
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
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