This project is read-only.

Problem with ImportFromShapefile Stored Proc.

May 10, 2007 at 4:12 PM
Hi,
I have been working on importing some shp files into my MsSQL Server 2005 with MsSqlSpatial installed via the ImportFromShapefile Stored Procedure somewhat unsuccessfully up to this point. I keep getting the following error:

Msg 6522, Level 16, State 1, Procedure ImportFromShapefile, Line 0
A .NET Framework error occurred during execution of user defined routine or aggregate 'ImportFromShapefile':
System.IO.DirectoryNotFoundException: Could not find a part of the path 'C:\vector\bound\boundary.shx'.
System.IO.DirectoryNotFoundException:
at System.IO.__Error.WinIOError(Int32 errorCode, String maybeFullPath)
at System.IO.FileStream.Init(String path, FileMode mode, FileAccess access, Int32 rights, Boolean useRights, FileShare share, Int32 bufferSize, FileOptions options, SECURITY_ATTRIBUTES secAttrs, String msgPath, Boolean bFromProxy)
at System.IO.FileStream..ctor(String path, FileMode mode, FileAccess access)
at SharpMap.Data.Providers.ShapeFile.ParseHeader()
at SharpMap.Data.Providers.ShapeFile..ctor(String filename, Boolean fileBasedIndex)
at StoredProcedures.ImportFromShapefileMain(String shapefile, String schemaname, String tablename, String column_name, Int32 srid, String type, String connectionString, Int32& importedRows, TimeSpan& elapsedTime)
at StoredProcedures.ImportFromShapefile(SqlString shapefile, SqlString schemaname, SqlString tablename, SqlString column_name, SqlInt32 srid, SqlString type)
.
I have verified that the path is correct (even moved it from a mapped drive to a local drive in case that was causing problems). The .shx file exists in this directory along with the .shp, .dbf, and .prj files all of the same name. Does anyone have any idea of why this is happening? thanks

--Eric
May 16, 2007 at 9:53 PM
using the msscmd.exe file to import took care of my problem.
May 17, 2007 at 4:43 AM
Sorry for the delay.
If you want to try again with the SP, verify whether boundary.shx has the same permissions as the other boundary.* I think that that may be the problem.

Best regards,
Ricardo Stuven.
May 17, 2007 at 2:43 PM
no problem, i actually think it might be a problem with my boundary shape file. i generated it from a dwg file and even attempting to import it via the msscmd process is failing. i generated all of my other shp files in the same fashion and didn't have any problems with them so i know the issue is not the conversion but i'm going to try and extract the boundary information again and see if that works. in the meantime, this is the error that msscmd is giving back to me:

msscmd -server=localhost -db=danger -table=boundary -import=shp -shp_filename="C:\vector\boundary.shp"

Unhandled Exception: System.Data.SqlClient.SqlException: Incorrect syntax near '1'.
at System.Data.SqlClient.SqlConnection.OnError(SqlException exception, Boolean breakConnection)
at System.Data.SqlClient.SqlInternalConnection.OnError(SqlException exception, Boolean breakConnection)
at System.Data.SqlClient.TdsParser.ThrowExceptionAndWarning(TdsParserStateObject stateObj)
at System.Data.SqlClient.TdsParser.Run(RunBehavior runBehavior, SqlCommand cmdHandler, SqlDataReader dataStream, BulkCopySimpleResultSet bulkCopyHandler,TdsParserStateObject stateObj)
at System.Data.SqlClient.SqlCommand.RunExecuteNonQueryTds(String methodName, Boolean async)
at System.Data.SqlClient.SqlCommand.InternalExecuteNonQuery(DbAsyncResult result, String methodName, Boolean sendToPipe)
at System.Data.SqlClient.SqlCommand.ExecuteNonQuery()
at MsSqlSpatial.GeometryTable.ExecuteCreate(SqlCommand command, String schemaName, String tableName, String columnName, String createColumns)
at StoredProcedures.ImportFromDatasource(IProvider datasource, String schemaName, String tableName, String columnName, Int32 srid, String type, String connectionString, ImportFromDatasourceProcess process, Int32& importedRows, TimeSpan& elapsedTime)
at StoredProcedures.ImportFromShapefileMain(String shapefile, String schemaname, String tablename, String column_name, Int32 srid, String type, String connectionString, Int32& importedRows, TimeSpan& elapsedTime)
at MsSqlSpatialConsole.Program.ImportShp(ArgParser arg, String schema, String table, String column, Int32 srid, String type, String connectionString) at MsSqlSpatialConsole.Program.Main(String[] args)

