SQL Compact allow only one WCF Client
Posted
by Andreas Hoffmann
on Stack Overflow
See other posts from Stack Overflow
or by Andreas Hoffmann
Published on 2010-01-15T13:18:13Z
Indexed on
2010/05/23
2:30 UTC
Read the original article
Hit count: 457
Hi,
I write a little Chat Application. To save some infos like Username and Password I store the Data in an SQL-Compact 3.5 SP1 Database.
Everything working fine, but If another (the same .exe on the same machine) Client want to access the Service. It came an EndpointNotFound exception, from the ServiceReference.Class.Open() at the Second Client.
So i remove the CE Data Access Code and I get no Error (with an if (false))
Where is the Problem? I googled for this, but no one seems the same error I get :(
SOLUTION
I used the wrapper in http://csharponphone.blogspot.com/2007/01/keeping-sqlceconnection-open-and-thread.html for threat safty, and now it works :)
Client Code:
public test()
{
var newCompositeType = new Client.ServiceReference1.CompositeType();
newCompositeType.StringValue = "Hallo" + DateTime.Now.ToLongTimeString();
newCompositeType.Save = (Console.ReadKey().Key == ConsoleKey.J);
ServiceReference1.Service1Client sc = new Client.ServiceReference1.Service1Client();
sc.Open();
Console.WriteLine("Save " + newCompositeType.StringValue);
sc.GetDataUsingDataContract(newCompositeType);
sc.Close();
}
Server Code
public CompositeType GetDataUsingDataContract(CompositeType composite)
{
if (composite.Save)
{
SqlCeConnection con = new SqlCeConnection(Properties.Settings.Default.Con);
con.Open();
var com = con.CreateCommand();
com.CommandText = "SELECT * FROM TEST";
SqlCeResultSet result = com.ExecuteResultSet(ResultSetOptions.Scrollable | ResultSetOptions.Updatable);
var rec = result.CreateRecord();
rec["TextField"] = composite.StringValue;
result.Insert(rec);
result.Close();
result.Dispose();
com.Dispose();
con.Close();
con.Dispose();
}
return composite;
}
© Stack Overflow or respective owner