2

I am trying to run the SQL procedure

EXEC xp_CMDShell 'blahblah.bat'

which needs to run an ogr2ogr script to create a kml from sql. The batch file works if I run it alone but with SQL permissions it fails. I can only think that because the first line below

pushd \\server\folder
ogr2ogr -f "KML" "\\server\folder\blahblah.kml" -s_srs "EPSG:28355" "MSSQL:server=blah;database=Blah;trusted_connection=yes" -sql "SELECT blah FROM blah" -t_srs "EPSG:28355"
popd \\server\folder

creates temporary drive mapping to the folder SQL can't find the DLL in that location.

ERROR 1: Can't load requested DLL: Y:\ogr2ogr\gdalplugins\ogr_MSSQLSpatial.dll
126: The specified module could not be found.

I've tried running the script using a SQL credential which links to a domain user which has full access to the actual folder this DLL lives in but I still get the error.

Has anyone come across this and been able to get around it? I'm assuming you can't insert the script directly into SQL.

  • You're running this in Linux which is foreign to me, however I have had a similar problem in Windows, I rectified it by running the OSGeo shell prior to executing the OGR2OGR to ensure the paths were set correctly for GDAL/OGR then in later iterations I copied the lines where the PATH and GDAL environments are being set into the batch file I run. Note that this doesn't look like a permissions problem, your error does not say access denied it says I can't find a Lib I need. – Michael Stimson May 22 at 1:36
  • Have a try by adding --config GDAL_DRIVER_PATH correct_path_to_ogr_MSSQLSpatial.dll into the ogr2ogr command. See trac.osgeo.org/gdal/wiki/ConfigOptions#GDAL_DRIVER_PATH – user30184 May 22 at 6:25
  • If I add the GDAL_DRIVER_PATH to the ogr2ogr I still have the problem, and this causes the batch file to do the same thing i.e. create a smaller size kml wihtout any geometries. Running it from SQL, I get the same error but now with the UNC path as I specified, rather than the temporary mapping. So you're right, it can't find the file even with the exact path specified. Michael, do you have a sample of your batch file handy so I can check it out? I'm at a loss with this one. Any other suggestions? – Joshua J Geoghegan May 23 at 3:02
  • Going by this personalcomputerfixes.com/how-to-fix-error-126 could it be that SQL needs read/write access to c:\Windows\System32 on the server it lives on, so that it can execute srvsvc.dll? The problem is I can't give SQL Service permission to this location. I think this has turned into a SQL problem. I might try to figure out another way around this. – Joshua J Geoghegan May 26 at 9:26

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.