Change sql server 2008 r2 database name/schema and username - schema

I have two accounts at Softsys Hosting with a domain on each account. I need to clone the database from one domain to the other, so I can run one as a staging site and the other as the live site.
I've taken a back-up of the live database and tried to restore it to the dev account, but it fails because of database/schema/user name conflicts (both databases will be on the same server apparently so it won't let the 'same' database be created twice, which makes sense).
Softsys said that I need to take a local back-up of the database, change the name, schema name and user name, then upload that to my dev environment. The trouble is, I just can't get it to work. When I restore the back-up to my local system it won't let me log-in via the same username/password as on the live server - I can only seem to log is as 'sa'.
Can someone please explain to a database dunce, how I can get this .bak file from the live database running on my local machine with a working user account, and also how to change the names of the schema/user/database so that I'll be able to upload it to the dev server without any conflicts with the live domain?
I'm using MSSQL 2008 R2 and SQL Server Management Studio 2008 R2 Express.
Thanks all...

The reason you cannot use the login from your Prod box on your Dev box is that the login does not exist on the Dev box.
When you move the database over, it sounds like you only have the SA login on the Dev box.
You should script out the login(s) that you use on the prod server and recreate them on your Dev box. Read up here http://support.microsoft.com/kb/246133
If you have the login on your dev box, or you just created it with the script above, you are going to have to connect the Login on the server to the User in the datbase.
You need to link the the new Login on the server to the User in the database. Use the ALTER USER statement to fix this. http://msdn.microsoft.com/en-us/library/ms176060.aspx
This used to be done with sp_change_users_login http://msdn.microsoft.com/en-us/library/ms174378.aspx

Related

How to fix TF246017 The Team foundation server could not connect to database

