![]() | |
![]() |
| | Thread Tools | Display Modes |
#1
| |||
| |||
|
#2
| |||
| |||
|
|
Our web application requires that when a new Organization is created,a separate Database is to be created for the corresponding organization, so that each organization remains a separate entity with their corresponding employees(This is our clients requirement, so that they can later provide the backup of the database if the organization decides to move out). And for that what we intend to do is restore the backup of database which already has the objects created in it.So we intend to restore a database for the new organization from the web page. |
|
We are using SQL Server 2005 Enterprise Edition |
|
I think most will suggest to use 'exec sp_changedbowner' to update the dbo, but for this we need sysadmin privileges, which we do not have for the xy login. |
#3
| |||
| |||
|
|
Was the database originally created on the same server or on a different server? Who is the owner of the original database? |
|
We are using SQL Server 2005 Enterprise Edition Which Service Pack are you on? (There is some new commands in SP2 that may be useful.) |
|
You could put ALTER AUTHORISZATION in a stored procedure that is signed by a certificate, and then you grant a login created from that certificate the rights change database owner. That login is not a real login that can actually connect. For more information about this, see an article on my web site:http://www.sommarskog.se/grantperm.html. |
#4
| |||
| |||
|
|
Who is the owner of the original database? This made me think about creating the database with the xy(the login |
#5
| |||
| |||
|
|
This made me think about creating the database with the xy(the login that connects from the web application) login and then backup the database and then restore using the RESTORE command with the xy login(xy is assigned to dbcreator role). This allowed me to connect to the NewOrgDB with xy login. But again I encountered the block when I tried restoring on a server other than the server that I took the orginal DB backup from. Yes I understand that this is due to the lost login-user mapping in the new database. |
|
Would like to restore the privilege of xy to be able to login to the NewOrgDB without assigning it to sysadmin role. Can i make use of sp_change_users_login in this case, but again I think we need to login as a user with sysadmin role to NewOrgDB database and only then can i execute this procedure, which I wouldnt be able to. Pls suggest any solution. |
#6
| |||
| |||
|
|
I can see two ways out: one is write a signed stored procedure as I discussed in my previous post. The great thing with this is that you can package the database creation into this procedure as well, and thereby the login does not even need dbcreator. The link >again:http://www.sommarskog.se/grantperm.html. |
|
The other way is to create the source database with the xy login. Then to avoid the login/user mapping problem on the other servers, create the login on these servers with same SID as on the source server. This is possible with CREATE LOGIN xy WITH PASSWORD = 'Sehr hemlig!', SID = 0x.... Get the SID on the source server from sys.server_principals. If the login already exists on the server, you need to drop it first. |
#7
| |||
| |||
|
|
I can see two ways out: one is write a signed stored procedure as I discussed in my previous post. The great thing with this is that you can package the database creation into this procedure as well, and thereby the login does not even need dbcreator. The link again:http://www.sommarskog.se/grantperm.html. Will go through the URL in detail. Did u mean that I need to include the 'RESTORE DATABASE' command within the stored procedure. |
![]() |
| Thread Tools | |
| Display Modes | |
| |