How to create Visual Components in PowerBuilder for Visual Studio Developers
Another of the latest videos from the SAP Database and Tools Academy (http://www.youtube.com/user/saptechnology/videos?query=PowerBuilder).
The video is pretty much self explanatory. Just reiterate the main points here and provide some of the sample code.
1. Create a .Net assembly target and select CustomVisual as the object type to be created.
2. Create your visual user object in the WPF panel that is presented.
3. Go to the Objects tab on the project and make sure you select the visual component you want to deploy.
4. In addition to the assembly containing your visual component, PowerBuilder will place the following runtime assemblies in the output folder. Give all of them to the Visual Studio developer.
com.sybase.iiop.net.dll
Sybase.DataWindow.Common.dll
Sybase.DataWindow.Core.dll
Sybase.DataWindow.Interop.dll
Sybase.DataWindow.Shared.dll
Sybase.DataWindow.WPF.dll
Sybase.PowerBuilder.Common.dll
Sybase.PowerBuilder.Common.xml
Sybase.PowerBuilder.Compiler.Assist.dll
Sybase.PowerBuilder.Core.dll
Sybase.PowerBuilder.Core.xml
Sybase.PowerBuilder.DataSource.Db.dll
Sybase.PowerBuilder.DataSource.dll
Sybase.PowerBuilder.Interop.dll
Sybase.PowerBuilder.WPF.Controls.dll
Sybase.PowerBuilder.WPF.Controls.Skins.dll
Sybase.PowerBuilder.WPF.Controls.xml
Sybase.PowerBuilder.WPF.dll
Sybase.PowerBuilder.WPF.xml
5. The visual studio developer will create a reference in their Toolbar to the new WPF control by selecting Choose Items… and then using the Browse option under WPF control to navigate to your assembly and then select the visual control within it.
6. The Visual Studio developer can now drop the PowerBuilder visual object onto a WPF window in their application. There may be a couple of errors the first time they attempt to compile the application:
a. If the WPF application has been created with a Target Framework Reference of “.Net Framework 4 Client Profile” they will need to change it to “.Net Framework 4”. The assembly that PowerBuilder created indicates it has a dependency on System.Web, which is not included in the Client Profile version of the target framework.
b. When the Visual Studio developer added your component to their WPF window, Visual Studio automatically added a reference to it to the project. The Visual Studio developer will also need to add an explicit reference to Sybase.PowerBuilder.WPF.Controls to the project.
If you are incorporating a DataWindow control in your custom visual user object, you will need to make a few additional changes.
1. Assuming that you are going to be using ADO.Net to connect to the database, you will need to provide these additonal runtime assemblies to the Visual Studio developer. Note that PowerBuilder will not automatically copy them to the output folder for you.
Sybase.PowerBuilder.ADO.dll
Sybase.PowerBuilder.DataSource.Db2.dll
Sybase.PowerBuilder.DataSource.Sharing.dll
Sybase.PowerBuilder.Db.dll
Also note that the following runtime assemblies will also need to be given to the Visual Studio developer, because the DataWIndow uses them to read SRD files:
antlr.runtime.dll
Antlr3.Runtime.dll
2. The Visual Studio developer will need to add explicit references to the antlr3.runtime.dll and Sybase.PowerBuilder.DataSource.Sharing.dll assemblies.
3. If you want to have the Visual Studio developer pass in an established connection to the database and have the DataWindow within the PowerBuilder component use it instead of establishing it’s own seperate connection to the database, you’ll need to add a method to the custom visual user object that takes an argument of System.Object and then uses the SetAdoConnection method on the transaction object to assign that argument as a proxy connection. For example:
boolean lb_rc
integer li_rc
try
SQLCA.DBMS = "ADO.Net"
SQLCA.DBParm = "Namespace='Oracle.DataAccess.Client'"
lb_rc = sqlca.SetAdoConnection(a_conn)
if not lb_rc then
MessageBox ( "Error", "SetAdoConnection failed" )
return -1
else
connect using sqlca ;
if sqlca.SQLCode <> 0 then
MessageBox ( "Error", "Connect failed: " + sqlca.SQLErrText )
return -1
else
li_rc = dw_1.SetTransObject ( sqlca )
if li_rc < 0 then
MessageBox ( "Error", "SetTransObject failed" )
return -1
else
return 1
end if
end if
end if
catch ( Throwable e )
Exception exp
exp = create Exception
exp.SetMessage(e.GetMessage())
throw exp
end try
4. The Visual Studio developer then creates a proxy object based on the IAdoConnectionProxy interface, create it based on AdoConnectionProxy, assigns the connection and transaction to it, and passes into your method on the custom visual user object.
short rc;
String connectString = "Data Source=//oracle:1521/orcl;User Id=scott;Password=tiger2";
Oracle.DataAccess.Client.OracleConnection conn = new Oracle.DataAccess.Client.OracleConnection(connectString);
conn.Open();
Oracle.DataAccess.Client.OracleTransaction trans = conn.BeginTransaction();
Sybase.PowerBuilder.DataSource.Sharing.IAdoConnectionProxy proxy;
proxy = new Sybase.PowerBuilder.DataSource.Sharing.AdoConnectionProxy();
proxy.Connection = conn;
proxy.Transaction = trans;
rc = u_customvisual1.AssignConnection(proxy);
5. Note that when you have methods you want to expose on the custom visual user object, you select those rather than the custom visual user object in the project painter, so that PowerBuilder knows it needs to expose those methods on the control in the assembly.
I'm having a problem getting a visual component with a datawindow to connect to the db. I've tried SQL Anywhere 12 and MS SQL Server with no luck. Creating the assembly and adding it to the toolbar all works fine. The component gets added to my WPF window although I don't see the datawindow object in the design painter of VS. I am using ADO to connect. It works just fine when adding the assembly as a reference to a PB WPF target (on the same machine) but not on a C# target on a different VM in VS. The System.Data assembly is in my reference list along with all the others you listed. What am I missing?
Not sure off the top of my head.
>>although I don't see the datawindow object in the design painter of VS.
You should. Note in the video that I do. You might be missing one or more runtime assemblies. You might also be missing the datawindow object.
Can the Visual Studio app make it's own connection to the database? That would indicate you have all the client pieces in place.
What kind of error messages do you get when attempting to connect? Or where is the failure occurring?
Is it possible to use the components in PowerBuilder 12.6 for Visual Studio 2005? I have an application in VS2005 that cannot upgrade to VS2010+