English 中文(简体)
SQL Compact allow only one WCF Client
原标题:

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;
}
最佳回答

I used the wrapper in http://csharponphone.blogspot.com/2007/01/keeping-sqlceconnection-open-and-thread.html for threat safty, and now it works :)

问题回答

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

Try:

con.Close();
con.Dispose();

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.





相关问题
Anyone feel like passing it forward?

I m the only developer in my company, and am getting along well as an autodidact, but I know I m missing out on the education one gets from working with and having code reviewed by more senior devs. ...

NSArray s, Primitive types and Boxing Oh My!

I m pretty new to the Objective-C world and I have a long history with .net/C# so naturally I m inclined to use my C# wits. Now here s the question: I feel really inclined to create some type of ...

C# Marshal / Pinvoke CBitmap?

I cannot figure out how to marshal a C++ CBitmap to a C# Bitmap or Image class. My import looks like this: [DllImport(@"test.dll", CharSet = CharSet.Unicode)] public static extern IntPtr ...

How to Use Ghostscript DLL to convert PDF to PDF/A

How to user GhostScript DLL to convert PDF to PDF/A. I know I kind of have to call the exported function of gsdll32.dll whose name is gsapi_init_with_args, but how do i pass the right arguments? BTW, ...

Linqy no matchy

Maybe it s something I m doing wrong. I m just learning Linq because I m bored. And so far so good. I made a little program and it basically just outputs all matches (foreach) into a label control. ...

热门标签