1
votes

I've been trying to work out how to connect to an ESRI shape file (which I think is a DBase table file) through NHibernate but haven't had any luck with anything I've tried.

Currently, my config's looking like this:

<property name="connection.provider">NHibernate.Connection.DriverConnectionProvider</property>

<!--<property name="dialect">NHibernate.Dialect.GenericDialect</property>
<property name="connection.driver_class">NHibernate.Driver.OdbcDriver</property>
<property name="connection.connection_string">Database=A303.dbf;protocol=TCPIP</property>-->

<property name="connection.driver_class">NHibernate.Driver.OdbcDriver</property>
<!--<property name="connection.connection_string">driver={IBM DB2 ODBC DRIVER};Database=a303.dbf;protocol=TCPIP</property>-->
<property name="connection.connection_string">Provider=VFPOLEDB.1; Data Source=C:\projects\rm4\Sandbox\bin\Debug\A303.dbf;Extended Properties=dBase III</property>
<property name="dialect">NHibernate.Dialect.DB2Dialect</property>
<property name="use_outer_join">true</property>

<property name="proxyfactory.factory_class">NHibernate.ByteCode.Castle.ProxyFactoryFactory, NHibernate.ByteCode.Castle</property>
<property name="show_sql">true</property>

I've left the commented out bits in so you can see what values I've been trying. No matter what I try, I get the error message:

ERROR [IM002] [Microsoft][ODBC Driver Manager] Data source name not found and no default driver specified

I've gone through most of the connection string I've found online and in some answers to questions on here was getting to the 'clutching at straws' phase where I'm just putting anything in so thought I'd better ask for help.

I'm not even sure if it's possible to connect to this type of file from NHibernate but, if it is, does anyone know what should be in the config?

2
On a side note, shapefile attribute tables are stored in a dBase format (can't remember if it's dBase IV or 5, but one of those) so you should be able to read them with any db driver that can read dBase files. Most drivers have you point to a directory as the "database", and then each dbf file in that directory is a table in the database.Michael Todd

2 Answers

1
votes

A Shapefile (.shp) is not a dbf, per se. It actually is a collection of files, one of which is a DBF, but the shapefile itself that stores the geometry is a different format altogether.

There is a whitepaper on the ESRI website (www.esri.com)

0
votes

I would try a different NHibernate driver. Here is a list of NHibernate drivers from the documentation.

Judging from the provider name in your connection string, I would try NHibernate.Driver.OleDbDriver.

Failing this, I would eliminate NHibernate from the mix and see if you can connect using the standard .NET data classes, such as System.Data.Odbc.OdbcConnection and System.Data.OleDb.OleDbConnection. If you cannot connect at this level, then the problem is not NHibernate.