I'am developing a batch or script file to execute at a dos prompt.
Therefore I want to use a Windows NT user to logon to a MSSQL7 server.
I use the command:
OSQL -Scp6411nks99 -dTEST -UDOMAINX\userx
Before this command I used the stored procedure:
sp_grantlogin to grant the userx access to the SQL server
sp_grantaccess to grant the userx acces to the database TEST
But when I execute the OSQL command and enter the correct password I got a message: Login failed for user 'DOMAINX\userx'
The server is in Mixed mode.
When I log on to a workstation with the above mentioned account I can start ISQL and I can login without any problem and execute queries.
Ini order to use a trusted connection, you have to use the -E switch. This will automatically pick up the name of the user that is running the batch, and use that as the username. Using the -U switch will attempt to use SQL authentication. Hope this helps.