Search code examples
c#wpfsql-server-ceconnection-string

Connect WPF app to SQL Server CE 3.5 file shared on LAN


How can I connect my C# WPF app to a SQL Server CE 3.5 .sdf file, placed on a shared location on LAN? I couldn't figure out what value to be used as Data Source in the connection string. I have a PC on my LAN, with name RT-PC, and it has a shared folder, named RSDB-prod. I tried to connect using following string:

<add name="RSEntitiesLan" 
     connectionString="metadata=res://*/Model.RsModelLan.csdl|res://*/Model.RsModelLan.ssdl|res://*/Model.RsModelLan.msl;provider=System.Data.SqlServerCe.3.5;provider connection string=&quot;Data Source=\\RT-PC\RSDB-prod\RsCompact.sdf;Password=123&quot;" 
     providerName="System.Data.EntityClient" />

Here, Password=123 is the password of the RsCompact.sdf file.

I also tried supplying User Id section, but It also did not work.

I tried to look for the solution and looked at several SO posts, like THIS, THIS, and THIS, but none discussed about LAN scenario as I require. I have following concerns/questions.

Questions:

  • How can I connect to a SQL Server CE 3.5 file, located on shared LAN PC from my WPF app?

  • How to change connection strings accordingly, when LAN PC has logon username and password set? My .sdf db file also has password

  • I have a PC on LAN, that has username, but no password. Would it be possible to connect that PC? If so, how?

Other info:

  • This is a WPF app, which need to store/retrieve data on/from .sdf file at server PC on LAN. When that PC is connected to internet, all data is copied to remote SQL Server db.

  • Above connection string works fine, if I change the DataSource to the same PC as C:\dbfile\xyz.sdf for instance. Now I need to deploy this system, so need to modify connection string accordingly


Solution

  • What does "not work" mean?

    Using SQL Compact for this scenario is not supported, you should use SQL Server Express instead