path variable changes in sql - sql-server

I'm not sure why but it looks like sql server is using a different path environmental variable then the rest of my system. When i add the cmd as an external tool in sql, by going to
Tools->external Tools and adding cmd.exe as the command i get a different path.
the shell from sql gives me
echo %PATH%
c:\Program Files (x86)\Microsoft SQL Server\100\Shared\;C:\Windows\system32\NV;.;
This does not reflect my path variable at all
when I echo the path from a regular command prompt I get my full path.
When SQL starts up it looks like it is using its own environmental variables. Does anyone know where these are defined or if I can have my system path appended to this "special" SQL path?

Looks like it's very rare problem. I found only this topic and it without solution.
I faced same problem.
Stopping all services that on the screenshot (in running state) and start them again one by one solved my problem.

I think your SQL Source Control issue may be related to something else. You may want to check your path and make sure that it doesn't have extra backslashes or double-quotes in it -- DOS is fine with that but the dox for ProcessStartInfo in .NET say this will not be a recognized path. For instance
c:\windows;c:\git;"c:\program files\git\bin"
With Git.exe in any of the latter two path components, you could launch Git.exe from the command prompt but the command would fail in SQL Source Control.

Related

Sql Advantage Error : Open Client is not configured correctly

I am trying to run the Sql Advantage editor but getting below mentioned error.
Internal failure while initializing the SQL Advantage.
Please check that Open Client is configured correctly.
Please check the SET command output in the attached screenshot.Also, I can see two folders in my system for OCS-12_5 and OCS-15_0. This may be causing this problem. I also tried to run a bat file with these commands but getting same error:
Bat file commands:
set SYBASE= C:\Sybase\OCS-12_5
set SYBASE_OCS=OCS-12_5
C:\Sybase\OCS-12_5\sqladv-12_5\sqladv.exe
Please suggest.
SQL Advantage is no longer supported with ASE 15.x
But you can probably still run it if you set your environment to 12.5 (it works for me). Put all the environment settings in a .bat file, and then (in the .bat file) kick off sqladv.exe.

SQL Server xcopy and xp_cmdshell file not found

I read other help posts but I keep getting file not found on the the network. The path is on the network on a fileshare and I'm using RDP to remote to my own machine that connects to the SQL Server database.
I'm using xcopy command with xp_cmdshell. I can't use just "copy" because I get an access denied error so I'm using Xcopy in this format:
echo f|xcopy /i "\\fileserver\file\excelfile1.xls" \\fileserver\file\newdirectory\excelfile1.xls"
I have tried almost everything and read other posts but this is still not working. I do have parameters for the directory and files, etc. but I actually have it hard-coded in the dos command it's still not working.
Any ideas would be great.
If you get an "access denied" with copy, you'll get the very same error with xcopy too. It offers more options, but won't let you bypass the OS security at will, both are still bound to the permissions of the user account that runs them, like every other software.
There are two options:
Use sp_xp_cmdshell_proxy_account to specify a different user for all xp_cmdshell operations (as suggested by Bacon Bits). This user must have enough permissions to both origin and target files.
Give those permissions to the account that runs the SQL Server service, so that it can access the files directly.
Thank you everyone for responding. This is the first time I've used this forum.
I found out the files were named .XLS but actually in .TXT delimited format. So I renamed them through SSIS with a ForEach Loop and processed them from there.
I tried to XCOPY from command line with new permissions that that didn't work. I was getting an extension hardening error and that is why, XLS to TXT wasn't liking it.

Batch or .exe via SSIS package fails to give output despite of success status of SQL Agent Job

I have created a batch file which starts a command line (IrfanView) with several arguments. The batch looks like this:
start /wait /d "C:\Program Files (x86)\IrfanView" i_view32.exe C:\Source\*.png /advancedbatch /convert=C:\Destination\*.jpg
Basically it converts all PNG from source folder to JPEG using advanced batch settings stored in INI of IrfanView to destination folder.
The batch file is located on my server (same as IrfanView) and when manually started it works fine. I also tried to start the batch using SSIS execute process task, which also works when package executes manually.
Another option was to start IrfanView directly from the execute process task (so no batch file) and then manually trigger the package. Every option seems to work manually.
However, whenever I try to run the batch (cmdExec) or any package in SQL Agent it will run the job successfully, but... there is no output in the folder. So, it doesn't give an error, it simple does nothing.
When run manually the output files will appear as expected in the destination folder.
When run through SQL Agent no output files will appear although the job was run successfully.
Could it have to do with security settings? SQL Agent runs under local user with full administrator rights.
I have read something about credentials and proxy, but not sure how to use it and if it will solve the problem.
I have another job running which also calls an executable (7zip) in a SSIS package and it works fine.
If I use another program, for example Flash Renamer from command line, then the SQL Job keeps running (status in progress), while triggering the package or batch manually it works fine.
Using SQL Server 2008 (BIDS + SSMS)
How can this be resolved?
Command start often interprets first double quoted string as title string. Therefore it is necessary to specify a title in double quotes if any other string must be enclosed also in double quotes.
IrfanView does not require that its program directory is the current working directory. Therefore simply starting IrfanView with full path would be better in my point of view.
IrfanView option advancedbatch requires data from i_view32.ini. On running IrfanView with a different account, it will be necessary most likely to specify the path to the folder containing i_view32.ini.
i_view32.ini is usually stored either in program files directory of IrfanView or in directory "%APPDATA%\IrfanView".
The first option is usually not used anymore as default program files location "%ProgramFiles(x86)%\IrfanView" on Windows x64 or "%ProgramFiles%\IrfanView" on Windows x86 is write-protected by default for users of Windows Vista and later Windows versions.
Therefore i_view32.ini is nowadays by default in application data directory of IrfanView of current user account.
Yes, environment variable APPDATA contains name of the user account and differs therefore from user account to user account. And by default user X has no permission to access the application data directory of user Y.
So on running IrfanView with a different account, file i_view32.ini or a copy of it containing the advanced batch conversion options must be located in a folder readable for all user accounts or at least the used account and on command line the path to this folder must be specified, too.
With summarizing up all information above, you would need most likely
start "Convert PNG to JPEG" /wait "%ProgramFiles(x86)%\IrfanView\i_view32.exe" C:\Source\*.png /advancedbatch /convert=C:\Destination\*.jpg /ini="Path to folder with i_view32.ini" /cmdexit
But below should also work if the batch file does not contain any other commands and therefore no batch file is needed at all.
"%ProgramFiles(x86)%\IrfanView\i_view32.exe" C:\Source\*.png /advancedbatch /convert=C:\Destination\*.jpg /ini="Path to folder with i_view32.ini" /cmdexit

