|
I have a dts package in Sql server 2000 which has three global variables in it. The script run as expected when i run it manually. But when i close the dts package and then run it by right clicking it or when i schedule the package.. the variables wont update. I have checked the permission and security of sql server agent and the user.. from which i run the script.. all admin rights. Please help... Below is the script
(comments are locked)
|
|
Are you expecting the end values of the variables to be used as the starting values the next time you run the package? If so, you'll have to save them to a table or file and read them back in each time you run the package. Variable state is not persisted between DTS executions. What you hard-code at design time is always used as the starting value. [Edit for codes request] I don't have a SQL 2000 instance to get the task names, but you need to...
Unfortunately, there isn't really much "code" to show you for this, just some DTS query tasks you'll need to add. [/Edit]
(comments are locked)
|
|
Finally here is the code... It will first fetch the values from database and then assign it to the global varibales and then update the new values to the database... '********************************************************************** ' Visual Basic ActiveX Script '************************************************************************ Function Main() dim ConnSQL1, RSSQL, strSQL, StartTime, Interval, RowDate '************************************************************************ set ConnSQL1 = CreateObject("ADODB.Connection") set RSSQL = CreateObject("ADODB.Recordset") ConnSQL1.Open = "Provider=SQLOLEDB;Data Source=(local);Initial Catalog=avayacms;UID=sa;Password=Carlson@1" '************************************************************************ strSQL = "Select RowDate,StartTime,Interval from Global_Variables" RSSQL.Open strSQL, ConnSQL1 do until (RSSQL.EOF) RowDate = RSSQL.Fields(0) StartTime = RSSQL.Fields(1) Interval = RSSQL.Fields(2) RSSQL.movenext loop RSSQL.close '************************************************************************ IF StartTime = 2400 Then StartTime = 0 RowDate = DateAdd("d" , 1 , RowDate) ElseIF Interval = 30 Then StartTime = StartTime + 30 Interval = 70 ElseIF Interval = 70 Then StartTime = StartTime + 70 Interval = 30 End IF '************************************************************************ strSQL = " Update Global_Variables Set RowDate=' " & RowDate & " ', StartTime=' " & StartTime & " ', [Interval] = ' " & Interval & " ' " ConnSQL1.execute strSQL ConnSQL1.close '************************************************************************ DTSGlobalVariables("RowDate").value = CDate(RowDate) DTSGlobalVariables("StartTime").value = StartTime DTSGlobalVariables("Interval").value = Interval 'msgbox DTSGlobalVariables("StartTime").value Main = DTSTaskExecResult_Success End Function
(comments are locked)
|
|
Is it possible that you are escaping the function before doing the actual work? Try moving the DTSTaskExecResult_Success ' Visual Basic ActiveX Script '************************************************************************ Function Main() RowDate = DTSGlobalVariables("RowDate").value StartTime = DTSGlobalVariables("StartTime").value Interval = DTSGlobalVariables("Interval").value IF StartTime = 2400 Then StartTime = 0 RowDate = DateAdd("d" , 1 , RowDate) ElseIF Interval = 30 Then StartTime = StartTime + 30 Interval = 70 ElseIF Interval = 70 Then StartTime = StartTime + 70 Interval = 30 End IF DTSGlobalVariables("RowDate").value = RowDate DTSGlobalVariables("StartTime").value = StartTime DTSGlobalVariables("Interval").value = Interval Main = DTSTaskExecResult_Success End Function Tried but the results are same.. No change in global variables..........
Jul 28 '11 at 09:39 AM
progzr
Wait, how are you viewing the global variables? Are you outputting them to a table or file somewhere?
Jul 28 '11 at 02:31 PM
SirSQL
No. From the package itself... They retain their values...
Jul 29 '11 at 06:35 AM
progzr
Any changes to global variables in the package are only saved when the package itself is saved. This means that if you run the package through a job then the variables will be assigned as directed however they will not be saved in the package itself. If you want to confirm that they are being set as you wanted you would need to output them to a table or file somewhere for checking. At this point I don't think it's your script that's causing you the problem, rather it's a change to your validation method that might well help you get past this.
Jul 29 '11 at 09:15 AM
SirSQL
Thanks a lot sir, I checked once again and that's true.. script is working properly and also supply variables to parametrized query as expected... global varibles wont save unless its open... So we have to store them into some table and then read values from it.... Sir, Do you have the code for doing so. i.e write values into table and then read back from that table via activex script... Thanks a lot once again...
Aug 01 '11 at 10:54 AM
progzr
(comments are locked)
|


Hi Kenj,
Thnaks for the help...Can you please give a code to do this..