Getting identity column values
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:
1 |
<configuration><br>   <configSections><br>     <sectionGroup name="dbConfiguration"><br>        <section name="<span>mycustomconfig</span>"<br>         type="Sybase.PowerBuilder.Db.DbConfiguration,<br>         Sybase.PowerBuilder.Db"<br>        /><br>      </sectionGroup><br>   </configSections><br> <br>   <dbConfiguration><br>      <<span>mycustomconfig</span> dbParm="<span>optional_value</span>"<br>       getIdentity="<span>optional_syntax</span>" <br>      /><br>   </dbConfiguration><br></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 aconfig1
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 DbParameter 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, theselect @@identity
syntax
is used.
Sample configuration file
This sample configuration file for PowerBuilder 12.6 is called pb126.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.
1 |
<configuration><br>   <configSections><br>     <sectionGroup name="dbConfiguration"><br>        <section name="myconfig"<br>         type="Sybase.PowerBuilder.Db.DbConfiguration,<br>         Sybase.PowerBuilder.Db"<br>        /><br>        <section name="myconfig1"<br>         type="Sybase.PowerBuilder.Db.DbConfiguration,<br>         Sybase.PowerBuilder.Db"<br>        /><br>        <section name="myconfig2"<br>         type="Sybase.PowerBuilder.Db.DbConfiguration,<br>         Sybase.PowerBuilder.Db"<br>        /><br>      </sectionGroup><br>   </configSections><br> |
1 |
<runtime><br>      <assemblyBinding xmlns=<br>       "urn:schemas-microsoft-com:asm.v1"><br>         <dependentAssembly><br>            <assemblyIdentity name=<br>            "Sybase.PowerBuilder.Db"/><br>            <codeBase href="file:///C:/Program Files/<br>             Sybase/PowerBuilder 12.6/DotNET/bin/<br>             Sybase.PowerBuilder.Db.dll"/><br>         </dependentAssembly><br>         <dependentAssembly><br>           <assemblyIdentity name=<br>            "Sybase.PowerBuilder.WebService.WSDL"/><br>           <codeBase href="file:///C:/Program Files/<br>            Sybase/PowerBuilder 12.6/DotNET/bin/<br>            Sybase.PowerBuilder.WebService.WSDL.dll"/><br>         </dependentAssembly><br>         <dependentAssembly><br>           <assemblyIdentity name=<br>            "Sybase.PowerBuilder.WebService.Runtime"/><br>            <codeBase href="file:///C:/Program Files/<br>             Sybase/PowerBuilder 12.6/DotNET/bin/<br>             Sybase.PowerBuilder.WebService.<br>             Runtime.dll"/><br>         </dependentAssembly><br>         <probing privatePath="DotNET/bin" /><br>      </assemblyBinding><br>   </runtime> |
1 |
<br>   <dbConfiguration><br>      <myconfig dbParm="disablebind=1"<br>       getIdentity="select scope_identity()" <br>      /><br>      <myconfig1 getIdentity="select scope_identity()"<br>      /><br>      <myconfig2 dbParm=<br>       "Namespace='Oracle.DataAccess.Client',<br>       DataSource='ora10gen',DisableBind=1,<br>       NCharBind=1,ADORelease='10.1.0.301'" <br>      /><br>   </dbConfiguration><br></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:
1 |
Sqlca.DbParameter="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.