Can't Serialize SqlConnection

  • Thread starter Thread starter Andrew Alford
  • Start date Start date
A

Andrew Alford

I have a class that I created that requires me to serialize it for
specific reasons. I have an SqlConnection that is a private member of
the class, and therfore the serialization fails. The SqlConnection
must be private as it is shared by many sub routines within the class.
How do I get around this? Is it possible to serialize the
SqlConnection Class?

Thanks for your help in advance!

Andrew Alford
 
I don't think you can get around it. The SqlConnection class is not
serializable (understandably), so there is really not much you can do if you
class has that as a member.

Maybe you can keep the connection string as a member, which would be
serializable.
 
I don't think you can get around it. The SqlConnection class is not
serializable (understandably), so there is really not much you can do if you
class has that as a member.

Maybe you can keep the connection string as a member, which would be
serializable.
Yes greath serializing the connection string

:-)

Cor
 
You could mark the private member with the NonSerializedAttribute so that
the rest of the class could be serialized.

HTH,
Greg
 
Excellent! This solves my problem completely. I'd only thought about
serialization in the context of defining the class - rather than during
dimensioning.

Thanks to all for your help

Andrew Alford
 
Back
Top