4

My application works with IBM DB2 via their .net provider(FP5). When i left application for a long time and after that try to get anything from database- i get the following error:

---> IBM.Data.DB2.DB2Exception: ERROR [08001] [IBM] SQL30081N A communication error has been detected. Communication protocol being used: "TCP/IP". Communication API being used: "SOCKETS". Location where the error was detected: "SERVER_IP". Communication function detecting the error: "recv". Protocol specific error code(s): "10054", "*", "0". SQLSTATE=08001

I use entity framework to communicate with the database and before the crashing operations i always have the following code:

using (EEntities db =  EntitiesFactory.CreateEEntity())
                {
                    // ..some operations
                }   

where:

public static EEntities CreateEEntity()
        {
            if (!string.IsNullOrEmpty(GlobalCommon.DBConnectionString))
                return CreateEEntity(GlobalCommon.DBConnectionString);
            return new EEntities();
        }

        public static EEntities CreateEEntity(string connectionString)
        {
            return new EEntities(connectionString);
        }

and:

public static string DBConnectionString
        {
            get
            {
                if (!string.IsNullOrWhiteSpace(_DBConnectionString))
                    return _DBConnectionString;

                string providerConnectionString = "Database=" +
                    Settings.Default.DBDatabase + ";User ID=" +
                    DBUserID + ";Password=" +
                    DBPassword + ";Server=" +
                    DBServer + ";Max Pool Size=150;Min Pool Size=15;Connection Lifetime=80;Pooling=true;";


                // Initialize the EntityConnectionStringBuilder.
                EntityConnectionStringBuilder entityBuilder =
                    new EntityConnectionStringBuilder();

                //Set the provider name.
                entityBuilder.Provider = "IBM.Data.DB2";

                // Set the provider-specific connection string.
                entityBuilder.ProviderConnectionString = providerConnectionString;

                // Set the Metadata location.
                entityBuilder.Metadata = @"res://*/DAL.DBModel.csdl|
                            res://*/DAL.DBModel.ssdl|
                            res://*/DAL.DBModel.msl";
                _DBConnectionString = entityBuilder.ToString();

                return _DBConnectionString;
            }
            set
            {
                _DBConnectionString = value;
            }
        }

so that i think with following lines i always do reconnect if the connection was terminated.
Can there be a problem with pooling or connection lifetime?..

1 Answer 1

2

This error typically means that your connection has been killed by the DBA, or that there was a network blip that broke the connection from your application.

If you get this error, just reconnect to the database.

3
  • But how to reconnect?.. if i call using (EEntities db = EntitiesFactory.CreateEEntity()) again doesnt it mean that it reconnects?
    – 0x49D1
    Commented Jun 27, 2012 at 6:47
  • It would seem that somehwere EntitesFactory creates an EntityConnection object – you can check the State property for this object to see if the connection is still open and if appropriate call the Open method to reconnect. Commented Jun 27, 2012 at 7:23
  • Just wondered why the method CreateEEntity() creates new entity object, so that new connection that is Open(as i thought..) Still added the check there.
    – 0x49D1
    Commented Jun 27, 2012 at 7:33

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.