I am running the following to schedule a csv export daily:
`DECLARE @sqlcmd VARCHAR(8000);
DECLARE @servername NVARCHAR(128);
DECLARE @instancename NVARCHAR(128);
— Get the server name
SET @servername = @@SERVERNAME;
— Get the instance name (it might be empty)
SET @instancename = COALESCE(@@SERVICENAME, ”);
— Print server and instance name for debugging
PRINT ‘Server Name: ‘ + @@servername;
PRINT ‘Instance Name: ‘ + @@servicename;
— Construct the sqlcmd command
SET @sqlcmd = ‘sqlcmd -S “‘ + @servername + ” + @instancename + ‘” -d master -Q “SELECT * FROM vw_odbc_appts_InsuranceOrder ORDER BY CreatedAt ASC” -o “c:csvtest.txt” -s “,”‘;
— Print the final command for debugging
PRINT ‘SQLCMD Command: ‘ + @sqlcmd;
— Execute the command
EXEC master..xp_cmdshell @sqlcmd;`
But I keep getting this error:
Sqlcmd: Error: Microsoft ODBC Driver 17 for SQL Server : SQL Server Network Interfaces: Error Locating Server/Instance Specified [xFFFFFFFF]. . Sqlcmd: Error: Microsoft ODBC Driver 17 for SQL Server : Login timeout expired. Sqlcmd: Error: Microsoft ODBC Driver 17 for SQL Server : A network-related or instance-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. For more information see SQL Server Books Online..
Any ideas on how to get past this?
I tried multiple things around the server name and instance name
Ronak Patel is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.