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 application, enabling the application and
the assembly to share the connection.
Use the SetAdoConnection method:
|
1 |
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
|
1 2 3 4 5 6 7 8 9 10 |
//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:
|
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 |
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. } } } ... } |
Document get from Powerbuilder help
Thank you for watching.
Subscribe
Login
0 Comments
Oldest