Page 1 of 1

"net use" in SDAC

Posted: Sat 16 May 2015 12:34
by LHSoft
Hello,

for Backup I want my SQLServer to connect to a network share with Password and username (can't do that in Delphi, cause SQLServer is running as "Local System" and can not reach devices with user login of course).

This works in Management Studio with following script:

Code: Select all

EXEC sp_configure 'show advanced options', 1
RECONFIGURE
EXEC sp_configure 'xp_cmdshell', 1
RECONFIGURE
EXEC xp_cmdshell 'NET USE X: "\\Machine\Share" MyPassword /USER:MyUsername /PERSISTENT:no'

BACKUP DATABASE XY TO DISK = 'X:\test1.bak'

EXEC xp_cmdshell 'NET USE X: /delete'
EXEC sp_configure 'xp_cmdshell', 0
RECONFIGURE
EXEC sp_configure 'show advanced options', 0
RECONFIGURE
If I try to execute this script within Delphi via TMSSQL or TMSQuery, the "net use" is not successful.
Other Lines are!

Does anybody has an idea?

best regards
Hans

Re: "net use" in SDAC

Posted: Tue 19 May 2015 13:07
by azyk
Perhaps, the "net use" command for creating the X disk in your sample is executed incorrectly in xp_cmdshell. In order to understand why your sample script is not executed via TMSQuery , please clarify what result is returned by xp_cmdshell after executing "net use". For this, create a table to store the result, for example:

Code: Select all

create table output_table (output_field nvarchar(255) null)
and insert the xp_cmdshell execution result, for example:

Code: Select all

insert output_table (output_field) EXEC xp_cmdshell 'NET USE X: "\\Machine\Share" MyPassword /USER:MyUsername /PERSISTENT:no'

Re: "net use" in SDAC

Posted: Wed 20 May 2015 13:11
by LHSoft
Hello,

I'll try this tonight.

Since my first post I found, that TMSScript is doing this, but not every time. When it failes once it failes further on. I suppose SQLServer leaves some resources open, but hard to see cause its in local system context.

Re: "net use" in SDAC

Posted: Sat 23 May 2015 08:50
by LHSoft
Hello,

First it runs without Error several times
but then there appeared following Errormessages:

System Error 1312 occured.
A specified logon session does not exist. It may already have been terminated.

This error occured, if I mapped the path in user context and deleted the mapping again before executing SQL in order to check the availability or if once connecting user Windows explorer to Network path to see if backup exists.

best regards
Hans

Re: "net use" in SDAC

Posted: Mon 25 May 2015 08:23
by azyk
Glad to see you have found the reason of the problem occurring during execution of your script. If you have any questions concerning SDAC, please contact us, we will answer you.