views:

137

answers:

2

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;
}
A: 

You're not closing the connection before disposing the con object.

Try:

con.Close();
con.Dispose();
tomlog
Thanks for your quick response. I tried this, but no effect. I comment this out and it runs, but with the missing things.I tried it also with the Enity Framework, same behavior. SqlCeResultSet result = com.ExecuteResultSet(ResultSetOptions.Scrollable | ResultSetOptions.Updatable); var rec = result.CreateRecord(); rec["TextField"] = composite.StringValue; result.Insert(rec);
Andreas Hoffmann
Thanks i found an Solution, the Problem was the multiple threads.
Andreas Hoffmann
A: 

Could be an exception occuring during the service initialisation when the second client connects. Debug the service at the same time as running the second exe,

Set exception behaviour in VS to break when Common Language Runtime Exceptions are thrown as well as when they're unhandled and you'll see the error.

As tomlog's answer states - it could be because you're not closing the connection properly.

Andras Zoltan
I set an Breakpoint, it doesn't came to the first line of the Server Code.
Andreas Hoffmann
one time it runs now, if i set some breakpoints an debug it :(
Andreas Hoffmann
have you switched on All Exceptions (Debug -> Exceptions -> Tick the 'thrown' checkbox next to Common Lanaguage Runtime Exceptions).My theory is that it's chucking an exception whilst trying to initialise the service instance for the second client, and bombing out. WCF will swallow the exception, hence why you need to have 'break on all exceptions' enabled.
Andras Zoltan
Thanks Andras, i tried this, but no result. I found an soloution.
Andreas Hoffmann