Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2000 Forums
 Transact-SQL (2000)
 Net Use Command

Author  Topic 

jones_d
Yak Posting Veteran

61 Posts

Posted - 2004-12-20 : 11:58:01

Hi,

I am using the net use command to map a network drive from within a stored procedure.

declare @cmd_name varchar(100)
set @cmd_name = 'net use K: \\testserver\Ftp\DATA\FIG password /user:username'

EXEC master..xp_cmdshell @cmd_name


However, I a getting the following error:

System error 1312 has occurred.
NULL
A specified logon session does not exist. It may already have been terminated.
NULL
NULL

I have tried the above command from the command prompt on the server (logged on as the same user that runs the stored procedure) and the command works fine here.

Has anyone come across this error before?

Thanks

TimS
Posting Yak Master

198 Posts

Posted - 2004-12-20 : 13:33:00
It worked OK for me.

Note: I got the error when the username account was locked out.

I used my own username so it may be when the person running the sql account is locked that got me the error.

Tim S
Go to Top of Page

Bustaz Kool
Master Smack Fu Yak Hacker

1834 Posts

Posted - 2004-12-20 : 15:41:21
When you use xp_cmdshell, you are operating in the security context of the SQL Server Service; not as yourself. Is there a chance that you have the necessary permissions but the SQL Server account does not?

HTH

=================================================================

Happy Holidays!
Go to Top of Page

jones_d
Yak Posting Veteran

61 Posts

Posted - 2004-12-21 : 05:38:43
The SQL Server Agent is running as user testsql.

When I logon to the server as testsql and run the above command using the command prompt - it works fine.

When I try to run the command using xp_cmdshell in a stored procedure I get error 1312.

Are there any permissions in particular I should check?

Thanks,
jones_d
Go to Top of Page

jen
Master Smack Fu Yak Hacker

4110 Posts

Posted - 2004-12-21 : 23:24:49
quote:

Permissions
Execute permissions for xp_cmdshell default to members of the sysadmin fixed server role, but can be granted to other users.



Important If you choose to use a Windows NT account that is not a member of the local administrator's group for the MSSQLServer service, users who are not members of the sysadmin fixed server role cannot execute xp_cmdshell.





--------------------
keeping it simple...
Go to Top of Page
   

- Advertisement -