aEk BKF
aEk BKF

Reputation: 131

How to connect to sdf file database on network

I developed a desktop application with c# 2010, I have a local .sdf (SQL Server Compact edition) database.

I want to install my application in an other PC, so what should I do to connect to the database? I tried to modify my connection string where I set my pc IP and username/password pc, it doesn't work.

Someone help me please. Thanks.

Upvotes: 0

Views: 1350

Answers (2)

03Usr
03Usr

Reputation: 3435

Your title says you want it on the network but then in the question you are talking about installing it on another pc, if you wish to install the app on another pc you can set the .sdf file as a required data file and once installed the .sdf file will be copied to the users machine, this way each user will have their own copy of the database if that's something you want to do.

And this is the way to connect to the database from within your app - Make sure the .sdf file is in the same directory ad the exe:

public static string Dbfile = "YourDbFile.sdf";

using (var cn = new SqlCeConnection("datasource=" + Dbfile))
using (var cmd = new SqlCeCommand("Select * From yourTable", cn))
{
   cn.Open();
   /// do stuff
}

Upvotes: 0

ErikEJ
ErikEJ

Reputation: 41779

Connecting to a SQL Server Compact database file (.sdf) over a network is not supported, use SQL Server Express for this scenario.

Upvotes: 1

Related Questions