Skip to content
This repository has been archived by the owner on Dec 1, 2018. It is now read-only.

SqlClient Configuration (ASP .NET)

Aleksey Nemiro edited this page Apr 2, 2014 · 7 revisions

Special configuration for Nemiro.Data class library is not required.

But it is recommended add to the web.config file a connection string with name LocalSqlServer.

<configuration>
  <!-- other sections -->

  <connectionStrings>
    <remove name="LocalSqlServer"/>
    <add
     name="LocalSqlServer" 
     connectionString="Data Source=.\SQLEXPRESS;Initial Catalog=example;Trusted_Connection=True;"
    />
  </connectionStrings>

  <!-- other sections -->
</configuration>

This will avoid specifying the connection string in a code.

NOTE: Before adding the connection string, you need to remove the LocalSqlServer, because the LocalSqlServer it's default connection string of the .NET Framework.

NOTE: The connection string (Data Source=.\SQLEXPRESS;Initial Catalog=example;Trusted_Connection=True;) is shown only for example. You must set your own connection string.

Additional settings

You can use additional parameters to configure the behavior of the SqlClient class.

Parameters are added to the appSettings section of the file web.config.

For example:

<configuration>
  <!-- other sections -->

  <appSettings>
    <add key="NeData:Sql:CachePath" value="G:\caching\test" />
  </appSettings>

  <!-- other sections -->
</configuration>

The list of settings for the SqlClient class:

Parameter name Values Description
NeData:Sql:ConnectionMode Auto (default), Manual Default connection mode. Automatically open and close a database connection (default) or automatically open and manual close a database connection.
NeData:Sql:CommandType Auto (default), StoredProcedure, TableDirect, Text Default command type for CommandText.
NeData:Sql:CacheType None, Auto (default), Web, File, Memory, Custom Default caching type.
NeData:Sql:CacheDuration Integer Default duration of storage in the cache entry (in seconds). Not recommended.
NeData:Sql:CachePath String Default path of storage a cache files.
NeData:Sql:CacheBinder String Default type serializer of custom objects. Expected type name. For example: MyNamespace.MyCacheBinder
NeData:Sql:CacheBufferSize Integer Default memory buffer size (Kb) of the file cache.
NeData:Sql:CacheBufferAccessTimeout String Waiting time gain access to the buffer of the file cache. TimeSpan string. For example: 0.00:00:00.500 - 0 days, 0 hours, 0 minutes, 0 seconds, 500 milliseconds. Default value is: 0.00:00:00.0 (TimeSpan.Zero)
NeData:Sql:CacheAccessTimeout String Default waiting time gain access to the entry of the file cache. TimeSpan string. For example: 0.00:00:00.500 - 0 days, 0 hours, 0 minutes, 0 seconds, 500 milliseconds. Default value is: 0.00:00:00.0 (TimeSpan.Zero)
NeData:Sql:CacheCustom String Default type of custom cache. Expected type name. For example: MyNamespace.MyCache
NeData:Sql:CacheCustomArgs String Additional parameters for initialization custom cache. Parameters are separated by a comma. For example: test, 123