Fix all orphaned users in a database

  • Comments posted to this topic are about the item Fix all orphaned users in a database

  • I ran the piece of code published under the title: "Fix all orphaned users in a database". It came back with a number of syntax errors. I fiddled with it and managed to run it. The environment I am using Windows 2008 R2 Server, SQL Server 2008 R2. And this is not the first time happening that SQLServerCentral.com publishes "bugy" codes. It would be nice that scripts or solutions published on the SQLServerCentral.com are debugged before publication.

    regards

    Julien

    PS: The majority of the SQL Server solutions are good and I got a lot of help in taking many of these ideas into my solution. Only those are the annoying minorities...

  • Thanks for the code! I've been using a script created by Gregory A. Larsen which I have modified to better suite my needs.

    As for "buggy" code. Sometime we write scripts that work well in our own environments and it may not run properly in others. This is not the responsibility of this site to see if ALL the code provide works perfectly. It would take them too long and need more staff to verify everything.

    Here is my recommendation. Use the scripts and modify it to suite your environment. It's free so really you can't complain. As a good DBA, you should try to modify the code so that 1) you better understand it, 2) you make it personalized to your environment and 3) you can help by provide your code here for others to see.

    If you don't like the script you can also rate it here. You can even submit your own code/articles for others to see and criticize. It's not easy publishing anything as you will always find someone who hates it.

    Thanks to everyone who submits code, articles, and help as these things make this site the best in the SQL world!

    Just my 2 cents worth.

    Rudy

    Rudy

  • thanks rudy

  • @julien : i ran the script on sql server 2008, worked fine for me.

  • No thanks needed as I'm not defending anyone. One thing I don't mention is that when submitting code the author should do his/her best to ensure that it is working.

    Now back the this code. Your script will re add users that are orphaned but what if they don't exist? Would your script remove them from the database?

    I would modify your script so that it checks if the login exists. If not it should be removed from the database.

    Thanks,

    Rudy

    Rudy

  • It would be helpful if the Author added comments to the article and code, including what version he/she created this on and on what versions it is known to work. In this case its a pretty simple script, yet what [font="System"]sp_change_users_login [/font]does and how it works is still kind of vague. Of course I can google it, but it would be good if the Author addressed that, since its the backbone of the script.

    BTW... msdn states that [font="System"]sp_change_users_login [/font]will not be used in future releases and advises not to include in new dev work

  • Good points Patrick

    Rudy

  • I use Mike Tutor's script. If someone interested it's here:

    http://www.sqlservercentral.com/scripts/users/69523/

    --Vadim R.

  • Patrick2525 (11/24/2010)


    It would be helpful if the Author added comments to the article and code, including what version he/she created this on and on what versions it is known to work. In this case its a pretty simple script, yet what [font="System"]sp_change_users_login [/font]does and how it works is still kind of vague. Of course I can google it, but it would be good if the Author addressed that, since its the backbone of the script.

    BTW... msdn states that [font="System"]sp_change_users_login [/font]will not be used in future releases and advises not to include in new dev work

    sp_change_users_login isn't something that you would include in your work, it is something you would use to DO your work.

    That said, if you're running 2005 SP2 or latter, you might want to use ALTER USER WITH LOGIN = .

  • Totally agree with Julien, nice when the code works out of the box. Production for me is 2003 Standard SQL 2005. I restore to 2003 Small business SQL 2005.

    My error was "Cannot assign a default value to a local variable." I changed the variable declaration to:

    DECLARE @rowCount INT

    Set @rowCount = (SELECT COUNT(1) FROM #OrphanedUsers)

    DECLARE @i INT

    SET @i =1

    DECLARE @tempUsername VARCHAR(1000)

    Once that fix was in place the code worked like a charm. I've been looking for a quick fix for my SQL users that read and write to the db through ASP.NET stored procs. So in a nut shell, thanks for the code it got me on the right track.

    Cheers,

    Graham

  • To SSC Veteran,

    Could you please read the full extent of my message in particular reference: "The majority of the SQL Server solutions are good and I got a lot of help in taking many of these ideas into my solution.", meaning for the benefit for some "good DBAs" I never use the codes published in this site strait out of the web page. Whatever strongly you feel about your point of you still should remain professional enough not even indirectly imply that who is good DBA and who is not. Among the qualities of a good DBA are accepting others' opinion and if disagree respond with professional courtesy. I don't remember that this site is for even remotely a tool to being personal. As I stated I "fiddled" with it and managed it to run. It it just happens too many too often. In the other day it happened the same with a piece of code (it was a function) which was supposed to return the date of the first day of the week. It in its original code had two bugs:

    1./ It returned consistently Tuesday as the first day of the week. I am aware of it that in some country Sunday is the first day of the new week in others is Monday. I newer heard of Tuesday being the first. If there such a calendar or country which uses Tuesday as the first day of the week please someone enlighten me about it.

    2./ When I entered as a parameter the date of Monday it returned the previous week's Tuesday the result even after fixing the above Tuesday issue. The bug was in the original code not my fix introduced it. I fixed this as well and I am happily using it in my project to develop a database application.

    And there was a period of a few weeks in early this year when unfortunately the majority of the published solutions and codes did not even work and found them so hopless after trying to fix them that I gave up to invest more afford in them. There were some SSIS solutions of which one of them the code and samples were published in an image format not web page text box and instead of the images on the page placeholders were displayed. SQLServerCentral.com is a trusted site in our web server firewall.

    And all the others who might directly or indirectly questioning my quality as DBA this is my reply. All my apology to the millions of genuinely professional DBAs and SQL Server developers who are like me registered members of SQLServerCentral.com community have to have to read this. Finally I did not change my opinion that crashing codes should not be published.

    Julien.

  • To SSC Veteran,

    Could you please read the full extent of my message in particular reference: "The majority of the SQL Server solutions are good and I got a lot of help in taking many of these ideas into my solution.", meaning for the benefit for some "good DBAs" I never use the codes published in this site strait out of the web page. Whatever strongly you feel about your point of you still should remain professional enough not even indirectly imply that who is good DBA and who is not. Among the qualities of a good DBA are accepting others' opinion and if disagree respond with professional courtesy. I don't remember that this site is for even remotely a tool to being personal. As I stated I "fiddled" with it and managed it to run. It it just happens too many too often. In the other day it happened the same with a piece of code (it was a function) which was supposed to return the date of the first day of the week. It in its original code had two bugs:

    1./ It returned consistently Tuesday as the first day of the week. I am aware of it that in some country Sunday is the first day of the new week in others is Monday. I newer heard of Tuesday being the first. If there such a calendar or country which uses Tuesday as the first day of the week please someone enlighten me about it.

    2./ When I entered as a parameter the date of Monday it returned the previous week's Tuesday the result even after fixing the above Tuesday issue. The bug was in the original code not my fix introduced it. I fixed this as well and I am happily using it in my project to develop a database application.

    And there was a period of a few weeks in early this year when unfortunately the majority of the published solutions and codes did not even work and found them so hopless after trying to fix them that I gave up to invest more effort in them. There were some SSIS solutions of which one of them the code and samples were published in an image format not web page text box and instead of the images on the page placeholders were displayed. SQLServerCentral.com is a trusted site in our web server firewall.

    And all the others who might directly or indirectly questioning my quality as DBA this is my reply. All my apology to the millions of genuinely professional DBAs and SQL Server developers who are like me registered members of SQLServerCentral.com community have to have to read this. Finally I did not change my opinion that crashing codes should not be published.

    Julien.

  • Julien Chappel,

    I'm guessing that you are referring to me when you say "To SSC Veteran".

    I'll keep my comments short.

    1) My name is not "To SSC Veteran" unless you are directing your comments to ALL SSC Veteran. If you are directing your comments, you should use their name.

    2) Not suggesting that you are a "Bad" DBA. Just noticing that Professional (top end) DBAs will take code found here or anywhere, analysis it, try it on there test servers and comment back on their findings. They don't complain about the original code but will help out in making the code work.

    3) I still stand in defense of this site and still believe that they don't have the time or man power to test every single code and/or article submitting. It should be up to the author to do their best in testing their code and ensuring accuracy of their articles. Sometimes this doesn't happen. But it's free so really why complain.

    4) Remember your options when using a script found here. Either help in making it better for everyone or don't use it.

    5) Lastly (as I don't want to make this a story) Positive and constructive comments will help make this site better and will help the author to make better contribution the next time. Help out when you can and if you can at least acknowledge that someone else has at least tried to make a contribution.

    Try submitting your own code or article, you will then see that there is always someone who doesn't like it. But that's just the way it goes. I know as I have several articles and script here.

    Thanks

    Rudy

  • Can you post that script if you have modified for Orphaned Users please?

Viewing 15 posts - 1 through 14 (of 14 total)

You must be logged in to reply to this topic. Login to reply