Showing posts with label scheduled. Show all posts
Showing posts with label scheduled. Show all posts

Tuesday, March 20, 2012

Active Script OK But Scheduled Job Fails

I have an ActiveX Script task in a DTS package which executes fine
within DTS.
However, if I run it as a sheduled job, it fails with a 'path not
found error'. I've cut the code down to the approriate problem and
posted it here, it just makes a simple text file with a name derived
from the current date and time and puts 'Hello World' in the file
although in reality I go on to make an xml file. (make sure your path
exists before you execute it). Why does the scheduled job not execute
this simple task. I have loads of other jobs that run packages to a
schedule and the account is a domain account with windows
administrative rights.

'******************************
' Visual Basic ActiveX Script
'**********************

Const strPath="d:\xml"

Private Function GetDateTime()
Dim strNow, stryear, strMonth, strDay, strTime
strNow = Now
stryear = Mid(strnow, 7, 4)
strMonth = Mid(strnow, 4, 2)
strDay = Left(strnow, 2)
strTime = Replace(Mid(strnow, 12, 8), ":", "")

GetDateTime = stryear + strMonth + strDay + strTime
End Function

Function Main()
Dim fso,f,MyFile 'file objects
Set fso = CreateObject("Scripting.FileSystemObject")
dim strRightNow
strRightNow=GetDateTime()
Set MyFile= fso.CreateTextFile(strPath &"\" & "UPD-"
& strRightNow & ".txt", True) 'This line fails from a scheduled job
MyFile.WriteLine("Hello World")
MyFile.Close
Main = DTSTaskExecResult_Success
End Function

'Error Source= Microsoft VBScript runtime error Error Description:
Path not found Error on Line 25"TiredOfSpam" <spam@.drmcl.free-online.co.uk> wrote in message
news:403767a1.0410080148.b529ff@.posting.google.com ...
>I have an ActiveX Script task in a DTS package which executes fine
> within DTS.
> However, if I run it as a sheduled job, it fails with a 'path not
> found error'. I've cut the code down to the approriate problem and
> posted it here, it just makes a simple text file with a name derived
> from the current date and time and puts 'Hello World' in the file
> although in reality I go on to make an xml file. (make sure your path
> exists before you execute it). Why does the scheduled job not execute
> this simple task. I have loads of other jobs that run packages to a
> schedule and the account is a domain account with windows
> administrative rights.
> '******************************
> ' Visual Basic ActiveX Script
> '**********************
> Const strPath="d:\xml"
> Private Function GetDateTime()
> Dim strNow, stryear, strMonth, strDay, strTime
> strNow = Now
> stryear = Mid(strnow, 7, 4)
> strMonth = Mid(strnow, 4, 2)
> strDay = Left(strnow, 2)
> strTime = Replace(Mid(strnow, 12, 8), ":", "")
> GetDateTime = stryear + strMonth + strDay + strTime
> End Function
> Function Main()
> Dim fso,f,MyFile 'file objects
> Set fso = CreateObject("Scripting.FileSystemObject")
> dim strRightNow
> strRightNow=GetDateTime()
> Set MyFile= fso.CreateTextFile(strPath &"\" & "UPD-"
> & strRightNow & ".txt", True) 'This line fails from a scheduled job
> MyFile.WriteLine("Hello World")
> MyFile.Close
> Main = DTSTaskExecResult_Success
> End Function
> 'Error Source= Microsoft VBScript runtime error Error Description:
> Path not found Error on Line 25

Assuming that D: is a local drive (ie. not mapped to a network share), I can
reproduce your error using the code sample, but I have no idea what the
solution is. Usually, this comes down to a problem of ownership and/or
permissions:

http://support.microsoft.com/?kbid=269074

However, even with both the package and the job owned by the same account (I
tried using both sa and a domain admin account in the sysadmin role), and
with the NTFS permissions of the target folder set to allow Everyone to
create a new file, the scheduled job still failed.

You might want to post this in microsoft.public.sqlserver.dts - you may get
a more useful answer there.

Simon

Monday, March 19, 2012

Active Directory, Terminated Employees