I'm getting nothing but this error TF246017 I'm not able to access TFS as admin or domain user
While accessing administration console, showing the error TF246017
Domain users getting TF31001 where the server returns TF246017
TFS was working fine with SQL Server 2008. And now we have also installed SQL server 2012 in the same machine.( I believe it doesn't connected anyway to tfs server)
But, even after uninstalling SQL 2012, it displays the same error
In application tier/ database tier, getting error as Error retrieving value.
Unable to access http://xxxxxxx:8080/tfs displays same error TF246017
And also, im unable to locate the sql express database to take the backup.
How to resolve this issue?
Note : I'm using TFS 2012 and VS2010
Login to windows server using the same windows credential user you used during SQL Server installation.
Verify or add the new windows user credential (assuming you are using different user credential to connect to TFS) to be part of sysadmin user group in SQL Server or ask your SQL Server DBA to add the user to sysadmin group.
Note: This is required because for every new TFS Team project created, TFS presents 2 option empty database or new database. To create new database the TFS admin user have to be part of SQL server sysadmin group
If TFS 2012 was installed using the same windows credential, open the TFS Admin console and add or verify the user is listed in "administration Console Users" list.
If TFS Admin console reads "You do not have permission or not administrator" or something along this line, then you need to log out and log back using the correct windows credential used for installation or use one of the TFS admin user and then add the new user credential.
Recommendation: To avoid confusion I would recommend use the same user credential for SQL Server and TFS server. Ex: "domainname/tfs" is local admin to the server, sysadmin in SQL Server DB and also admin user to TFS server.
To make like simple start of by, adding the windows user (intended to use as TFS admin) as windows administration group. Then logout and log back using the TFS admin user to install SQL Server and TFS server.
I had a similar issue branch code in my version of TFS (Azure DevOps Premise). I tracked my issue down by looking at the event viewer on the local TFS server and found that I was that I was getting the following SQL error:
DESCRIPTION: SQL Server Assertion: File: , line=951 Failed Assertion =
'IS_OFF (BUF_MINLOGGED, m_buf->bstat) || pageModifyType !=
PageModifyType_Contents || GetPagePtr ()->IsTextPage ()'. This error
may be timing-related. If the error persists after rerunning the
statement, use DBCC CHECKDB to check the database for structural
integrity, or restart the server to ensure in-memory data structures
are not corrupted.
I found the first item in the following answer solved my issue.
I simply switched my main TFS database containing my collection to FULL recovery mode and I was immediately able to proceed with my previously erroring task.
Connect to your SQL instance via SQL Server Management Studio and check if any of the TFS databases are in a "Recovery Pending" state. If so, restart your SQL instance and the state should return to normal. Worked for me!
Just find out the Team foundation application under application pool. right click and go to advance setting set the identity using the credentials used for SQL Sever or TFS Admin and done ..you can now access the TFS as earlier.

sql server user authentication not working

i created a software in vb.net 2005. i create a database in sql server 2005. i connect it with window authentication. everything works fine.
but problem started when i replace my database with old database copyed from different computer.
i attach screnshot of both database with attached users.
old database
and new database is
when i try to connect my software with old database with window authentication, it is not connected.
can anyone please tell me what the problem is and how to solve this?
When you restore a Microsoft SQL Server database on a different machine, the user could be no more the same on the previous machine. Even if you see the same username listed.
This user is called an 'orphaned user'.
Meaning that there is no login id or password associated with the user since the original SID identifying the user is no more valid on the new machine.
You could check if you have this situation with
EXEC sp_change_users_login 'Report'
and, you could fix with
EXEC sp_change_users_login 'Auto_Fix', 'Gauntam-PC\Gautam'

Microsoft SQL Server Management Studio trouble with permissions

Please find all the files I'm refering to at this link:
http://whyisthisinmyfood.com/sql/
I have installed a new copy of "SQL Server 2008 R2 Management Studio Express (x86)" on two Windows 7 computers. The SAME install file for both computers. Installed the same way. (as far as I know, I chose the same options)
One at home and one at work.
The one at home seems to work perfectly I "Execute" this file (ITD132-Inventory Initial with data.sql) and it works fine. When I "Execute" it at work I get:
Msg 262, Level 14, State 1, Line 1
CREATE DATABASE permission denied in database 'master'.
..and a bunch of stuff after that which is caused because the database was not created in the first place.
I have compared the permissions on both computers.
see these files:
home computer : non-networked.jpg
work computer: work-networked.jpg
I read in one post that to create new Logins one must be logged in as the Administrator. I log into the Server Managment studio with my windows credentials and I am the Local Admin for my work computer and I have not been able to find any other place to log in as an administrator for this SQL Server Management Studio (so clearly I'm not sure whats meant by that)
At this point I think my problem is that I need to create a user who is not just the "BUILTIN\User" (because this login does not have permissions) with permissions.
But I have no idea how to login as an administrator to create this user role.
Please forgive me if these are obvious answers as I am just starting with this MS Management studio and am not very familiar with T-SQL.
Thanks,
Diana
If you install SQL Server, you get asked during installation process which user or user group should have the Admin-Privileges. If your computer is part of a domain and you login locally, things might get complicated.
The easiest (but not safest way) to login as a "superuser" if to enable the "sa" user.
this is one user that logs on with a password (not integrated logon) and has all the juice to run every script possible :-) By default it's disabled - googling I found a easy how-to enable it:
http://sudeeptaganguly.wordpress.com/2010/04/20/how-to-enable-sa-account-in-sql-server/
I think you are correct that you need to create another user with enough permission. Generally logging in with "integrated security" using your Windows credentials should have enough permissions (assuming the same user is the user that installed SQL Server). If not, you have better luck logging in as the SQL Server user "sa" (system administrator) which should have full permission. Do you know the "sa" password?
Note: the security mode for SQL Server can be set to "Only integrated security with Windows users", "SQL Server security" or "both". The "sa" account will only work if the SQL Server security is enabled. You may be able to access these settings using your BuiltIn\User account.

"Cannot open database - login failed" . Works in Management Studio, not code

Oh yes, the famous error:
Cannot open database "MYDBNAME" requested by the login. The login failed. Login failed for user 'USERNAME'.
Let me explain my situation:
I have a database server, which has a SA account and my user account. The user has the correct mappings to my database (dbowner).
I can open the database with this user, using SQL Management Studio 2008 R2, both on the SQL server itself (using localhost), and on my frontend server.
However, when I run my application, I get the login failed error.
Strange thing is I have a test application and a production application on our frontend server. The test application has test databases on the same database server, and there are no login problems here. The only difference between the two, are the prefix which differs from "TEST" to "PROD". The test application works, the production however, doesn't. The user mappings and seem it should work on both.
Any ideas?
EDIT:
Our connectionstring:
<add key="umbracoDbDSN" value="Server=Websqlsrv01;Database=PROD_Databasename;User ID=umbraco_user;Password=password;Trusted_Connection=False" />
Sql server has a dichotomy login/user
they are 2 different entity:
http://www.akadia.com/services/sqlsrv_logins_and_users.html
maybe your sql login is not associated with an user for database PROD_Databasename but only for TEST_Databasename
another cause could be the user default database or eventually different database schemas
you can easily check if one of those is the problem simply creating a new user for PROD_Databasename and using it in connectionstring.
another way is to execute
exec sp_helpuser
in both databases (PROD and TEST) and see if the username "umbraco_user" is listed.
Anyway it is not a good practice to use same login for 2 different users:
https://dba.stackexchange.com/questions/16374/is-there-any-benefit-to-having-one-sql-server-login-for-multiple-users
Sometimes you need to use servername\instancename in your connection string if you've setup something other than a default instance. Use this link to find your instance name. Give that a try!
right click on you application and run as admin. This should work!

SQL Server restorig backup on Developement (Or Test) Server and user mapping

I got 3 server.
development (my local development machine)
Test purpose (Beta site).
Production
I got Instances in both SQL server 2005 and 2008.
So, When I want updated data, i take the latest backup from our production server and restore it on the Test or development Server. I got a script that make the changes (restore the file and make some slight changes on the databases.)
My problem is, each time i do this, The SQL server Login (created on the server) I use lose it's Database user mapping. I got to delete it form the restored database and recreate it from the root Security Logins.
Is there a way to include that in my restore script?
I got to delete it form the
restored database and recreate it from
the root Security Logins.
No, you don't need to do this - at least not on SQL Server 2005 and 2008.
What you need to do (like in a script) is this:
USE (your database)
GO
ALTER USER YourUserNo1 WITH LOGIN = YourServerLoginNo1
That associates your user YourUserNo1 in your database (whatever) to the server login called YourServerLoginNo1.
Works pretty nice'n'easy, I'd say! You can even do this as a last step in the restore script (which I'm sure you have to restore those things over and over again)
When restoring our production database to the report server each month, I run:
EXEC sp_change_users_login 'Auto_Fix', 'usernamegoeshere'