0

(This relates to Microsoft's SitkaSoapService, in the service reference at https://database.windows.net/soap/v1/)

I'm using SitkaSoapServiceClient to access my SQL Data Services database by SOAP.

Should I use a "using" statement every time I use this proxy class? Or does it do its own connection handling in a safe way internally?

I.e. do I need to say:

using (SitkaSoapServiceClient proxy = GetProxy())
    proxy.Update(scope, entity);

... or is it safe to say:

GetProxy().Update(scope, entity);

[where GetProxy() returns a SitkaSoapServiceClient object.]

sds
  • 58,617
  • 29
  • 161
  • 278
teedyay
  • 23,293
  • 19
  • 66
  • 73

2 Answers2

0

Does the proxy class code compile when wrapped in a using statement? If so, it implements IDisposable and I'd use it.

EDIT: calling Dispose() should incur little overhead if it does nothing, and if the designer of the class decides at a later date to allocate unmanaged resources you will be protected from a leak.

Mitch Wheat
  • 295,962
  • 43
  • 465
  • 541
  • It does implement IDisposable, but I remember there being a similar debate around LinqToSql's DataContext - this implements it too, but the Microsoft brains behind it swore that the "using" was unnecessary. – teedyay Feb 13 '09 at 09:50
0

You should always use using when the class implements IDisposable, because the author of the class tells you that it contains some resources that should be freed.

Grzenio
  • 35,875
  • 47
  • 158
  • 240