Hello, we have scheduled a nightly refresh into an Employees table in a
database, that receives data from Active Directory. AD is the "authority" o
f
who is an active employee and frees us from manual maintenance of the
Employees table in our DB. However, we want to store information on
employees who resign, retire etc. and don't want orphaned records (this is a
training database storing information on what employees take what classes,
with dates and costs). I'd like to set up some kind of append query but
unlike Access, SQL would not let me append duplicate records. The database
has a termination date field also. Any suggestions would be appreciated.
Thanks, Pancho.Do you want only one row per employee, or one for every change in the
employee data?
Are you only updating the termination date from AD, or are you loading all
of the employee data from AD?
Please include DDL and more detail.
(explained here)
http://www.aspfaq.com/etiquette.asp?id=5006
"Pancho" <Pancho@.discussions.microsoft.com> wrote in message
news:4FBC26F2-F086-4734-8A2B-06CC11525F36@.microsoft.com...
> Hello, we have scheduled a nightly refresh into an Employees table in a
> database, that receives data from Active Directory. AD is the "authority"
of
> who is an active employee and frees us from manual maintenance of the
> Employees table in our DB. However, we want to store information on
> employees who resign, retire etc. and don't want orphaned records (this is
a
> training database storing information on what employees take what classes,
> with dates and costs). I'd like to set up some kind of append query but
> unlike Access, SQL would not let me append duplicate records. The
database
> has a termination date field also. Any suggestions would be appreciated.
> Thanks, Pancho.|||Jim,
We only want one row per employee. To the table structure depicted in the
script below I would ideally like to add a date/time column named TermDate.
If empty the employee would be still active.
Thank you for the etiquette link. The programmer kept default length 255's
on varchars. In reality our EmpNumbers are only 3-4 characters, not 50. In
our employee population, we have some employees who leave to go to college
and then return, and we typically preserve their old employee number, and
reactivate it when they return.
if exists (select * from dbo.sysobjects where id =
object_id(N'[dbo].[Employees]') and OBJECTPROPERTY(id, N'IsUserTable') = 1)
drop table [dbo].[Employees]
GO
CREATE TABLE [dbo].[Employees] (
[FullName] [varchar] (255) COLLATE SQL_Latin1_General_CP1_CI_AS NOT NULL ,
[LName] [varchar] (255) COLLATE SQL_Latin1_General_CP1_CI_AS NULL ,
[FName] [varchar] (255) COLLATE SQL_Latin1_General_CP1_CI_AS NULL ,
[Extension] [varchar] (255) COLLATE SQL_Latin1_General_CP1_CI_AS NULL ,
[Description] [varchar] (255) COLLATE SQL_Latin1_General_CP1_CI_AS NULL ,
[EmpNumber] [varchar] (50) COLLATE SQL_Latin1_General_CP1_CI_AS NULL ,
[Email] [varchar] (255) COLLATE SQL_Latin1_General_CP1_CI_AS NULL ,
[Company] [varchar] (255) COLLATE SQL_Latin1_General_CP1_CI_AS NULL ,
[Department] [varchar] (255) COLLATE SQL_Latin1_General_CP1_CI_AS NULL
) ON [PRIMARY]
GO
"Jim Underwood" wrote:

