Sunday, February 19, 2012

Different Date Formats when using xp_cmdshell

Hi all,
If I use the TSQL command:-
EXEC master.dbo.xp_cmdshell 'dir /a/od c:\*.*'
What determines the date format from of the output? I have 2 PC's (XP and
W2K) both with the same regional settings (DMY), both giving the same date
format output (DMY) for the dir command in a command window, but giving
different date formats with the above command.
I've tried changing the regional settings in the CP and also using the
DATEFORMAT command but the nothing changes the date format of the output.
I want to make sure the command returns the same format regardless of the
database, country or anyother SQL option/setting.
Thanks in advance.
Greg
greghines@.bigfoot.com.NOSPAM
Remove NOSPAM when replyingWho is logged into the machine in each case? What account is SQL Server
running under? What windows user is issuing the command?
The only way you can expect the output to be consistent is to be sure that
regional settings on all machines are identical, as are the regional
settings of all system accounts (e.g. the one SQL Server runs under) and all
accounts that may be logged in at the time the command is run.
A
"Greg Hines" <greghines@.bigfoot.com.NOSPAM> wrote in message
news:_PP9f.162$_j6.6553@.nnrp1.ozemail.com.au...
> Hi all,
> If I use the TSQL command:-
> EXEC master.dbo.xp_cmdshell 'dir /a/od c:\*.*'
> What determines the date format from of the output? I have 2 PC's (XP and
> W2K) both with the same regional settings (DMY), both giving the same date
> format output (DMY) for the dir command in a command window, but giving
> different date formats with the above command.
> I've tried changing the regional settings in the CP and also using the
> DATEFORMAT command but the nothing changes the date format of the output.
> I want to make sure the command returns the same format regardless of the
> database, country or anyother SQL option/setting.
> Thanks in advance.
> Greg
>
> --
> greghines@.bigfoot.com.NOSPAM
> Remove NOSPAM when replying
>|||The only logged in user in both cases is sa.
Account for both is dbo
It's not a windows user it's sa. Both use only SQL Authentication.
As I said the regional settings are the same. Proven by the fact that the
dir command in a command window gives the same date format on both PCs.
Greg
--
greghines@.bigfoot.com.NOSPAM
Remove NOSPAM when replying
"Aaron Bertrand [SQL Server MVP]" <ten.xoc@.dnartreb.noraa> wrote in message
news:e%23Zf2Ay3FHA.696@.TK2MSFTNGP09.phx.gbl...
> Who is logged into the machine in each case? What account is SQL Server
> running under? What windows user is issuing the command?
> The only way you can expect the output to be consistent is to be sure that
> regional settings on all machines are identical, as are the regional
> settings of all system accounts (e.g. the one SQL Server runs under) and
all
> accounts that may be logged in at the time the command is run.
> A
>
> "Greg Hines" <greghines@.bigfoot.com.NOSPAM> wrote in message
> news:_PP9f.162$_j6.6553@.nnrp1.ozemail.com.au...
and
date
output.
the
>|||> The only logged in user in both cases is sa.
You can't be logged into Windows as sa. Believe it or not, this user may
have a bearing on how dir returns results.
Also, SQL Server is either running as a specific Windows user, or the "local
system" account. The service itself does not run as dbo or sa -- Windows
has absolutely no idea what those mean.
A

No comments:

Post a Comment