xp_cmdshell throwing 'null' but working in command prompt - sql

I am using xp_cmdshell command to process csv file to a folder. My query is as below:
Exec master..xp_cmdshell 'C:\test\mydotnetapp.exe -s:03/09/2020 -t:1 -l:1,2,3,4,7 -d C:\test'
In SSMS this command returns null. But in command prompt when I do:
cd C:\test
mydotnetapp.exe -s:03/09/2020 -t:1 -l:1,2,3,4,7 -d C:\test
The same query is working perfectly fine. A couple of things:
xp_cmdshell is enabled
SQL Server has access to the folder
Only this xp_cmdshell command is not working. my other xp_cmdshell is working fine
Any help on how this can be fixed?

If this is run as part of a SQL Job regularly scheduled, run it as a task outside of SQL Server.
Many production DBAs won't let any process run XP_CMDSHELL given the security issues.
If the CSV is well-formed, it can be mapped into SQL Server as a table (not recommended).
It can be imported directly into SQL Server.
Lastly, many production DBAs won't install any custom process code on a production SQL Server machine. The SQL Server machine is dedicated to running only SQL Server plus the minimum extra needed for security and monitoring.

Related

Unable to run .sql file in SQL Server

I have a .sql dump file 20 gb and I am trying to run it on Mysql workbench using run script and after successful execution, using SSMA I'll migrate the data from Mysql workbench to SQL Server. I have migrated the data this way many times successfully however for 20 gb file it seems very time-consuming. Please let me know if there is any alternate way to achieve this quickly. I have followed the following link:
Steps to migrate mysql tables to sql server using SSMA!
From your Title "unable to run .sql file in SSMS" and "I have a .sql dump file 20 gb" are you trying to open a 20GB .sql in SSMS? That's never going to work. SSMS is a 32bit application, so the maximum addressable memory is 2GB. If you want to run your .sql file, I suggest using sqlcmd.
Open up Powershell, and then run the command below replacing the appropriate parts:
sqlcmd -S {Server Name/ServerIP} -U {Your Login} -i {Your full path to your script}
You'll be prompted for your password and then you the file will be run. So, as an example, you might run:
sqlcmd -S svSQL2017 -U Larnu -i \\svFileServer\SQLShare\Scripts\BigBatchFile.sql
If you are using integrated security, then don't pass the -U parameter for the command.
Edit: This answer is no relevant to the OPs question, as they were using "SSMS" as a synonym for SQL Server, which it is not. I have left this here for the moment so the OP can review my comments, and I will likely remove this answer at a later point.

SQL Schema Compare from one SQL version to another not working

In Visual Studio (2013 or 2015, they both do the same) > SQL Schema Compare, I am trying to copy the schema from one database on sql 2008, to databases on sql 2014. From 2008 -> 2008 works fine, 2014->2014 works fine, but when trying to go from 2008->2014, it does not work. After running the compare and hitting update it just sits on "Schema Compare generate script (db1 > db2) until it eventually freezes and visual studio just says it is busy, and never finishes. I can not find a log that explains what point it gets stuck on either.
Under options I have tried to ignore compatibility issues but this does not fix it. Any suggestions?
That might be a schema compare bug. I'd suggest first ensuring that you're using the latest version of the SQL Server tools (available for download here: https://msdn.microsoft.com/en-us/library/mt204009.aspx)
Then, if the problem still persists, I'd suggest capturing a trace log using the below instructions and opening a Connect issue that describes the problem and includes the trace log at https://connect.microsoft.com/SQLServer/feedback/CreateFeedback.aspx using the category "Developer Tools (SSDT, BIDS, etc.)"
Gathering an Event Log for SSDT
Open a new command prompt as Administrator.
Run this command logman create trace -n DacFxDebug -p "Microsoft-SQLServerDataTools" 0x800 -o "%LOCALAPPDATA%\DacFxDebug.etl" -ets
Then run this command: logman create trace -n SSDTDebug -p "Microsoft-SQLServerDataToolsVS" 0x800 -o "%LOCALAPPDATA%\SSDTDebug.etl" -ets
Run SSDT and reproduce the issue.
Go back to the command prompt and run the following commands:
logman stop DacFxDebug -ets
logman stop SSDTDebug -ets
The resulting ETL files will be located at %LOCALAPPDATA%\SSDTDebug.etl & %LOCALAPPDATA%\DacFxDebug.etl.
Instead of hitting "Update" try "Generate Script", and then run the script on the destination database.

Windows Server Permissions: What permission changes are needed to run 'sqlcmd' through IUSR?

A little background: I need to invoke sqlcmd to remotely run .sql files via PHP. I am trying to use this function call: exec("sqlcmd -?", $second); There is zero output after running this command. Running this command under my current user works fine.
PHP runs under IUSR according to PHP's get_current_user(); function so it would be logical to change the permissions on sqlcmd to allow PHP to run sqlcmd (I give full permissions temporarily just for testing):
Then I retest the PHP script and again no output. I decide to restart IIS. Still no output.
What permissions are needed to run sqlcmd under IUSR?

Export data with bcp in SQL Server produces nothing

I am exporting data in SQL Server 2005 with the following command but it produces nothing in SQL server 2008, no file is created although the query is executed succesfully:
execute xp_cmdshell 'bcp "SELECT * FROM MYDB.dbo.MYTABLE" queryout d:\file.csv -c -t; -S(local) -T'
What is wrong with my command?
I managed to execute the command. Solution:
I installed more than one sql server versions. And the management studio cannot find the bcp.exe because in the enviroment path, there are more than one paths for the bcp.exe. You can check this by executing bcp.exe from command prompt and it will say sqlncli.dll was not found.
So you have to put the exact path of bcp.exe to the enviroment path (or in front of other paths). So that windows can use it. Then dont forget to restart the sql server in order to change in paths takes effect. In conclusion, my command is not wrong but the path of bcp.exe is wrong.

How to Execute SVN Update command through SQL xp_CMDShell

I have installed Tortoise SVN on my machine, i want to update my local copy with SVN using SVN UPDATE command. I am using SQL script
EXEC master..xp_CMDShell 'svn update D:\SVN_WorkingFolder'
This script is not executing. May i know where i am doing workng.
Thanks in advances guys.
KumaR
Script execution process won't complete because of insufficient permissions to access network.
We won't get any error message or output redirection.
Steps to give permission: Services--> SQLServer2005--> Properties-->Log on-->This account--> Provide local user credentials. Now restart SQL server then execute above SVN update command it will work. Even we can execute batch file to do this job.