How to Use Windows Task Scheduler to Execute a SQL Query

Viewed 26

I am aware that this is a duplicate question so apologies in advance. However, I am having difficulty understanding where I am going wrong with my issue. I am trying to leverage a basic Command Prompt to execute a .sql file instead of using SQL Server Agent and the in-built job functionality. Going through some past posts relating to this topic, I think I found the basis of what to input into Command Prompt to run my SQL query, however I receive the following error:

Sqlcmd: Error: Microsoft ODBC Driver 17 for SQL Server : MAX_PROVS: Error Locating Server/Instance Specified [xFFFFFFFF] Sqlcmd: Error: Microsoft ODBC Driver 17 for Sql Server : Login timeout expirered Sqlcmd: Error: Microsoft ODBC Driver 17 for SQL Server : A network-related or isntance-specific error has occurred while establishing a connection to SQL Server. Server is not found or not accessible. Check if instance name is correct and if SQL Server is configured to allow remote connections.

The below is the string that I input to Command Prompt to attempt to run my SQL Query:

sqlcmd -S SERVER-NAME\DATABASE-NAME -U USERNAME -P PASSWORD -i C:\LCP_Idea.sql

Based off of the screenshot below, I believe I mapped the parameters correctly but please correct me if I'm mistaken.

-S = Server name:
-U = Login:
-P = Password:
-i = the file location of where I saved my query right? Which in this case is simply sitting in my C drive with the file name of "LCP_Idea.sql"

I can only use SQL authentication and not Windows Authentication, I just don't know where I am going wrong with the above.

enter image description here

0 Answers
Related