Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 Automate/schedule Script

Author  Topic 

xhostx
Constraint Violating Yak Guru

277 Posts

Posted - 2012-08-21 : 14:38:17
I have a .SQL file that I want to run on a monthly basis.
Is there anyway how to schedule this to happen?

Thanks,

--------------------------
Joins are what RDBMS's do for a living

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2012-08-21 : 15:03:55
you need to add a sql agent job and configure it to call and execute osql utility to execute th .sql file commands

------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/

Go to Top of Page

xhostx
Constraint Violating Yak Guru

277 Posts

Posted - 2012-08-21 : 15:11:56
Sounds doable :).
Do you have any example with step by step please :)
Thanks Visakh!

--------------------------
Joins are what RDBMS's do for a living
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2012-08-21 : 15:15:06
see

http://databases.about.com/od/sqlserver/ss/sql_server_agent_3.htm

------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/

Go to Top of Page

xhostx
Constraint Violating Yak Guru

277 Posts

Posted - 2012-08-22 : 08:34:53
Thanks Visakh,
I'm running win2000 and tried multiple solution to automate that .SQL script but it does not RUN at all, here is what I have tried; 2 different solutions from Microsoft website:
http://support.microsoft.com/kb/843282

Any help is appreciated!

--------------------------
Joins are what RDBMS's do for a living
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2012-08-22 : 11:05:29
where are you creating the sql agent job? is sql file in same server or in a remote machine?

also is it not runing at all or are you getting some error?

------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/

Go to Top of Page

xhostx
Constraint Violating Yak Guru

277 Posts

Posted - 2012-08-22 : 11:17:31
all files are in the same server.
Following the steps of "Scheduled task" does show that the job (task) as "Running". However, my script should create/update text files which is not happening when right-click and run the task manually. However if I type this command in cmd "osql -E -ifile.sql -n" it does run and I can see the text files are being created/updated.
Any help will very appreciated :)

--------------------------
Joins are what RDBMS's do for a living
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2012-08-22 : 11:22:01
whats the account that sql server agent uses? does it have access to file path?

------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/

Go to Top of Page

xhostx
Constraint Violating Yak Guru

277 Posts

Posted - 2012-08-22 : 13:08:55
The owner of the Job is part of the administrator.
This is the error according to job history:
Executed as user: XXDB1100\CompanyServices. Cannot open input file - C:\temp\folder\file.sql  No such file or directory.  Process Exit Code 1.  The step failed.

when I changed back the Owner to "sa", this wha tI got:

The job failed.  The Job was invoked by User sa.  The last step to run was step 1 (SAudit).
Go to Top of Page
   

- Advertisement -