3

I'm needing some assistance on a problem I can't seem to find a resolution for. I have a SQL Server stored procedure accepting two nvarchar parameters. Within my C# code, I call the SP using the following set-up:

searchStringParameter = new ObjectParameter("searchString", "有者明确的");

filterParameter = new ObjectParameter("filterParameter", "Approved");

return base.ExecuteFunction<Nullable<global::System.Int64>>("Find", searchStringParameter, filterParameter);

However, on the SQL Server end, it captures the parameters as: "?????" (5 x question marks) and "Approved".

Any ideas?

stats101
  • 1,837
  • 9
  • 32
  • 50
  • Are you sure that the data is really lost, or is it just the font used when presenting the data in the SQL Server end that lacks those characters? – Anders Abel Nov 28 '11 at 18:20
  • @Anders the data is lost. I'm expecting a row to be returned as part of the SP call. Running the SP within SQL Server, returns the correct results, however running through C# brings back no rows. The conclusion I'm making is (after stepping through both bits of code), is that between the ExecuteFunction call, and the SP picking it up, the values are lost. – stats101 Nov 28 '11 at 18:25
  • Hmmm, im thinking there is some kind of code page conversion going on and there is not a mapping for the characters you are passing in. What is the local of you PC vs the default language of your SqlServer. [This](http://stackoverflow.com/questions/5180764/sql-server-code-pages-and-collations) previous post might be of some help. – user957902 Nov 28 '11 at 22:01
  • You can get the default collation for the SqlServer instance with select SERVERPROPERTY(N'Collation'). I am assuming that you are using SQLServer 2008. – user957902 Nov 28 '11 at 22:09
  • @957902 I am working with SQL Server 2008. The above function returns an error: "Incorrect syntax near 'Collation'". – stats101 Nov 29 '11 at 10:47
  • @957902 I've ran this command: SELECT CONVERT(sysname, SERVERPROPERTY(N'Collation')); and I get 'Latin1_General_CI_AS'. As I mentioned earlier however, running the SP within SQL Server with the same parameters works, so would that not be good enough reasoning to why it's not a configuration issue? – stats101 Nov 29 '11 at 10:48
  • Is the Locale of the PC you are running your .Net code from anything other than US English ? – user957902 Nov 29 '11 at 11:54
  • It's on English United Kingdom. – stats101 Nov 29 '11 at 12:26

1 Answers1

1

We had a similar situation because our SP had originally defined the parameter as varchar instead of nvarchar. At some point it was corrected to nvarchar.

We would still see unicode on C# side and "?"'s on the Sql server side.

However then doing an EF6 "Update" did not change the edmx. It was necessary to:

  1. Manually open the edmx using right click "Open With... Xml", then
  2. Find the parameter names and change them from varchar to nvarchar.

It wasn't possible to change these fields using the "Model Browser" Properties (F4).

Hope it helps.

crokusek
  • 5,345
  • 3
  • 43
  • 61