Using the ADO.NET Database Profile Setup
To define a connection using the ADO.NET interface, you must create a database profile by supplying values for at least the basic connection parameters in the Database Profile Setup -- ADO.NET dialog box. You can then select this profile at any time to connect to your data in PowerBuilder.
For information on how to define a database profile, see Using database profiles.
Specifying connection parameters
You must supply a value for the Namespace and DataSource connection parameters and for the User ID and Password. When you use the System.Data.OleDb namespace, you must also select a data provider from the list of installed data providers in the Provider drop-down list.
The Data Source value varies depending on the type of data source connection you are making. For example, if you are using Microsoft's OLE DB Provider for SQL Server, you select SQLOLEDB as the Provider value and enter the actual server name as the Data Source value. In the case of Microsoft SQL Server, you must also use the Extended Properties field to provide the database name (for example, Database=Pubs) since you can have multiple instances of a database.
Using the Data Link API with OLE DB
The Data Link option allows you to access Microsoft's Data Link API, which allows you to define a file or use an existing file that contains your OLE DB connection information. A Data Link file is identified with the suffix .udl.
To launch this option, select the File Name check box on the Connection page and double-click the button next to the File Name box. (You can also launch the Data Link API in the Database painter by double-clicking the Manage Data Links utility included with the OLE DB interface in the list of Installed Database Interfaces.)
For more information on using the Data Link API, see Microsoft's Universal Data Access Web site at http://msdn.microsoft.com/en-us/data/default.aspx.
Using a Data Link file versus setting the database parameters
If you use a Data Link file to connect to your data source, all other database-specific settings you make in the ADO.NET Database Profile Setup dialog box are ignored.
You can use the standard select @@identity syntax to obtain the value of an identity column. You can also use an alternative syntax, such as select scope_identity(), by adding sections to a .NET configuration file for your application.
Setting up a dbConfiguration section in a configuration file
The following example shows the general structure of a configuration file with a database configuration section and one custom configuration section:
<configuration> <configSections> <sectionGroup name="dbConfiguration"> <section name="mycustomconfig" type="Sybase.PowerBuilder.Db.DbConfiguration, Sybase.PowerBuilder.Db" /> </sectionGroup> </configSections> <dbConfiguration> <mycustomconfig dbParm="optional_value" getIdentity="optional_syntax" /> </dbConfiguration> </configuration>
To add a database configuration section to a .NET configuration file:
-
In the <configSections> section of the configuration file, add a <sectionGroup> element with the name "dbConfiguration". This name is case sensitive.
<configSections> must appear at the beginning of the configuration file, before the <runtime> section if any.
-
In the dbConfiguration <sectionGroup> element, add one of more <section> elements.
For each section, specify a name of your choice and a type. The type is the strong name of the assembly used to parse this section of the configuration file.
-
Close the <section> and <configSections> elements and add a <dbConfiguration> element.
-
For each section you defined in step 2, add a new element to the <dbConfiguration> element.
For example, if you defined a section called config1, add a config1 element. Each element has two attributes: dbParm and getIdentity. You can set either or both of these attributes.
The dbParm value sets the value of the DBParm parameter of the transaction object. It has a maximum length of 1000 characters. If you set a value for a parameter in the configuration file, any value that you set in code or in the Database Profile Setup dialog box is overridden.
The getIdentity value specifies the syntax used to retrieve the value of an identity column. It has a maximum length of 100 characters. If you do not specify a value for getIdentity, the select @@identity syntax is used.
Sample configuration file
This sample configuration file for PowerBuilder 17.0 is called pb170.exe.config. It contains three custom configurations. The <myconfig> element sets both the dbParm and getIdentity attributes. <myconfig1> sets getIdentity only, and <myconfig2> sets dbParm only. The <runtime> section is in the configuration file that ships with PowerBuilder but would not be included in the configuration file that you ship with your application, which would have the same name as your application with the extension exe.config.
<configuration> <configSections> <sectionGroup name="dbConfiguration"> <section name="myconfig" type="Sybase.PowerBuilder.Db.DbConfiguration, Sybase.PowerBuilder.Db" /> <section name="myconfig1" type="Sybase.PowerBuilder.Db.DbConfiguration, Sybase.PowerBuilder.Db" /> <section name="myconfig2" type="Sybase.PowerBuilder.Db.DbConfiguration, Sybase.PowerBuilder.Db" /> </sectionGroup> </configSections> <runtime> <assemblyBinding xmlns= "urn:schemas-microsoft-com:asm.v1"> <dependentAssembly> <assemblyIdentity name= "Sybase.PowerBuilder.Db"/> <codeBase href="file:///C:/Program Files/ Appeon/PowerBuilder 17.0/DotNET/bin/ Sybase.PowerBuilder.Db.dll"/> </dependentAssembly> <dependentAssembly> <assemblyIdentity name= "Sybase.PowerBuilder.WebService.WSDL"/> <codeBase href="file:///C:/Program Files/ Appeon/PowerBuilder 17.0/DotNET/bin/ Sybase.PowerBuilder.WebService.WSDL.dll"/> </dependentAssembly> <dependentAssembly> <assemblyIdentity name= "Sybase.PowerBuilder.WebService.Runtime"/> <codeBase href="file:///C:/Program Files/ Appeon/PowerBuilder 17.0/DotNET/bin/ Sybase.PowerBuilder.WebService. Runtime.dll"/> </dependentAssembly> <probing privatePath="DotNET/bin" /> </assemblyBinding> </runtime> <dbConfiguration> <myconfig dbParm="disablebind=1" getIdentity="select scope_identity()" /> <myconfig1 getIdentity="select scope_identity()" /> <myconfig2 dbParm= "Namespace='Oracle.DataAccess.Client', DataSource='ora10gen',DisableBind=1, NCharBind=1,ADORelease='10.1.0.301'" /> </dbConfiguration> </configuration>
Specifying the custom configuration to be used
On the System tab page in the Database Profile Setup dialog box for ADO.NET or in code, specify the name of the custom configuration section you want to use as the value of the DbConfigSection parameter. For example:
Sqlca.DBParm="DbConfigSection='myconfig'"
If you set any parameters in the profile or in code that are also set in the configuration file, the value specified in the configuration file takes precedence.
The configuration file must be present in the same directory as the executable file and must have the same name with the extension .config.