views:

189

answers:

1

LATER EDIT : It was me :( It was a non-nullable column left unfilled. Sorry to everyone I confused..

I am having issues with an INSERT statement generated by NHibernate because it formats the decimal numbers using the regional settings. The generated statement goes something like :

exec sp_executesql N'INSERT INTO [TableName] (
    Column1, 
    Column2, 
    Column3, 
    Column4, 
    Column5, 
    Column6, 
    Column7, 
    Column8, 
    Column9, 
    Column10) 
VALUES (@p0, 
    @p1, 
    @p2, 
    @p3, 
    @p4, 
    @p5, 
    @p6, 
    @p7, 
    @p8, 
    @p9); 

select SCOPE_IDENTITY()',

N'@p0 float,@p1 float,@p2 float,@p3 float,@p4 int,@p5 datetime,@p6 nvarchar(69),@p7 int,@p8 int,@p9 int',
@p0=0,
@p1=0,
@p2=589186,74188329,           -- <-- here is my problem
@p3=320829,21535209997,        -- <-- here is my problem
@p4=6,
@p5='2009-05-10 17:00:00',
@p6=N'Some string value',
@p7=232323,
@p8=2,
@p9=1

As you can see there is a comma used as a decimal separator which screws up the parameters value list.

I have not found anywhere a way to set the culture used to format the numbers so the statement would get generated in a valid form.

I set the Thread.CurrentCulture and CurrentUICulture to en-us right before the Save method call on the ISession but nothing happened.

What can be done? :(

+1  A: 

But this list with formatted numbers is only for display purposes - the values being set as the parameters are set as floating point numbers. This shouldn't cause the INSERT to fail in any way.

Are you just anticipating a problem, or are you actually getting an error? If you are getting an error, what is it?

David M
This query has been intercepted in SQL Server Profiler. It is the query actually sent.
Andrei Rinea
Yes, but it is a parameterised query, and where the parameter values are being written out they are being formatted. But where they are set, they are set as native float values.
David M
Well it's actually failing reporting exactly this issue.
Andrei Rinea
I've switched my regional settings from Romanian to English (United States) and now it's ok, there are dots instead of commas and the statement doesn't fail anymore. How could I convince NHibernate to work on other regional settings? :((((((
Andrei Rinea
OK - so can you post the details of the exception?
David M
Post the code that generates the statements. I use NHiberante with comma locale and I didn't had to change anything.
Paco
I am so sorry, my mistake. It was a non-nullable column. I saw the INSERT fail, captured it with SQL Profiler and looked over the string. Seeing the commas there made me think they were the culprit. A thousand appologies :( I will close the question.
Andrei Rinea