Please start any new threads on our new
site at https://forums.sqlteam.com. We've got lots of great SQL Server
experts to answer whatever question you can come up with.
Author |
Topic |
DeniseGoodheart
Starting Member
12 Posts |
Posted - 2009-04-27 : 17:29:55
|
Good Day:I am creating a VB.NET WinForms application using VS.NET 2005 and SQL Sever 2000. The IT department moved the TestDB database to a new server. My problem is that none of the users can make a connection to the TestDB database. I can successfully log in using the default SA login. I can see all the users on the SQL Server Users panel, but the users cannot log in. If a user tries to log in from the VB.NET application; an error message reads: Login failed. I also tried running the Login scripts with no success. I tried copying the .mdf file from TestDB Server,1 but I get a message that says the database is in use, so this is not an option because it is always in use. The TestDB was originally on Server1. All the users could successfully access the database TestDB on Server1. Now the database TestDB Server1 backup was loaded on to TestDB Server2. I can see all the users on the SQL Server Users panel for TestDB Server2, but the users cannot log in.I use a DSNless connection string which means I do not have to install an ODBC on each users computer. I simply change the DSN connection string to point to Server2 TestDB instead of Sever 1 TestDB.SQL Server security authentication is set to mixed mode, so this is not the problem.I was able to successfully login after doing the following, but unfortunately it did not work for the other users.sp_password @new = 'wings', @loginame = 'Denise'Any Suggestions?Denise |
|
tkizer
Almighty SQL Goddess
38200 Posts |
|
DeniseGoodheart
Starting Member
12 Posts |
Posted - 2009-04-29 : 12:21:05
|
testquote: Originally posted by DeniseGoodheart Good Day:I am creating a VB.NET WinForms application using VS.NET 2005 and SQL Sever 2000. The IT department moved the TestDB database to a new server. My problem is that none of the users can make a connection to the TestDB database. I can successfully log in using the default SA login. I can see all the users on the SQL Server Users panel, but the users cannot log in. If a user tries to log in from the VB.NET application; an error message reads: Login failed. I also tried running the Login scripts with no success. I tried copying the .mdf file from TestDB Server,1 but I get a message that says the database is in use, so this is not an option because it is always in use. The TestDB was originally on Server1. All the users could successfully access the database TestDB on Server1. Now the database TestDB Server1 backup was loaded on to TestDB Server2. I can see all the users on the SQL Server Users panel for TestDB Server2, but the users cannot log in.I use a DSNless connection string which means I do not have to install an ODBC on each users computer. I simply change the DSN connection string to point to Server2 TestDB instead of Sever 1 TestDB.SQL Server security authentication is set to mixed mode, so this is not the problem.I was able to successfully login after doing the following, but unfortunately it did not work for the other users.sp_password @new = 'wings', @loginame = 'Denise'Any Suggestions?Denise
|
|
|
DeniseGoodheart
Starting Member
12 Posts |
|
DeniseGoodheart
Starting Member
12 Posts |
Posted - 2009-04-29 : 12:29:18
|
Hello,I am still figuring out this site and this is why there are repeat postings; sorry. There is no delete post.I thought I posted this yesterday, but I do not see it here, so I'll post it again. I tried what you recommended with no success. I wonder if it is hopeless at this point.The following are all the things I tried with no success:----In that case, you should be able to remap db user to sql login with sp_change_users_login.-----------------------------------------------------------use this script if you don't want to bother with double-checking your usernames. ----just run it under the database that you believe has orphans. set nocount on select 'sp_change_users_login ''update_one'', ''' + name + ''', ''' + name + '''' + char(10) + 'go' + char(10)from sysusers where name not like 'db_%' and name not like 'public' and name not like 'guest' -----------------------------------------------------------------------------------better yet... here is a script which will produce the sp_change_users_login code for all --databases on the server. use master go set nocount on select 'use ' + name +char(10) + 'go ' + char(10) + 'print ''Database: ' + name + '''' + char(10)+ 'go ' + char(10) + 'select ''sp_change_users_login ''''update_one'''', '''' + name + '''','''' + name + '''' + char(10) + ''''go'''' from sysusers where name not like ''''db_%'''' and name not like ''''public'''' and name not like ''''guest'''' + char(10) + ''''go''''' from sysdatabases -----------------------------------------------------------------------SQLTeam.comsp_change_users_login does not allow modifications to dbo, INFORMATION_SCHEMA, or sys logins. Try adding this code to your sp_change_users_login proc:/*Script to fix orphans when moving db to another server.Note: Auto_fix option will create a SQL login id if necessary.Note: Update_one option will NOT create a SQL login.Note: Report option reports on sql login vs user login mismatches.*/SET NOCOUNT ONDECLARE @UserName nvarchar(128),@MissingUsers varchar(4000),@cmd varchar(1000)-- Re-sync user ids to master databaseSET @UserName = ''WHILE @UserName IS NOT NULLBEGINIF @UserName IS NOT NULLBEGINSELECT @UserName = min(a.name)FROM sysusers AS aWHERE a.name > @UserName and IsSQLRole = 0AND name NOT IN('dbo','guest', 'INFORMATION_SCHEMA', 'sys')-- Add this check for domain accounts -- They do not need synced with the master databaseIF (SELECT CHARINDEX('\',@UserName) )= 0BEGINSET @cmd = 'sp_change_users_login ''update_one'', ''' + @UserName + ''', ''' + @UserName + ''''EXEC(@cmd)END---I get errors when I run the script above:-- Server: Msg 156, Level 15, State 1, Line 3--Incorrect syntax near the keyword 'not'.--Server: Msg 170, Level 15, State 1, Line 38--Line 38: Incorrect syntax near 'END'.---------------------------------------------------------------------------- --SQLTeam.com/*************************************************************************************This procedure should be created in the Master database. This procedure takes no parameters. It will remap orphaned users in the current database to EXISTING loginsof the same name. This is usefull in the case a new database is created by restoringa backup to a new database, or by attaching the datafiles to a new server. *************************************************************************************/IF OBJECT_ID('dbo.sp_fixusers') IS NOT NULLBEGINDROP PROCEDURE dbo.sp_fixusersIF OBJECT_ID('dbo.sp_fixusers') IS NOT NULLPRINT '<<< FAILED DROPPING PROCEDURE dbo.sp_fixusers >>>'ELSEPRINT '<<< DROPPED PROCEDURE dbo.sp_fixusers >>>'ENDGOCREATE PROCEDURE dbo.sp_fixusersASBEGINDECLARE @username varchar(25)DECLARE fixusers CURSOR FORSELECT UserName = name FROM sysusersWHERE issqluser = 1 and (sid is not null and sid <> 0x0)and suser_sname(sid) is nullORDER BY nameOPEN fixusersFETCH NEXT FROM fixusersINTO @usernameWHILE @@FETCH_STATUS = 0BEGINEXEC sp_change_users_login 'update_one', @username, @usernameFETCH NEXT FROM fixusersINTO @usernameENDCLOSE fixusersDEALLOCATE fixusersENDgoIF OBJECT_ID('dbo.sp_fixusers') IS NOT NULLPRINT '<<< CREATED PROCEDURE dbo.sp_fixusers >>>'ELSEPRINT '<<< FAILED CREATING PROCEDURE dbo.sp_fixusers >>>'go---Output Message:---<<< CREATED PROCEDURE dbo.sp_fixusers >>>----------------------------------------------------------------------------------sp_change_users_login 'report'--Output----No users display--------------------------------------------------------------------- |
|
|
tkizer
Almighty SQL Goddess
38200 Posts |
|
|
|
|
|
|