Why can't I create a simple SQL Agent Job or find correct syntax? - sql

This works perfectly in a SSMS 2008 query window:
use [HSS Maintenance]
exec HSS_Guest.[olap storedprocedure]
exec HSS_Guest.[MAKE OLAP_CUBE]
But when I build an Agent Job and then test by using "Start Job at Step..." it always fails.
I have tried Operating System (CmdExec) "Type" as well as T-SQL and even SSAS I believe.
Am I having a Syntax issue or not using the correct "Type"?
Using full rights on an Enterprise edition & Server 2008.
I have Googled this to death and do not believe that I can't just build this simply via the GUI.
Please show me how dumb I am!
Note - I have tried to generate the Script from the Job window and get an error that "There is no Action to be Scripted"

Edit the SQL Server Agent job that contains the step that has the SQL code you posted. Remove the "use [HSS Maintenance]" line and instead use the drop down menu on the step to choose this database.

Related

Run multiple SQL scripts with oracle SQL developer

Right now I'm dropping, creating and then running scripts for several database several times each day. It's getting a little tedious.
I've simple scripts from dropping and creating databases and additional scripts that writes data to the DBs.
I run these scripts through oracle SQL developer. Is there a way I can run all of these scripts at the same time. Like in a batch file or another tool? I.e
Drop existing DBs
Create DBs
Run scripts for DBs
Haven't been able to figure it out
You can create a scheduled job in sql developer. See bellow steps to create a job:
1- From your connection in sql developer select scheduler. In right click select "New Job ...".
2- In opened window you should select "PL/SQL Block" for "Type of Job" then write a block just like I wrote in bellow picture. Then you should select "Repeating" and insert intervals and start and end dates:
3- Keep in the mind that "Enable" box should be checked.
4- click on "Apply". Your Job will be ran based on intervals and start date you inserted.

SSIS SQL Executation Task error: unable to run some sql queries

