Friday, February 24, 2012

Connection string for SqlCeConnection

Which format is assumed for connection string for SqlCeConnection?
In help topics there are only examples like this:

... Data Source = 'SalesData.sdf'; ...

But this example is intended for SQL Server 2005 Mobile database located on desktop computer...

I need to custom data load from desktop to device and vice versa, so I did this:

string SqlMobileConnString = "Persist Security Info = False; Data Source = Mobile Device\CF Card\mBase.sdf; File Mode = 'shared read';";

SqlCeConnection SqlMobileConn;
SqlMobileConn = new SqlCeConnection(SqlMobileConnString);
SqlMobileConn.Open();

// Exception!!! Invalid path... I tried to set path like this: "Data Source = My Computer\Mobile Device\..." and old variant with slash: "Data Source = \Mobile Device\...", but nothing was helpful... It's very strange because even SQL Server Management Studio uses this format: "Data Source = Mobile Device\..."

I only know that this format is intended to use from mobile applications:
"Data Source = \CF Card\...". It's quite simple and logically ...

So I don't know what to do... Please help!

P.S. Sorry for my english :)

\ should be escaped as \\ in C#.
Or please use verbatim strings by adding @. to the string.|||

Oh, string is ok, I forgot to set @. here (in code everything was OK).

But I've solved problem with connection!

I used namespace Microsoft.SqlServerCe.Client instead of System.Data.SqlServerCe, in which I found classes identical to classes from the latter one.

Instance of Microsoft.SqlServerCe.Client.SqlCeConnection class connected to my SQL Server 2005 Mobile database on PocketPC through ActiveSync and I viewed data from it on my desktop computer.

Only one question: Where I can find some detailed info about this namespace?
It is located in

C:\Program Files\Microsoft SQL Server\90\Tools\Binn\VSShell\Common7\IDE\Microsoft.SqlServerCe.Client.dll

or

C:\Program Files\Microsoft Visual Studio 8\Common7\IDE\Microsoft.SqlServerCe.Client.dll

I've found no information about this namespace (as for me I've found it searching files *sqlserverce*.dll in My Computer :)

Maybe it is not documented yet...

|||Microsoft.SqlServerCe.Client.dll is not supported and hence not documented.

Thanks,
Laxmi NRO, SQL Mobile, Microsoft|||

in most instances,you have to replace SqlCommand with SqlCeCommand , XxxYxx with XxxCeYyy
(my app was for windows ce 5.0 for symbol 3000 handheld and pocket pc ).

to connect ms sql management studio to .sdf file on visual studio seems to require the non express edition of the sql management studio

|||

How can i do it in VB.NET?

Thanks

Fabio

No comments:

Post a Comment