I have a Sql Server that uses Windows Authentication.
I want to connect to the server from a Delphi application.
By default, SQL Server will assume the credentials of the user that launches the connecting process.
This means that to change the login, I currently have two options:
-
Log off and Log in as the desired
user, then run my application -
Launch the program from the command
line using the RUNAS command.
I’d like to let the user provide credentials from within the application, and log in as that user. Is this possible, either by manipulating the ConnectionString or by programatically changing the user of the current process?
The closest I’ve found is this entry, which tells me how to launch another process under specific credentials. I could use that technique to create a “launcher” program that launches the connecting process after gathering credentials from the user, but I’d really like something cleaner.
I’m using Delphi 2010 for this project.
Thanks
I think a combination of
LogonUserand thenImpersonateLoggedOnUserwill do the trick for you. That should change the user account for which the current process is running. As gbn mentioned, you will likely have to disconnect any active connection before changing the logon credentials.