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.DataWindow.Db.DbConfiguration,
         Sybase.DataWindow.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 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, the select @@identity syntax is used.

Sample configuration file

This sample configuration file contains three custom configurations. The <myconfig> element sets both the dbParm and getIdentity attributes. <myconfig1> sets getIdentity only, and <myconfig2> sets dbParm only.

<configuration>
   <configSections>
     <sectionGroup name="dbConfiguration">
        <section name="myconfig"
         type="Sybase.DataWindow.Db.DbConfiguration,
         Sybase.DataWindow.Db"
        />
        <section name="myconfig1"
         type="Sybase.DataWindow.Db.DbConfiguration,
         Sybase.DataWindow.Db"
        />
        <section name="myconfig2"
         type="Sybase.DataWindow.Db.DbConfiguration,
         Sybase.DataWindow.Db"
        />
      </sectionGroup>
   </configSections>


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