tdsserver35.exe Error when connecting to SQLCE 3.5 DB’s(on a device) from the Desktop

October 31, 2008

i recently came across this problem when trying to access a sqlce 3.5 db on a device from the desktop… after some googling i found the fix.

problem: when you try to connect to a sqlce 3.5 db on a device, form the desktop using sql management console 2008 or VS 2008sp1(yes 2008 without the sp won’t give this error ,btw you can’t connect to a sqlce 3.5 db with sql management console 2005 or vs 2005) you might get a error like this in the device…

An unexpected error has occoured in TDSSERVER35.EXE

Select Quit and then restart this program, or select Details for more information.

System.Net.Sockets.Socket.

DETAILS:

TDSSERVER35.EXE

ObjectDisposedException

and something like this in the sql management console on the desktop…

Cannot connect to Mobile Device\Program Files\zooApp\zooApp.SDF.

——————————
ADDITIONAL INFORMATION:

Microsoft SQL Server Compact and/or .NET Compact Framework v2.0 or later is not properly installed on your mobile device or the device is not responding. (SQL Server Compact ADO.NET Data Provider)

this is happening because you don’t have the sqlce 3.5 sp1 installed on your device(vs2008 sp1 will install the desktop version of sqlce sp1, but not the device version…). get it from here. after installing it,

go to the folder …:\Program Files\Microsoft SQL Server Compact Edition\v3.5\Devices\wce500\armv4i in your desktop and get the two cab files listed bellow installed in your device.

  1. sqlce.wce5.armv4i.CAB
  2. sqlce.dev.ENU.wce5.armv4i.CAB
  3. sqlce.repl.wce5.armv4i.CAB

note: these might change depending on your device and your ‘needs’ (ie: if you don’t need replication you won’t need the 3rd file)…

now everything should be fine.

ref: http://forums.microsoft.com/MSDN/ShowPost.aspx?PostID=3745016&SiteID=1

download links for sqlce 3.5 sp1: http://blogs.msdn.com/stevelasker/archive/2008/08/07/sql-server-compact-3-5-sp1-released.aspx


XmlSerializer.Deserialize(Stream s) Strips \r out of \r\n !

August 8, 2008

I encountered a bug recently on one of the projects that i am working on. basicaly the program was getting user input through a text box(after wich all the user data gets saved as a object’s properties…) and then seriallizing it to XML and writing it to a DB. afterwards when the user wants to view this data the program would read it off the DB and deserialize the XML string to a object, that can be reprecented to the user.

when the user hit return in the text box to get to a new line it would result in ‘\r\n’ which represents a both carriege return and a new line. now when this data gets serialized, it goes in to the DB as it should. everything is fine until then. but when you try to deserialize this data that includes ‘\r\n’ using XmlSerializer.Deserialize(Stream s), it would strip the ‘\r’ out of every place where you have ‘\r\n’. this made my text boxes display some unreadable chars! this is happening because of the way XmlSerializer.Deserialize(Stream s) works. more details here(this is the page that solved my problem and teached me most of the stuff i am writing here :D ).

a quick solution would be to use something like this…

XmlSerializer.Deserialize(new XmlTextReader(Stream s))

here when you create a XmlTextReader, its XmlTextReaderproperty is by default set to false. but when you use the above mentioned XmlSerializer.Deserialize(Stream s) overload, it internally create a XmlTextReader and sets it’s XmlTextReader to true. which causes the ‘Bug’.

hope this will save some of your/my time in the feutre.


How to Read Private Fields Through Reflection In .net

February 22, 2008

After a long while, no i am not in a mood to blog right now! lol but still i just wanted to share/save this code snippet here in my blog as i could’t  think of a better place :P

Basically this code works on dot net compact framework. and it was written so that i can read a table name that is stored inside a SQLCeResultSet object… this code uses reflection to archive this task :)

//load the assembly by the given name
Assembly asm = Assembly.Load(“System.Data.SqlServerCe”);
//get the type of MetaData the class that holds the needed field
Type MetaData = asm.GetType(“System.Data.SqlServerCe.MetaData”);
//get the Field info for the needed field, baseTableName
FieldInfo FIbaseTableName = MetaData.GetField(“baseTableName”, BindingFlags.Instance | BindingFlags.NonPublic);
//get the FieldInfo for the metadata property in the SQLCeDataReader class.
FieldInfo fi = typeof(SqlCeDataReader).GetField(“metadata”, BindingFlags.Instance | BindingFlags.NonPublic);
//get the metadata array
IList metadataArray = (IList)fi.GetValue(rsSeek);
//get the table name that we want
Debug.Assert(metadataArray.Count > 0);
string tableName = (string) FIbaseTableName.GetValue(metadataArray[0]);

thats it folks, i hope this would help someone out in the future(including my self :) ). read the comments if you have any doubts about how this works.