Batch runs manually but not in scheduled task

I don't generally write batches, but I currently have a batch that uses forfiles to copy my FLVs from one folder to another. When I run the batch manually it works every time, but from a scheduled task, it throws a (0x1) error.
forfiles -p "C:\Program Files\Adobe\Flash Media Server 4.5\applications\name\streams" -m *.flv -s -d -1 -c "cmd /c copy #file ^0x22C:\Program^ Files\Adobe\Flash^ Media^ Server^ 4.5\applications\name\output\"
Not sure what syntax the scheduled task doesn't like.
Update
Under my scheduled task, Actions I have the following:
Program/script: name.bat
Start in (optional): \\servername\file\to\batch
Hi might be this is helpful,
I also face the same issue.
Just set the startin path like:
Here start in path is the path of batch file:
like you have enter in program script:
"E:\program related files\demo.bat"
then in startin just pass:
E:\program related files & done!
When my Start in (optional): path was a UNC path, it wouldn't work. So I moved my batch on the server and everything worked correctly.
UNC in Windows Batch Files
forfiles with UNC path
On Server 2008 R2 when running the batch file under domain user credentials, with confirmed "log on as a batch job" security in the Local Security Policy>Local Settings>User Rights Assignment,
even then my batch (copying a log file to a network share) would not run as scheduled task, until I selected in tab General the option "Run with highest privileges" (default NOT checked!)
The option Run whether user is logged on or not was also selected, with radio-button, but I guess this is quite standard, when selecting to run the task using a domain user account.
For the tab Actions : specifying the entire batch file name including its path, directly in "Program/script:" works fine (with Server 2008 R2)
Using double quotes inside the batch file causes no problems.
See the screen shot bellow.
You need to change the user to system
Most common reason for such problems is permissions: scheduled tasks does NOT always run with your user credentials. If you want scheduled task to run as you you will have to set it up as you or alternative user.
Besides that I hope that your line of code is a content of your batch file, you are not trying to run this command directly. Or are you?
P.S. What are these ^0x22 and ^ doing in your code?
I know this is an old question, but just wanted to share some info.
The (0x01) error code can also refer to resources that are not found. Therefore:
all files/folders referd from within the batch file should be accessible to the user which account is being used to run that scheduled task;
pay attention when using network locations in combination with "Run whether user is logged on or not" option;
the above-mentioned option can be tricky to use because some resources may be available only after log on.
For .bat files to run inside your scheduled task, you need to specify your .bat file path inside the start option - despite the fact that your .bat file is at the same directory as your .exe. Also, I flagged it to run with highest privilege. After I have done those two things, the task suddenly takes off without any problem!

How to create Log file in SSIS

I want to create a log file in SSIS. I know how to create through management studio, but I wanted to run my SSIS package through Command Prompt.
Can you help me find the Windows commands for that?
You can use the /L option, as documented here; however, you can also set Logging up in a much easier and finer way through the SSIS>Logging menu in Visual Studio.
Cheers,
Eric
In your SSIS you need to create and configure an SSIS Log provider before you can use it. Look into link text for more info.
You need to set up the a new connection string inside of Business Intelligence Development Studio (BIDS). where you have to specify the path of Log file...i mean here path will be D:\Sample_Examples\Log.log... and name of the connection manager will be Log.log
so now the command prompt will get changed into
dtexec /f "C:\\Package.dtsx" /l "DTS.LogProviderTextFile";"Log.log"
instead of
dtexec /f "C:\\Package.dtsx" /l "DTS.LogProviderTextFile;D:\Sample_Examples\Log.log"
we cant specify a direct path after DTS.LogProviderTextFile...because of that only i got error...
Thank you very much for the suggestions...
You can do this another way, without going into your SSIS package.
Create a batch file and run DTEXEC in a new instance of CMD, i.e.:
CMD /C DTEXEC your package and args > log file
When you do this, you can run this batch file and get your log file.
See http://richarddingwall.name/2009/01/26/capture-the-output-from-a-scheduled-task/ for more details
Yes, you have to create a connection manager for the log provider; however; there is no documentation on how to do this if you are using a custom log provider.

Resources