on 07-11-2005 3:09 PM
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
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;
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
User | Count |
---|---|
86 | |
10 | |
10 | |
9 | |
7 | |
7 | |
6 | |
5 | |
4 | |
4 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.