472,992 Members | 3,704 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,992 software developers and data experts.

Executing a job using TSQL or Stored procedure on SQL 2005 Express

I need to execute a job on a SQL Express 2005 instance (no SQLAgent).
The job will be executed manually by a user, so it doesn't need to be
scheduled to run automatically. I thought I could execute the job
through a stored procedure, but it appears that SQL Agent is necessary
even for that.

The job was given to me by a software vendor to add EDI capabilities
to an accounting package, but the assumption was made that a full
version of SQL was available.

Is there another way to execute a job on an Express instance? The job
has 4 steps. Two are just executing stored procedures, which I could
easily do via another stored procedure. But the other two steps are
Activescripting/VBScript ( @subsystem=N'ActiveScripting') and involve
creating text files and starting a ftp session to transfer them... And
that's a bit beyond me..

Thanks

Nov 21 '08 #1
2 7425
On Fri, 21 Nov 2008 00:43:10 -0500, Carlton Kirby
<ckirbyATmindspringdottcomwrote:

Jobs seem tightly related to SQLAgent. So you either upgrade, or have
someone with VBScript skills take a look at those scripts.
If a VBScript was in a file, it could be executed like this:
cscript.exe c:\my.vbs
Scripts can extract data from a SQLServer, e.g. using ADO.
You may also be able to export the data some other way, e.g. BCP.

-Tom.
Microsoft Access MVP
>I need to execute a job on a SQL Express 2005 instance (no SQLAgent).
The job will be executed manually by a user, so it doesn't need to be
scheduled to run automatically. I thought I could execute the job
through a stored procedure, but it appears that SQL Agent is necessary
even for that.

The job was given to me by a software vendor to add EDI capabilities
to an accounting package, but the assumption was made that a full
version of SQL was available.

Is there another way to execute a job on an Express instance? The job
has 4 steps. Two are just executing stored procedures, which I could
easily do via another stored procedure. But the other two steps are
Activescripting/VBScript ( @subsystem=N'ActiveScripting') and involve
creating text files and starting a ftp session to transfer them... And
that's a bit beyond me..

Thanks
Nov 21 '08 #2
So I should be able to take the text from the VBScript job step and
save it to a vbs file, then run it using the cscript.exe?
Here's the text of the Job, step 2 :


EXEC @ReturnCode = msdb.dbo.sp_add_jobstep @job_id=@jobId,
@step_name=N'OutputInvoiceExportTextFiles',
@step_id=2,
@cmdexec_success_code=0,
@on_success_action=4,
@on_success_step_id=3,
@on_fail_action=2,
@on_fail_step_id=0,
@retry_attempts=0,
@retry_interval=0,
@os_run_priority=0, @subsystem=N'ActiveScripting',
@command=N'Dim oFilesys
Dim oFiletxt
Dim sFilename
Dim strPath
Dim sFullFileName
Dim strdbConnectString
Dim dbConnection
Dim rsOutput
Dim sqlCommand
Dim strDatabaseName
Dim sqlCommandGroup
Dim rsGroup
Dim sKey
Dim sValue
Dim FsoObject
Dim strSourceFile
Dim OpenFile
Dim strInputLine

Const cForReading = 1
Const cForWriting = 2
Const cForAppending = 8

Call LoadParameters()

Public Sub LoadParameters()
Set FsoObject = CreateObject("Scripting.FileSystemObject")

strSourceFile = "C:\Program Files\TSM105\EDIConfigSettings.txt"

If (FsoObject.FileExists(strSourceFile)) Then
Set OpenFile = FsoObject.OpenTextFile(strSourceFile, cForReading)

Do Until Mid(strInputLine, 1, 15) = "[CreateInvoice]"
strInputLine = OpenFile.ReadLine
Loop

