"net use" in SDAC

Discussion of open issues, suggestions and bugs regarding SDAC (SQL Server Data Access Components) for Delphi, C++Builder, Lazarus (and FPC)
Post Reply
LHSoft
Posts: 104
Joined: Sat 18 Aug 2012 08:33

"net use" in SDAC

Post by LHSoft » Sat 16 May 2015 12:34

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

azyk
Devart Team
Posts: 1057
Joined: Fri 11 Apr 2014 11:47
Location: Alpha Centauri A

Re: "net use" in SDAC

Post by azyk » Tue 19 May 2015 13:07

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'

LHSoft
Posts: 104
Joined: Sat 18 Aug 2012 08:33

Re: "net use" in SDAC

Post by LHSoft » Wed 20 May 2015 13:11

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.

LHSoft
Posts: 104
Joined: Sat 18 Aug 2012 08:33

Re: "net use" in SDAC

Post by LHSoft » Sat 23 May 2015 08:50

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

azyk
Devart Team
Posts: 1057
Joined: Fri 11 Apr 2014 11:47
Location: Alpha Centauri A

Re: "net use" in SDAC

Post by azyk » Mon 25 May 2015 08:23

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.

Post Reply