Thursday, February 16, 2012

About PlatformNotSupportedException in WM 5.0 with SQL Server

Hi All, I am now trying to develop an application connecting to a remote SQL server in a PDA with Windows Mobile 5.0 in Visual Studio.

I have installed SDK for WM5.0 for the development.

But I got the following Exception

System.PlatformNotSupportedException was unhandled
Message="PlatformNotSupportedException"
StackTrace:
at System.Globalization.CultureInfo..ctor()
at System.Globalization.CultureInfo..ctor()
at System.Data.SqlClient.TdsParser.GetCodePage()
at System.Data.SqlClient.TdsParser.ProcessEnvChange()
at System.Data.SqlClient.TdsParser.Run()
at System.Data.SqlClient.TdsParser.Run()
at System.Data.SqlClient.SqlInternalConnection.Login()
at System.Data.SqlClient.SqlInternalConnection.OpenAndLogin()
at System.Data.SqlClient.SqlInternalConnection..ctor()
at System.Data.SqlClient.SqlConnection.Open()
at System.Data.Common.DbDataAdapter.QuietOpen()
at System.Data.Common.DbDataAdapter.FillInternal()
at System.Data.Common.DbDataAdapter.Fill()
at System.Data.Common.DbDataAdapter.Fill()
at DeviceApplication1.rfidcpsDataSetTableAdapters.VehicleTableAdapter.Fill()
at DeviceApplication1.Form1.Form1_Load()
at System.Windows.Forms.Form.OnLoad()
at System.Windows.Forms.Form._SetVisibleNotify()
at System.Windows.Forms.Control.set_Visible()
at System.Windows.Forms.Application.Run()
at DeviceApplication1.Form1.Main()

I just cannot figure what's the problem. Please help me! Thanks a lot!

That means you're trying to use locale which is not supported on your device (or emulator). With SQL Client it happens if your database has collation which is not available on device.

How to fix it:

1. Get device/emulator which supports collation you're using in your database (best way to go). Usually that would be device localized in particular language.

2. Purchase and install localization package on to your device. Note: some of these packages are do not provide complete localization required by NETCF and might not work, so test before you buy.

3. Change database collation to whatever is supported on your device. This one has consequences of potentially incorrect sorting, etc. Please refer to SQL Server documentation for collation impact.

|||

Thanks. Actually my database is just in English and no other language.

So I go for changing database collation. But in the Option, I don't know which one is supported in my PDA (Dell Axim X51v). In the PDA with WM 5.0, the regional setting is to English(United States). In th SQL Server Database collation, it was set to Chinese_Hong_Kong_Stroke_90_CI_AI_WS.

Can you tell me which collation I should set to as well as the locale setting in the PDA?

Thanks a lots!

|||

If your device is in English then I would guess something like SQL_Latin1_General* in it would do.

|||

I tried to change the database collation to "SQL_Latin1_General_CP1_CI_AI", with PDA setting to English(United States), but the same error came out!

Here comes my code and error

Dim sqlConnection1 As New SqlConnection("Data Source=BILLY\SQLEXPRESS;Initial Catalog=rfidcps;Persist Security Info=True;User ID=*****; Password=****;")

Dim cmd As New SqlCommand

Dim reader As SqlDataReader

cmd.CommandText = "SELECT * FROM Vehicle WHERE MainTagID = '123''"

Dim i As Integer = 0

cmd.CommandType = CommandType.Text

cmd.Connection = sqlConnection1

sqlConnection1.Open()

reader = cmd.ExecuteReader()

--

ERROR

System.PlatformNotSupportedException was unhandled
Message="PlatformNotSupportedException"
StackTrace:
at System.Globalization.CultureInfo..ctor()
at System.Globalization.CultureInfo..ctor()
at System.Data.SqlClient.TdsParser.GetCodePage()
at System.Data.SqlClient.TdsParser.ProcessMetaData()
at System.Data.SqlClient.TdsParser.Run()
at System.Data.SqlClient.SqlDataReader.ConsumeMetaData()
at System.Data.SqlClient.SqlDataReader.get_MetaData()
at System.Data.SqlClient.SqlCommand.ExecuteReader()
at System.Data.SqlClient.SqlCommand.ExecuteReader()
at RFIDApp.Form1.Form1_Load()
at System.Windows.Forms.Form.OnLoad()
at System.Windows.Forms.Form._SetVisibleNotify()
at System.Windows.Forms.Control.set_Visible()
at System.Windows.Forms.Application.Run()
at RFIDApp.Form1.Main()

Can any one help me?

|||

Use debugger to see which locale/LCID it's trying to use. Try another collation.

I'm also quite surprised you can even connect to the server - named instances do not work with devices because there's no support for named pipes. Are you running another SQL Server by any chance? Since you obviously can connect I would suspect this connection is made to the wrong server and you're changing collations not on the database you're connecting to. See this for more info on SQL Express connections from NETCF.

|||

"Use debugger to see which locale/LCID it's trying to use."

-> How can I check it?

Actually I did try to use the emulator to run but I failed to run and showed some error. So I stopped to carry on.

Ha, I don't know why, but, I can sure that my computer has only one instance of SQL Server (SQL Server Express Edition). So, the collation setting is the right one I used.

Any other advice? Thanks a lot!

|||

In the Debug/Exceptions... menu check the "Thrown" box for CLR exception. Run to the right exception and look at call stack window, you'll see something like this on the top:

mscorlib.dll!System.Globalization.CultureTableRecord.GetCultureTableRecord(int cultureId = 4556, bool useUserOverride = true) + 0x3c bytes

First number is a culture ID it's trying to get, should be 1033 for ENU. It would be something else in your case, look up which culture is that on MSDN.

Have you tried localized emulator, e.g. in CHT?

Try following the tutorial. Try changing collation for entire SQL Server Express.

|||

Thanks. I've used your method to check the cultureID. The conclusion is that it is set to 0xC04 Chinese (Hong Kong SAR, PRC)

I think it is the problem!! But how can I really change it to other value? How to chang this ID to ENGLISH?

Thanks a lot for your help!

|||

You already know that – you need to change database collation. It’s pretty clear what your attempt to change it has failed and you’re still using Chinese_Hong_Kong_Stroke_90_CI_AI_WS so client if forced to create matching locale (Chinese (Hong Kong SAR, PRC)) which is failing because your device does not support it.

I don’t know why it did not work, I would suggest asking in SQL Express forum. Perhaps SQL Express only allows one collation per server or something…

Also try creating brand new database with some ENU collation, see if that works.

|||

Yes, I finally understand the problem.

But what makes trouble is that I DID reinstall the SQL server express for changing the collation at server-level to Latin1_General_CI_AI,

Also, I DID change the database collation to Latin1_General_CI_AI as well! But how come from the debugger, the locale is Chinese (Hong Kong SAR, PRC)!!!!!!!

I have double-checked the setting in SQL Server Managment Studio Express! I tried to restart my computer as well but there's no change!!

Feel so lost!

|||I'm with Ilya on this one, please post this question in the SQL Server forum|||Thanks all of you. Hope someone could help me. :)

No comments:

Post a Comment