OGR2OGR Use with database driver

Jan 27, 2015 at 2:19 PM
Hi! I'm trying to convert a DXF file into MSSQL using the ogr2ogr method from the class Utils with no results. Using ogr2ogr directly from console works correctly, so there is no problem with the dxf file or the database. In this case, the command I've used is:
ogr2ogr -overwrite -f MSSQL "MSSQL:server=.\SQLEXPRESS;trusted_connection=yes;database=testdb " C:\test.dxf
And the C# code is:
var path =@"C:\\test.dxf";
var dest = @"MSSQL:server=.\SQLEXPRESS;trusted_connection=yes;database=testdb ";
var opc = "-overwrite -f MSSQL";
utils.OGR2OGR(path, dest, opc, null);
Where should I declare the driver to use? In the bstrDstFilename or in the bstrOptions string? Could you provide me an example?

Thanks in advance
Jan 31, 2015 at 11:57 AM
Sorry for belated answer. I checked it. It seems you are doing everything right. The following code worked for me for shapefiles and MIF tab format as input and SQL Server as target (not an Express edition though).
if (utils.OGR2OGR(@"d:\jcsample.dxf", @"MSSQL:server=.\;trusted_connection=yes;database=test",
    "-overwrite -skipfailures -f MSSQL"))
    Debug.Print("Copied successfully");
    Debug.Print("Failed to copy");
However with DXF files there are troubles. For example for sample DXF file from here most of the entities were skipped with the following error:
GDAL FAILURE: INSERT command for new feature failed. [Microsoft][ODBC SQL Server Driver][SQL Server]A .NET Framework error occurred during execution of user-defined routine or aggregate "geometry": 
System.FormatException: 24115: The well-known binary (WKB) input is not valid.
When I converted one of the shapefiles to DXF format and tried to import it to MSSQL it generally worked, however gave me some warnings as well.

So I would suggest first of all to set application callback to see the errors GDAL reports and then act depending on these errors. Perhaps a workaround like converting through intermediary format might work. It's hard to say for me why it works in console app for you and doesn't via MapWinGIS. Obviously there are different versions of GDAL perhaps something else.

Hope it'll help,