NHibernate & SQL Server CE

42 views
Skip to first unread message

Ross McEwan

unread,
Aug 19, 2008, 1:18:56 AM8/19/08
to nhusers
Hi,
I'm having a bit of an issue with NHibernate and Sql Server CE.
A basic outline of the problem is this:
* We have a solution using Sql Server CE as a local datastore; and
NHibernate with ActiveRecord as the ORM;
* The local datastore is used to store XML submissions that will be
submitted to a central datastore (via WCF) at a later date, on request
from the user;
* We use ActiveRecord to create our schema and the table that stores
the XML has an xmlData column of type 'NText';
* When running this against a Sql Server 2005 database, there are no
problems - the inserts complete successfully and the XML submission
can be saved to the underlying table;
* However, when using CE, an InvalidOperationException occurs, due to
string truncation - the limit being 4000.
* This is not an actual database issue though, this insert can be
successfully executed against the database as the 'NText' column can
easily store the XML data.
* This error stems from the SqlCeCommand.FillParameterDataBindings();
* Now ... I did find this problem reported on some MS forums, and the
fix is a little bit dodgy. Please see the following link:
http://forums.microsoft.com/MSDN/ShowPost.aspx?PostID=2378450&SiteID=1
* It seems that if the parameter is created in a certain manner, then
everything works just fine.
* I created my own driver class that extends the SqlServerCeDriver and
put breakpoints at the GenerateCommand() and InitializeParameter()
methods to interrogate the state of the parameters prior to execution.
* I found that the parameter instance always has the type NVarChar
inferred for it - regardless of what is specified as the sql type -
and if prepare_sql is true, then only the default lengths are set for
these datatypes (which is 4000 for NVarChar);
* I couldn't figure out for myself how to alter this behaviour as it
seems that the issue needs to be fixed in the creating of the
parameter (which is not overridable) or the SqlDbType (on the
SqlCeParameter) needs to be changed (to NText) at a later date with
knowledge of the length of data that is being stored (some types
remain NVarChar).
Hope someone can help.
Thanks.
Reply all
Reply to author
Forward
0 new messages