473,441 Members | 1,926 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,441 software developers and data experts.

How do you associate a user to a Login in SQL 2005

I have DB that was restored from SQL 2000 into an instance of 2005. With the different Login/User structure I had to create a login to connect to the DB through ODBC.

What I am looking to do now is set it up so that the old user credentials can be used to login to the new DB and get all the same permissions.

So in old 2000 DB user name is john and password is fortheloveofallthingsholypleaseletmein1.

If I create the Login john I get an error back stating that there is already an object named john. I am guessing that when it tries to make he user for the DB with the same name as the login that is being created it sees the current one and declines.

Maybe I have this wrong and the Login has nothing to do with connecting to the DB from ODBC, I just know that when I try to connect with john and fortheloveofallthingsholypleaseletmein1 I get back "Login filed for user 'john'" and the log shows state 5 (invalid userid). But when I created a login (johnlogin) for the server it created a user (johnlogin) for the DB that I was able to use to make a connection.

How do I make a login john and have it associate with user john that already has the permissions that are needed and not have to change the password so that it won't need to be changed on a lot of machines and in other apps that are using it?

Thanks for your help!
Aug 6 '10 #1

✓ answered by Jerry Winston

I think I might have a solution for you. If you take a look at the script SSMS attempts to execute to create the login John, it contains both a CREATE LOGIN statement as well as a CREATE USER statement when you choose 'map to database'. The trick is to create the login john without mapping it to your restored database. Once the unmapped login John is created, you can connect it to database users using the following code.
Expand|Select|Wrap|Line Numbers
  1. USE [basedata]
  2. ALTER USER john WITH LOGIN = john
  3.  
Although the code looks very straightforward, you won't be able to run this on all SQL2005 servers. This will work only for those with SP2+ installed.

4 2147
NeoPa
32,556 Expert Mod 16PB
You don't say, but I'm getting that you are not seeing the existing user ID John when you look in the list. Is that right?
Aug 7 '10 #2
Correct, after restore the DB, we will call it basedata, has all the old users, including john.

However there are no logins for any of the old users, including john.

If I make a new login then it will make a new user of the same name and those work fine for connecting and everything is shiny.

Is there a process I can use to make a newjohn get all permissions and table ownerships of john, then kill john, bury the body, and recreate john and pass the securables and ownerships back to the remade john from newjohn? Or will that create other issues that I am not seeing? Maybe just rename john to oldjohn and make a new john and move permissions from oldjohn to new john?

Thanks for your help.
Aug 7 '10 #3
NeoPa
32,556 Expert Mod 16PB
I'm not sure how you could do much with the old John Login if it doesn't get displayed anywhere. Rename or delete would both require you to have access to it in the first place which, from my understanding, is what you don't have and which is the fundamental cause of your issues.

For the record, on my SQL 2005 server the Logins are stored under the server as :
{Server} / Security / Logins

Both the SQL Server and your local PC need to be members of the same security domain.
Aug 9 '10 #4
Jerry Winston
145 Expert 100+
I think I might have a solution for you. If you take a look at the script SSMS attempts to execute to create the login John, it contains both a CREATE LOGIN statement as well as a CREATE USER statement when you choose 'map to database'. The trick is to create the login john without mapping it to your restored database. Once the unmapped login John is created, you can connect it to database users using the following code.
Expand|Select|Wrap|Line Numbers
  1. USE [basedata]
  2. ALTER USER john WITH LOGIN = john
  3.  
Although the code looks very straightforward, you won't be able to run this on all SQL2005 servers. This will work only for those with SP2+ installed.
Aug 10 '10 #5

Sign in to post your reply or Sign up for a free account.

Similar topics

2
by: Bennett Haselton | last post by:
I'm looking for a PHP tutorial that specializes in how to build sites that are based around user logins. i.e. the user logs in on the front page, and are taken to a main login page where fields on...
3
by: Joey Lee | last post by:
Hi, Does anyone knows how to control user login that only a single userid can login at a time? Thanks Joey
4
by: 2good2b | last post by:
Hi Everyone, Do you have a place where i can find an example for a PHP system that uses secure user login (e.g. web based mail application etc) Thanks
15
by: bb nicole | last post by:
The company profile showed blank after user login and click the company profile button. Supposed the company profile should not be blank and will show the company information which call from...
3
by: freee8896 | last post by:
Can nyone help me with this multi user login from the same system. Multiple users must be able to login from the same system at a time.... in PHP. Sessions must be used. Please donot suggest these...
2
by: antonyliu2002 | last post by:
I am testing ASP.NET 2.0 Forms athentication with user credentials in SQL Server 2005. I don't want to put user credentials in web.config, so the credentials section is commented out. The...
3
by: thiago777 | last post by:
What is the best/most correct way of starting an application without the need of login in (after windows startup)? I found some options on the net: 1. Insert on...
22
by: klenwell | last post by:
I'm in the process of refactoring the php code base I've amassed over the last few years into an object-oriented framework. I'm about to start in on the authentication/login extension and I've...
12
by: tvnaidu | last post by:
I have Two kinds of web pagess, one is for control page for only admin login, another one is to view status for user login. initially both html files can view with 192.168.0.10/control.htm and other...
1
by: munkee | last post by:
I have modified Richard Rensel's Security Demo 2000 in order to produce a custom user login system. One of the aspects which I am succesfully using is the basic user grouping level: Access ID -...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
1
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.