I'm working to make some fact tables (taking some data from some resources, doing some transformations and putting them in a table). My main dilemma is that I can't run any SQL query other than select, update, and insertion. As soon as i try:
exec someProcedure
or a conditional statement (if #part1 ...) or even (create table ...) I take errors. Opening the task to build my SQL statements and find problems it gives errors ranging from (The Set SQL construct or statement is not supported.) to (The EXEC SQL construct or statement is not supported.).
I looked for numerous topics here on stackoverflow but none were actually addressing me problem.
Thanks,
You can see a view of what I'm facing in this picture :
I expect to run my SQL commands as usual in SSIS.
Try changing the SQL Source Type from Direct Input to Stored Procedure and just specify the stored procedure name instead of Exec stored procedure
Also make sure that you have selected the relevant TargetServerVersion from the project configuration:
How to change TargetServerVersion of my SSIS Project
Based on your comments, you are using SQL Server 2012 with Visual Studio 2010 which are not compatible.
You have to use Visual Studio 2012 or 2015+ (backward compatibility added). You can refer to the SSIS tag wiki for more info:
https://stackoverflow.com/tags/ssis/info

Run MS SQL server script on startup

I am trying to run an SQL script when I start (or restart) my windows 2012 R2 server instance (Google Cloud Server). I am doing so using an SQL script, a Batch-file and the task-scheduler.
For the sake of testing I have created a simple SQL-script that adds a datestamp to a table:
USE <Databasename>
GO
INSERT INTO testingTable(time_Stamp)
VALUES (GETDATE())
SELECT * FROM testingTable
(where Databasename obviously contains the name of the specific database)
The batch-file looks as follows:
sqlcmd -S <servername> -i "C:\Temp\testQuery.sql" > C:\Temp\output.txt
I am outputting everything to a text-file. When I run the Batch-file the output looks fine: it prints a list with all the times I have run this SQL-query and saves it in the text-file.
I have scheduled this task to run on startup (following the steps here: https://www.sevenforums.com/tutorials/67503-task-create-run-program-startup-log.html). I have tried a whole range of settings here but nothing seems to work, including the exact settings as highlighted in the forum.
When I now restart the server the output file shows the following error message:
Msg 904, Level 16, State 3, Server <servername>, Line 1
Database 7 cannot be autostarted during server shutdown or startup.
Msg 208, Level 16, State 1, Server <servername>, Line 2
Invalid object name 'testingTable'.
It seems like MS SQL does not allow scripts to be run before you log-in to one of the user accounts.
The problem really is that the actual SQL tasks that I want to run have to be run very early in the morning such that they are done when everyone arrives at the office. I have managed to automate the startup of the server using VMPower, but I can not automate logging in to one of the accounts.
I was hoping someone could give me some feedback on how to resolve this issue. Preferably I would want my current setup to work, but if anyone has an idea on how to automate logging in to an account on an existing google cloud server instance that would be really helpful as well.
Thank you,
Joost
SQL Server offers the system stored procedure sp_procoption which can be used to designate one or more stored procedures to automatically execute when the SQL Server service is started.
For instance, you may have an expensive query in your database which takes some time to run at first execution. Using sp_procoption, you could run this query at server startup to pre-compile the execution plan so one of your users does not become the unfortunate soul of being first to run this particular query. I've used this feature to set up the automatic execution of a Profiler server side trace which I've scripted. The scripted trace was made part of a stored procedure that was set to auto execute at server start up.
exec sp_procoption #ProcName = ['stored procedure name'],
#OptionName = 'STARTUP',
#OptionValue = [on|off]
Read more: Automatically Running Stored Procedures at SQL Server Startup.
Docker
For solution to MSSQL Docker image, see: SQL Server Docker container is stopping after setup.

How to check if an SQL Script executed successfully in MS SQL Server?

I have created multiple SQL DB Maintenance scripts which I am required to run in a defined order. I have 2 scripts. I want to run the 2nd script, only on successful execution of 1st script. The scripts contain queries that creates tables, stored procedures, SQL jobs etc.
Please suggest an optimal way of achieving this. I am using MS SQL Server 2012.
I am trying to implement it without using an SQL job.
I'm sure I'm stating the obvious, and it's probably because I'm not fully understand what you meant by "executed successfully", but if you meant no SQL error while running:
The optimal way to achieve it is to create a job for your scripts, then create two steps - one for the first script and for the second. Once both steps are there, you go to the advanced options of step 1 and set it up to your needs.
Screenshot
Can you create a SQL Server Agent Job? You could just set the steps to be Step 1: Run first script, Step 2: run second script. In the agent job setup you can decide what to when step 1 fails. Just have it not run step 2. You can also set it up to email you, skip to another step, run some other code etc... If anything the first code did failed with any error message, your second script would not run. -- If you really needed to avoid a job, you could add some if exists statements to your second script, but that will get very messy very fast
If the two scripts are in different files
Add a statement which would log into a table the completion and date .Change second script to read this first and exit,if not success
if both are in same file
ensure they are in a transaction and read ##trancount at the start of second script and exit ,if less than 1
SQL Server 2005’s job scheduling subsystem, SQL Server Agent, maintains a set of log files with warning and error messages about the jobs it has run, written to the %ProgramFiles%\Microsoft SQL Server\MSSQL.1\MSSQL\LOG directory. SQL Server will maintain up to nine SQL Server Agent error log files. The current log file is named SQLAGENT .OUT, whereas archived files are numbered sequentially. You can view SQL Server Agent logs by using SQL Server Management Studio.

msg102 level 15 error - sql server

I was trying to run a script to create a DB with all the tables and data on a server, which I created using script wizard in SSMS 2008. The destination server is 2005 and since I am unable to just restore a backup, I had to go through this long process which entailed running it through sqlcmd cause it was too large to open in SSMS.
But after running for more than 5 hours, I checked on it and it had the following error:
msg 102 level 15 state 1, incorrect syntax near 'VA'
Now I tried finding the source of the error and looking in the script the only reference to 'VA' are in the data types nvarchar or varchar.
Please help, I really need to deploy this DB.
EDIT
For those who have answered, thanks for the responses. I guess I will have to rerun the script but I would like to know if anyone has any ideas on running the script in SSMS. The script is over 2GB in size since it has to recreate the data and there is no other way to deploy this 2008 DB to a 2005 sql server edition.
Either: you have scripted a SQL Server 2008 only option which can be changed in SSMS (tools..options somewhere)
Or (assuming no other VA strings) the word VARCHAR has truncated to VA. I've had this happen with dynamic SQL: can be a real pain to track down
in SSMS if you double click on the error message in the results pane, it will usually change focus and highlight that line of code. Now, how close that line of code is to the actual error depends on the actual problem, but you should be able to find the line of code it is complaining about.
Really tricky to track these down, but you could either try to generate the script setting the compatibility level for SQL 2005 or use the SQL 2005 tools to generate the script.