Do Until OpenFile.AtEndOfStream = "True"
strInputLine = OpenFile.ReadLine
If Mid(strInputLine, 1, 1) = "[" Then
Exit Do
End If
If Instr(strInputLine, "=") 1 Then
sKey = Ltrim(Rtrim(Left(strInputLine, instr(strInputLine,
"=") - 1)))
sValue = Ltrim(Rtrim(mid(strInputLine, instr(strInputLine,
"=") + 1, 255)))
End if

If sKey = "Path" then
strPath = sValue
ElseIf sKey = "dbConnectString" then
strdbConnectString = sValue
ElseIf sKey = "DatabaseName" then
strDatabaseName = sValue
End If
Loop

OpenFile.Close
Set FsoObject = nothing
Else
Err.Raise vbObjectError, "LoadParameters", "Error: " &
strSourceFile & " does not exist."
End If
End Sub

''set the select statement to retrieve each distinct Retailer Hub Code
sqlCommandGroup = "SELECT DISTINCT RetailerHubCode, InvcNum FROM [" +
strDatabaseName + "]..tmpEDIInvoiceExport WHERE RetailerHubCode IS NOT
NULL"

''create and open a connection to the sql server
Set dbConnection = CreateObject("ADODB.Connection")
dbConnection.Open = strdbConnectString

''open the recordset to copy into the text file
Set rsGroup = CreateObject("ADODB.Recordset")
rsGroup.Open sqlCommandGroup, dbConnection
If not (rsGroup.BOF) Then rsGroup.MoveFirst

''loop through each Retailer Hub Code
While (Not rsGroup.EOF)
''build the invoice number based file name using the Retailer
Hub Code as the file extension

sFileName = "IN" + rsGroup("InvcNum") + "." +
rsGroup("RetailerHubCode")

''combine the path and filename
sFullFileName = strPath + sFileName

''use a file system object to create a text file
Set oFilesys = CreateObject("Scripting.FileSystemObject")

Set oFiletxt = oFilesys.CreateTextFile(sFullFileName, True)

''set the select statement to retrieve all records for the
current Retailer Hub Code
sqlCommand = "SELECT CombinedFields FROM [" + strDatabaseName
+ "]..tmpEDIInvoiceExport WHERE RetailerHubCode = ''" +
rsGroup("RetailerHubCode") + "'' AND InvcNum = ''" +
rsGroup("InvcNum") + "''"

''open the recordset to copy into the text file
Set rsOutput = CreateObject("ADODB.Recordset")
rsOutput.Open sqlCommand, dbConnection
If not (rsOutput.BOF) Then rsOutput.MoveFirst

''write each record into the text file
While (Not rsOutput.EOF)
oFiletxt.Write (rsOutput("CombinedFields") + VbCrLf)
rsOutput.MoveNext
Wend

rsOutput.Close
oFiletxt.Close
set rsOutput = nothing
set oFiletxt = nothing
set oFileSys = nothing

rsGroup.MoveNext
Wend

rsGroup.Close
dbConnection.Close

set dbConnection = nothing
set rsGroup = nothing',
@database_name=N'VBScript',
@flags=0

I should take the text in the @command line and move that out to a vbs
file, right?

On Fri, 21 Nov 2008 07:42:46 -0700, Tom van Stiphout
<to*************@cox.netwrote:
>On Fri, 21 Nov 2008 00:43:10 -0500, Carlton Kirby
<ckirbyATmindspringdottcomwrote:

Jobs seem tightly related to SQLAgent. So you either upgrade, or have
someone with VBScript skills take a look at those scripts.
If a VBScript was in a file, it could be executed like this:
cscript.exe c:\my.vbs
Scripts can extract data from a SQLServer, e.g. using ADO.
You may also be able to export the data some other way, e.g. BCP.

-Tom.
Microsoft Access MVP
>>I need to execute a job on a SQL Express 2005 instance (no SQLAgent).
The job will be executed manually by a user, so it doesn't need to be
scheduled to run automatically. I thought I could execute the job
through a stored procedure, but it appears that SQL Agent is necessary
even for that.

The job was given to me by a software vendor to add EDI capabilities
to an accounting package, but the assumption was made that a full
version of SQL was available.

