cancel
Showing results for 
Search instead for 
Did you mean: 

SAPProxy.close()

Former Member
0 Kudos

Hi,

if i call to opened SapProxy class sapProxy.connection.close() method the connectionstring in Sapproxy.connection is set to "". and then i can not open SAPproxy.connection again. is this bug ? how can i open it again?

thanx Palo

Accepted Solutions (0)

Answers (1)

Answers (1)

reiner_hille-doering
Active Contributor
0 Kudos

This is not a bug, but by design. This follows the general .NET Dispose pattern: Once an object implementing IDispose is disposed, it cannot be used again. Here are the possible options:

1. Just keep proxy and connection living as long as you need.

2. Keep connection separated and assign to proxy instances as needed:

Connection conn = Connection.GetNewConnection(connStr);

...

SAPProxy1 proxy1 = new SAPProxy1();

proxy1.Connection = conn;

// do calls here.

proxy1.Connection = null;

...

SAPProxy2 proxy2 = new SAPProxy2();

proxy2.Connection = conn;

// do calls here.

proxy2.Connection = null;

...

conn.Dispose(); // or Close

3. Re-create connection each time (slow):

SAPProxy1 proxy = new SAPProxy1();

proxy.Connection = Connection.GetNewConnection(connStr);

// or equivalent: SAPProxy1 proxy1 = new SAPProxy1(connStr);

// Calls here

proxy.Connection.Close();

...

proxy.Connection = Connection.GetNewConnection(connStr);

...

proxy.Dispose(); // The same as proxy.Connection.Dispose();

4. Use Connection Pool (recommended):

SAPProxy1 proxy = new SAPProxy1();

proxy.Connection = Connection.GetConnectionFromPool(connStr);

// Calls here

Connection.ReturnConnection(proxy.Connection);

proxy.Connection = null;

...

proxy.Connection = Connection.GetConnectionFromPool(connStr);

// Calls here

Connection.ReturnConnection(proxy.Connection);

proxy.Connection = null;