> Do you want only one row per employee, or one for every change in the
> employee data?
> Are you only updating the termination date from AD, or are you loading all
> of the employee data from AD?
> Please include DDL and more detail.
> (explained here)
> http://www.aspfaq.com/etiquette.asp?id=5006
>
> "Pancho" <Pancho@.discussions.microsoft.com> wrote in message
> news:4FBC26F2-F086-4734-8A2B-06CC11525F36@.microsoft.com...
> of
> a
> database
>
>|||OK, so you need to add a column to your table:
alter table [dbo].[Employees]
add TerminationDate datetime;
Then you need to update this table on a periodic basis? I have not worked
much with AD in SQL Server, but lets assume you are connected and querying
AD as you would a table. We'll call the "table" ADEmpData, and assume it
has EmpNumber and TerminationDate as columns. Also assume EmpNumber can be
duplicated in AD, but it is the PK (or at least unique) in the Employees
table. If you can explain how you are connecting to AD, someone may be able
to provide more complete code.
Update Employees as Emp
set Emp.TerminationDate = (
select top 1 AD.TerminationDate
from ADEmpData as AD
Where AD.EmpNumber = Emp.EmpNumber
order by AD.TerminationDate
-- the above added just to give consistent results with TOP
)
and exists (select 1
from ADEmpData as AD
Where AD.EmpNumber = Emp.EmpNumber)
-- exists used to only attempt to update values if the emp
-- exists in AD
Note that AD may store term date as a string, not a date type, so you may
have to do some conversion here.
"Pancho" <Pancho@.discussions.microsoft.com> wrote in message
news:79A765A9-80AE-4B80-BD4F-106AB1CB636C@.microsoft.com...
> Jim,
> We only want one row per employee. To the table structure depicted in the
> script below I would ideally like to add a date/time column named
TermDate.
> If empty the employee would be still active.
> Thank you for the etiquette link. The programmer kept default length
255's
> on varchars. In reality our EmpNumbers are only 3-4 characters, not 50.
In
> our employee population, we have some employees who leave to go to college
> and then return, and we typically preserve their old employee number, and
> reactivate it when they return.
> if exists (select * from dbo.sysobjects where id =
> object_id(N'[dbo].[Employees]') and OBJECTPROPERTY(id, N'IsUserTable') =
1)
> drop table [dbo].[Employees]
> GO
> CREATE TABLE [dbo].[Employees] (
> [FullName] [varchar] (255) COLLATE SQL_Latin1_General_CP1_CI_AS NOT NULL ,
> [LName] [varchar] (255) COLLATE SQL_Latin1_General_CP1_CI_AS NULL ,
> [FName] [varchar] (255) COLLATE SQL_Latin1_General_CP1_CI_AS NULL ,
> [Extension] [varchar] (255) COLLATE SQL_Latin1_General_CP1_CI_AS NULL ,
> [Description] [varchar] (255) COLLATE SQL_Latin1_General_CP1_CI_AS NULL ,
> [EmpNumber] [varchar] (50) COLLATE SQL_Latin1_General_CP1_CI_AS NULL ,
> [Email] [varchar] (255) COLLATE SQL_Latin1_General_CP1_CI_AS NULL ,
> [Company] [varchar] (255) COLLATE SQL_Latin1_General_CP1_CI_AS NULL ,
> [Department] [varchar] (255) COLLATE SQL_Latin1_General_CP1_CI_AS NULL
> ) ON [PRIMARY]
> GO
>
> "Jim Underwood" wrote:
>
all
a
"authority"
(this is
classes,
but
appreciated.|||Jim,
This is good information and I appreciate the detail. This will probably
work here. Have a nice wend! Pancho.
"Jim Underwood" wrote:

> OK, so you need to add a column to your table:
> alter table [dbo].[Employees]
> add TerminationDate datetime;
> Then you need to update this table on a periodic basis? I have not worked
> much with AD in SQL Server, but lets assume you are connected and querying
> AD as you would a table. We'll call the "table" ADEmpData, and assume it
> has EmpNumber and TerminationDate as columns. Also assume EmpNumber can b
e
> duplicated in AD, but it is the PK (or at least unique) in the Employees
> table. If you can explain how you are connecting to AD, someone may be ab
le
> to provide more complete code.
> Update Employees as Emp
> set Emp.TerminationDate = (
> select top 1 AD.TerminationDate
> from ADEmpData as AD
> Where AD.EmpNumber = Emp.EmpNumber
> order by AD.TerminationDate
> -- the above added just to give consistent results with TOP
> )
> and exists (select 1
> from ADEmpData as AD
> Where AD.EmpNumber = Emp.EmpNumber)
> -- exists used to only attempt to update values if the emp
> -- exists in AD
> Note that AD may store term date as a string, not a date type, so you may
> have to do some conversion here.
> "Pancho" <Pancho@.discussions.microsoft.com> wrote in message
> news:79A765A9-80AE-4B80-BD4F-106AB1CB636C@.microsoft.com...
> TermDate.
> 255's
> In
> 1)
> all
> a
> "authority"
> (this is
> classes,
> but
> appreciated.
>
>|||Glad if I could help.
Please remember to post your final solution so others who have a similar
issue will be able to learn from it.
Also, I am interested in seeing how you handle the AD connection. Thus far
I have only done it via VB.Net and have not connected via SQL Server.
"Pancho" <Pancho@.discussions.microsoft.com> wrote in message
news:84DA9C84-4201-4766-9ADC-FD74F3EB5DED@.microsoft.com...
> Jim,
> This is good information and I appreciate the detail. This will probably
> work here. Have a nice wend! Pancho.
> "Jim Underwood" wrote:
>
worked
querying
it
be
able
may
the
50.
college
and
=
NULL ,
,
NULL ,
the
loading
in
the
on
query|||We use a scheduled DTS package to import a .csv file. The .csv file is
exported nightly using a scheduled .bat file that calls a .vbs script that
performs the export from AD. We're not going to implement the TermDate just
yet but I will post the outcome when we do. Thanks again, P.
"Jim Underwood" wrote:

> Glad if I could help.
> Please remember to post your final solution so others who have a similar
> issue will be able to learn from it.
> Also, I am interested in seeing how you handle the AD connection. Thus fa
r
> I have only done it via VB.Net and have not connected via SQL Server.
>
> "Pancho" <Pancho@.discussions.microsoft.com> wrote in message
> news:84DA9C84-4201-4766-9ADC-FD74F3EB5DED@.microsoft.com...
> worked
> querying
> it
> be
> able
> may
> the
> 50.
> college
> and
> =
> NULL ,
> ,
> NULL ,
> the
> loading
> in
> the
> on
> query
>
>|||You might check out microsoft.public.active.directory.interfaces to see if
you can use a more direct approach. I believe SQL Server allows you to
query AD directly, which could eliminate the need for the VBS, BAT, CSV,
etc. I do not know how much is implemented in 2000 VS 2005, but I think I
have seen some examples in this forum.
"Pancho" <Pancho@.discussions.microsoft.com> wrote in message
news:931B3577-C055-4184-AEF5-AC0D22D9652E@.microsoft.com...
> We use a scheduled DTS package to import a .csv file. The .csv file is
> exported nightly using a scheduled .bat file that calls a .vbs script that
> performs the export from AD. We're not going to implement the TermDate
just
> yet but I will post the outcome when we do. Thanks again, P.
> "Jim Underwood" wrote:
>
far
probably
assume
can
Employees
be
you
depicted in
length
not
number,
N'IsUserTable')
NOT
,
,
NULL
NULL ,
,
NULL ,
NULL
in
table
of
information
records
what
The

