This project is read-only.

Import shape file fais

Topics: Developer Forum
Jan 9, 2008 at 4:56 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 than 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?


Also 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. I really need to able to resolve this within the next couple of days because of the time it will take to carry out the import before the deadline.

ER Joell
Jan 14, 2008 at 11:44 AM
Edited Jan 14, 2008 at 2:27 PM
If you are running the stored procedure make sure the .shp and .dbf are both on the database server at the given path. It will not work from a client machine. The database process identity (often Network Service or System) must also have permissions to access the target folder. I think you may also need to remove the inner quotes from the param e.g
@shapefile = N'''C:\HSIP_GOLD2005\HSIP Gold 2005\Data\Infrastructure\Mining\CoalFieldsUS.shp''' should be
@shapefile = N'C:\HSIP_GOLD2005\HSIP Gold 2005\Data\Infrastructure\Mining\CoalFieldsUS.shp'

Also: I have previously had trouble if any of the files (.shp .dbf etc ) are readonly... e.g came out of a source control repository..

Personally I always use the mssql console
HTH jd
Jan 29, 2008 at 10:05 PM
The dbf and shp and all the rest are in the the same directory in the given path. Took out the extra quotes inserted by the Management Studio "Execute Stored Procedure" interface. I am logged on the machine with admin rights and into SQL server as sa. I now get the following permission denied message.


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.Security.SecurityException: Request for the permission of type 'System.Security.Permissions.FileIOPermission, mscorlib, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089' failed.
System.Security.SecurityException:
at System.Security.CodeAccessSecurityEngine.Check(Object demand, StackCrawlMark& stackMark, Boolean isPermSet)
at System.Security.CodeAccessPermission.Demand()
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)
.
Mar 28, 2011 at 8:56 AM

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"

should be

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