You can import an ADO.NET connection from an external .NET assembly into a PowerBuilder WPF application, enabling the application and the assembly to share the connection.
Follow these guidelines:
SQLCA.DBMS = "ADO.NET" SQLCA.AutoCommit = true SQLCA.DBParm = "Namespace='System.Data.Odbc', DataSource='SQL Anywhere 11 Demo'" bool retVal = SQLCA.SetAdoConnection(emp.AdoConnectionProxy) // emp is an instance of a type in the 3rd-party .NET assembly if (retVal = true) then connect using SQLCA; // db operations end if
public class Emp {
private IDbConnection conn;
private IDbTransaction trans;
...
private IAdoConnectionProxy proxy;
...
public object AdoConnectionProxy {
get {
//disposing/clean-up actions.
if (null == proxy) {
proxy = new AdoConnectionProxy();
}
proxy.Connection = conn;
proxy.Transaction = trans;
return proxy;
}
set {
//disposing/clean-up actions.
proxy = value as IAdoConnectionProxy;
if (null != proxy) {
if (conn != proxy.Connection as IDbConnection)
this.Disconnect();
conn = proxy.Connection as IDbConnection;
trans = proxy.Transaction as IDbTransaction;
proxy.TransactionChanged += new EventHandler(proxy_TransactionChanged);
} else {
//disposing/clean-up actions.
}
}
}
...
}