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:

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

StepsTo add a database configuration section to a .NET configuration file:

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

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

  3. Close the <section> and <configSections> elements and add a <dbConfiguration> element.

  4. 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 12.5 is called pb125.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. For .NET Web Forms targets, you add the custom configurations to the web.config file.

<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/
             Sybase/PowerBuilder 12.5/DotNET/bin/
             Sybase.PowerBuilder.Db.dll"/>
         </dependentAssembly>
         <dependentAssembly>
           <assemblyIdentity name=
            "Sybase.PowerBuilder.WebService.WSDL"/>
           <codeBase href="file:///C:/Program Files/
            Sybase/PowerBuilder 12.5/DotNET/bin/
            Sybase.PowerBuilder.WebService.WSDL.dll"/>
         </dependentAssembly>
         <dependentAssembly>
           <assemblyIdentity name=
            "Sybase.PowerBuilder.WebService.Runtime"/>
            <codeBase href="file:///C:/Program Files/
             Sybase/PowerBuilder 12.5/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.