This website uses cookies. By clicking Accept, you consent to the use of cookies. Click Here to learn more about how we use cookies.
Turn on suggestions
Auto-suggest helps you quickly narrow down your search results by suggesting possible matches as you type.
- Revenera Community
- :
- InstallShield
- :
- InstallShield Forum
- :
- Finding SQL Users
Subscribe
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Subscribe
- Mute
- Printer Friendly Page
- Mark as New
- Subscribe
- Mute
- Permalink
- Report Inappropriate Content
Jul 10, 2008
09:00 AM
Finding SQL Users
This is more of a SQL question. I have a CA that adds a SQL user. How can I tell (vail a SQL script) if a particular user already exists?
Thanks,
Ron
Thanks,
Ron
(1) Reply
- Mark as New
- Subscribe
- Mute
- Permalink
- Report Inappropriate Content
Jul 16, 2008
09:53 AM
Looking back through my old posts I thought I'd post an answer in case anyone else has a similar problem. I figured out if a user already exists by using a bat file and SQLCMD to attempt to alter a login. Something like this:
REM This bat file will attempt to alter the login.
REM The alter is bogus in that it tries to enable a login that would already be enabled.
REM If it succeeds there is no message output from SQL and we will issue a warning that the username already exists.
REM If there is a message output from SQL we will assume it is an error indicating the username does not exist, which is OK.
SET TempFile=%TEMP%\%~n0.txt
IF EXIST "%TempFile%" DEL /q "%TempFile%"
sqlcmd -E -S "YourServername" -Q "ALTER LOGIN YourName ENABLE" > "%TempFile%"
FOR /F %%A in ('TYPE "%TempFile%"') DO (
IF NOT %%A=="" GOTO :Done
)
COLOR E0
ECHO.YourUserName already exists on YourServer.
ECHO.
PAUSE
:Done
IF EXIST "%TempFile%" DEL /q "%TempFile%"
REM This bat file will attempt to alter the login.
REM The alter is bogus in that it tries to enable a login that would already be enabled.
REM If it succeeds there is no message output from SQL and we will issue a warning that the username already exists.
REM If there is a message output from SQL we will assume it is an error indicating the username does not exist, which is OK.
SET TempFile=%TEMP%\%~n0.txt
IF EXIST "%TempFile%" DEL /q "%TempFile%"
sqlcmd -E -S "YourServername" -Q "ALTER LOGIN YourName ENABLE" > "%TempFile%"
FOR /F %%A in ('TYPE "%TempFile%"') DO (
IF NOT %%A=="" GOTO :Done
)
COLOR E0
ECHO.YourUserName already exists on YourServer.
ECHO.
PAUSE
:Done
IF EXIST "%TempFile%" DEL /q "%TempFile%"
![](/skins/images/089A6DFE1F4989CB8CCC689A38D62C96/responsive_peak/images/icon_anonymous_message.png)