Importing an ADO.NET Connection from a Third-Party .NET Assembly

You can import an ADO.NET connection from an external .NET assembly into a PowerBuilder Classic application, enabling the application and the assembly to share the connection.

Use the SetAdoConnection method:

bool SetAdoConnection(oleobject proxy)

where proxy is the instance of type IAdoConnectionProxy that is passed in by the third-party assembly.

The imported connection and any transaction are assigned to the IAdoConnectionProxy instance.

The method returns true if the parameter is available (that is, the parameter is an instance of IAdoConnectionProxy or null). It returns false if the operation fails.

Start the connection after invoking SetAdoConnection.

Sample PowerScript Code

//Sample PowerScript code 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

Sample C# Code

Here is an example of C# code in the third-party assembly:

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. } } } ... }