Is there another way to execute a job on an Express instance? The job
has 4 steps. Two are just executing stored procedures, which I could
easily do via another stored procedure. But the other two steps are
Activescripting/VBScript ( @subsystem=N'ActiveScripting') and involve
creating text files and starting a ftp session to transfer them... And
that's a bit beyond me..

Thanks
Nov 21 '08 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

11
by: randi_clausen | last post by:
Using SQL against a DB2 table the 'with' key word is used to dynamically create a temporary table with an SQL statement that is retained for the duration of that SQL statement. What is the...
11
by: athos | last post by:
Hi guys, Sounds a bit strange, however, if we could put some calculation in stored procedure it would be quite convenient, just... where can I find a REGEXP library for matching checking?...
2
by: Not Me | last post by:
Hey, Coming back to a piece of work I did a while back, which used a stored procedure to populate a list box. The SP takes a single parameter, and I think this is the reasoning for using 'exec'...
0
by: Daniel | last post by:
will a client application using ado.net get an exception if the command is executing a stored procedure that does a RAISEERROR in its tsql?
13
by: Filips Benoit | last post by:
Dear All, How can I show the resultrecords of a SP. I can be done by doubleclick the SPname? But how to do it by code. I want the following interface In my form the user 1 selects a SP...
7
by: Filips Benoit | last post by:
Dear all, Tables: COMPANY: COM_ID, COM_NAME, ..... PROPERTY: PRP_ID, PRP_NAME, PRP_DATATYPE_ID, PRP_DEFAULT_VALUE ( nvarchar) COMPANY_PROPERTY: CPROP_COM_ID, CPROP_PRP_ID, CPROP_VALUE...
3
by: Goog79 | last post by:
Hi everyone, first time here, so I'm sorry if this has been covered already ages ago. :( I am trying to learn T-SQL and Stored Procedures and bought the book on these topics by Djan...
2
by: moforiappiah | last post by:
I urgently need help on how to execute a stored procedure in SQL Express 2005. I have created a stored procedure with as follows: Create Procedure upInsertCountry @CountryName varchar(50) ...
4
by: jleeie | last post by:
Can someone help me, I'm going round in circles with this and my head is cabbaged ! I am using visual studio 2005 & VB & MS SQL 2005 I am trying to execute a stored procedure from within a...
0
by: lllomh | last post by:
Define the method first this.state = { buttonBackgroundColor: 'green', isBlinking: false, // A new status is added to identify whether the button is blinking or not } autoStart=()=>{
4
NeoPa
by: NeoPa | last post by:
Hello everyone. I find myself stuck trying to find the VBA way to get Access to create a PDF of the currently-selected (and open) object (Form or Report). I know it can be done by selecting :...
1
by: Teri B | last post by:
Hi, I have created a sub-form Roles. In my course form the user selects the roles assigned to the course. 0ne-to-many. One course many roles. Then I created a report based on the Course form and...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 1 Nov 2023 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM) Please note that the UK and Europe revert to winter time on...
3
by: nia12 | last post by:
Hi there, I am very new to Access so apologies if any of this is obvious/not clear. I am creating a data collection tool for health care employees to complete. It consists of a number of...
0
NeoPa
by: NeoPa | last post by:
Introduction For this article I'll be focusing on the Report (clsReport) class. This simply handles making the calling Form invisible until all of the Reports opened by it have been closed, when it...
0
isladogs
by: isladogs | last post by:
The next online meeting of the Access Europe User Group will be on Wednesday 6 Dec 2023 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, Mike...
4
by: GKJR | last post by:
Does anyone have a recommendation to build a standalone application to replace an Access database? I have my bookkeeping software I developed in Access that I would like to make available to other...
3
SueHopson
by: SueHopson | last post by:
Hi All, I'm trying to create a single code (run off a button that calls the Private Sub) for our parts list report that will allow the user to filter by either/both PartVendor and PartType. On...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.