after reading up on Microsoft's pages about what this error could mean it seems like it might just be a typographical error in the way some query is being processed (since error numbers from 1 to 10 indicate very minor errors) but, aside from using the sql profiler, i can't get to the queries being executed. any ideas on where i should go if the regeneration of the shp file fails like this as well? Thanks.
May 29, 2007 at 10:10 PM
If it's possible, send me the shapefile to rstuven@gmail.com

Best regards,
Ricardo Stuven.
Jan 2, 2008 at 8:54 PM
Edited Jan 2, 2008 at 8:54 PM
Just installed MSSQLSpatial and tried to do an import of several shape files that were exported from an ESRI geodatabase. All I get is is the following error.

C:\Program Files\Microsoft SQL Server\90\Tools\MsSqlSpatial>msscmd -server=esri-
client4 -db=db_gis -table=AgriculturalMineralsOperations -import=shp -shp="C:\HS
IP_GOLD2005\HSIP Gold 2005\Data\Infrastructure\Mining\AgriculturalMineralsOperat
ions.shp"

Unhandled Exception: System.ArgumentOutOfRangeException: Length cannot be less t
han zero.
Parameter name: length
at System.String.InternalSubStringWithChecks(Int32 startIndex, Int32 length,
Boolean fAlwaysCopy)
at SharpMap.Data.Providers.ShapeFile..ctor(String filename, Boolean fileBased
Index)
at StoredProcedures.ImportFromShapefileMain(String shapefile, String schema_n
ame, String tablename, String columnname, Int32 srid, String type, String conn
ectionString, Int32& importedRows, TimeSpan& elapsedTime)
at MsSqlSpatialConsole.Program.ImportShp(ArgParser arg, String schema, String
table, String column, Int32 srid, String type, String connectionString)
at MsSqlSpatialConsole.Program.Main(String[] args)

What length is it referring to? Why is it failing? I've read here and have been informed that it is best to do these imports from the command line which I am trying to do. As can be seen by the command, I am using the format specified in the example on thegetting started page. In fact I want to make my geometry column called "Shape" and I want to import this into the "Mining" Schema. It was my thought to carry out the task the easy way first then tackle the harder task but I can't even get that to work. Does anyone have any ideas?
Jan 2, 2008 at 9:37 PM
Edited Jan 2, 2008 at 9:39 PM
Tried import using stored Proc

This is is the command

EXEC ST.ImportFromShapefile
@shapefile = N'''C:\HSIP_GOLD2005\HSIP Gold 2005\Data\Infrastructure\Mining\CoalFieldsUS.shp''',
@schema_name = N'''Mining''',
@table_name = N'''CoalFieldsUS''',
@column_name = N'''Shape''',
@srid = -1,
@type = 'shp'

The error message reads:

Msg 6522, Level 16, State 1, Procedure ImportFromShapefile, Line 0
A .NET Framework error occurred during execution of user-defined routine or aggregate "ImportFromShapefile":
System.NotSupportedException: The given path's format is not supported.
System.NotSupportedException:
at System.Security.Util.StringExpressionSet.CanonicalizePath(String path, Boolean needFullPath)
at System.Security.Util.StringExpressionSet.CreateListFromExpressions(String[] str, Boolean needFullPath)
at System.Security.Permissions.FileIOPermission.AddPathList(FileIOPermissionAccess access, AccessControlActions control, String[] pathListOrig, Boolean checkForDuplicates, Boolean needFullPath, Boolean copyPathList)
at System.Security.Permissions.FileIOPermission..ctor(FileIOPermissionAccess access, AccessControlActions control, String[] pathList, Boolean checkForDuplicates, Boolean needFullPath)
at System.IO.FileStream.Init(String path, FileMode mode, FileAccess access, Int32 rights, Boolean useRights, FileShare share, Int32 bufferSize, FileOptions options, SECURITY_ATTRIBUTES secAttrs, String msgPath, Boolean bFromProxy)
at System.IO.FileStream..ctor(String path, FileMode mode, FileAccess access)
at SharpMap.Data.Providers.ShapeFile.ParseHeader()
at SharpMap.Data.Providers.ShapeFile..ctor(String filename, Boolean fileBasedIndex)
at StoredProcedures.ImportFromShapefileMain(String shapefile, String schemaname, String tablename, String column_name, Int32 srid, String type, String connectionString, Int32& importedRows, TimeSpan& elapsedTime)
at StoredProcedures.ImportFromShapefile(SqlString shapefile, SqlString schemaname, SqlString tablename, SqlString column_name, SqlInt32 srid, SqlString type)
.
"Path Format not supported"!!!???

I tried to open the stored procedure to view it to see where it is returning this error but even the sa login was not allow to view the code. Yet other people seem to be having no problems with the import. Their problems come further down the road. So I am thoroughly baffled.

ER Joell