I can set up linked servers with various login mappings for different users.
But sometimes I need a login to be mapped differently depending where I am using it.
e.g. for scheduled jobs that use linked servers I might want to map the SQL Server Agent login to different remote users depending on the job, to make sure I am using the minimum permissions necessary on the remote server.
Currently I do this by setting up separate linked servers for each usage, to the same actual server but with different login mappings. I can't help feeling there must be a better way though. It means I have a proliferation of linked servers.
In effect I want to be able to specify the login to map to at runtime (or at least compile time). The actual passwords can still be held at the server level; obviously I wouldn't want these in the code.
How do other people handle this problem?