Thursday, February 16, 2012

Accessing SQL Server 2005 via Scheduled Task

I have a strange problem that I think deals with security on SQL 2005.
I have a scheduled task that runs on a Windows 2000 machine. It calls
a vb script which creates a connection to SQL Server.

We migrated a database from SQL 2000 to 2005 which is on a different
box. I changed the connection in the vb script to use the new sql
server. The original connection to SQL 2000 used the 'sa' account
coded into the connection string , which we don't want to use on the
new server, so I changed the connection string in the script to use
the below login information.

Const strConnection = "Provider=SQLOLEDB;Data
Source=SQLServer;Integrated Security=SSPI;Persist Security
Info=False;Initial Catalog=database;

I created a domain user and gave it dbo rights on the new database on
SQL 2005 as well as administrative rights on the local machine and the
network. The task runs fine for a while and then it will fail to
start. I have looked in the event log as well as the SQL log and have
not found anything else that ran when my task failed. Once it has
failed, if I manually run the vb script on the 2000 machine, it runs
just fine, but the schedule won't work. If I change the name of the
user that is running the scheduled task, it will begin working again.
I have run the profiler on SQL 2005 and watched the scheduled task
login as the correct user and update the database. There is no
pattern to when the scheduled task will stop running. This has been
happening for a few days now.

This script and scheduled task worked fine for over a year on the
machine when it logged into SQL 2000 and nothing else has changed,
which makes me think it is related to the SQL 2005 server. Any ideas?Hi

"Myster Edd" <mysteredd@.gmail.comwrote in message
news:1179861414.783713.3260@.z24g2000prd.googlegrou ps.com...

Quote:

Originally Posted by

>I have a strange problem that I think deals with security on SQL 2005.
I have a scheduled task that runs on a Windows 2000 machine. It calls
a vb script which creates a connection to SQL Server.
>
We migrated a database from SQL 2000 to 2005 which is on a different
box. I changed the connection in the vb script to use the new sql
server. The original connection to SQL 2000 used the 'sa' account
coded into the connection string , which we don't want to use on the
new server, so I changed the connection string in the script to use
the below login information.
>
Const strConnection = "Provider=SQLOLEDB;Data
Source=SQLServer;Integrated Security=SSPI;Persist Security
Info=False;Initial Catalog=database;
>
I created a domain user and gave it dbo rights on the new database on
SQL 2005 as well as administrative rights on the local machine and the
network. The task runs fine for a while and then it will fail to
start. I have looked in the event log as well as the SQL log and have
not found anything else that ran when my task failed. Once it has
failed, if I manually run the vb script on the 2000 machine, it runs
just fine, but the schedule won't work. If I change the name of the
user that is running the scheduled task, it will begin working again.
I have run the profiler on SQL 2005 and watched the scheduled task
login as the correct user and update the database. There is no
pattern to when the scheduled task will stop running. This has been
happening for a few days now.
>
This script and scheduled task worked fine for over a year on the
machine when it logged into SQL 2000 and nothing else has changed,
which makes me think it is related to the SQL 2005 server. Any ideas?
>


I assume that the task worked fine when you profiled it on the SQL 2005
server? Have you run a server side trace to trap this being run when it
fails?
How often does this task run?
As this sounds like a windows scheduled task are you using SQL Express?
Have you installed any service packs on the SQL Server (SELECT @.@.VERSION)?
Does the schedule run on a different machine to the server?
Do you run AV or IDS software on the database server?

John