Friday, 17 February 2012

Configuring SQL cache

Hi all,

I have a question regarding SQL caching.

I want to use SQL caching for my pages.I've gone throughhttp://msdn2.microsoft.com/en-us/library/e3w8402y(VS.80).aspx article on msdn, where in step by step procedure is explained for this. But I have a slightly different situation. In the article, we need to configure our application from web.config by following...

<!-- caching section group -->
<caching>
<sqlCacheDependency enabled = "true" pollTime = "1000" >
<databases>
<add name="Northwind"
connectionStringName="NorthwindConnectionString1"
pollTime = "1000"
/>
</databases>
</sqlCacheDependency>
</caching>

Where in"NorthwindConnectionString1"is the SQLdatasource connection string. But I'm not using SQLDatasource, and have my own classes to build a connection datasource and get a dataset, and then bind it to my control.So in this case what should I write for the above"connectionstring" attribute. My connection string is in web.config only with a section defined. and in my application i'm reading from web.fing only.The connection section i'm using is as follows...

<

ConnSettings>

<

addkey="ConnString"value="server=serverName;database=dbName;uid=dbuser;Pwd=password"/>

</

ConnSettings>

I want to know how to configure my sql cache in this situation.

Thanks,

Mehul Mistry

Hi Mehul,

In your case, your connection string can be declared as below:

<ConnSettings>
<add name="MyConn" connectionString="server=serverName;database=dbName;uid=dbuser;Pwd=password"/>
</ConnSettings>

So your caching configuring can be declared in this way:

<caching>
<sqlCacheDependency enabled = "true" pollTime = "1000" >
<databases>
<add name="Northwind"
connectionStringName="MyConn"
pollTime = "1000"
/>
</databases>
</sqlCacheDependency>
</caching>

Note: You should usestring conn = ConfigurationManager.ConnectionStrings["MyConn"].ConnectionString; to get the connection string in your application code.

Hope this helps. Thanks.

|||

Hi Nai,

After a long long time I'm posting again in this thread ( as I had to shift to some other module and issues). Regarding this caching, as I've written above that I'm not using any SQLDatasource and have my own classes for that. So I've problem in configuring the caching in web.config. I'm going through a tutorial on msdn ( http://msdn2.microsoft.com/en-us/library/e3w8402y(VS.80).aspx ). The solution which u gave above is not working still. I'm still getting eorror...

Parser Error Message:The connection name 'ConnSettings' was not found in the applications configuration or the connection string is empty.

Line 226: <databases>

Line 227: <add name="DBCACHE"

Line 228: connectionStringName="MyConn"

Line 229: pollTime = "2000"Line 230: />

I'm re-writing what I've done in web.config...

<configuration>

<section name="MyConn" type="System.Configuration.NameValueFileSectionHandler,System, Version=1.0.3300.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 "/>

<ConnSettings>
<add name="MyConn" connectionString="server=serverName;database=dbName;uid=dbuser;Pwd=password"/>
</ConnSettings>

</<configuration>

<system.web>

<caching>
<sqlCacheDependency enabled = "true" pollTime = "2000" >
<databases>
<add name="DBCACHE"
connectionStringName="MyConn"
pollTime = "2000"
/>
</databases>
</sqlCacheDependency>
</caching>

</system.web>

I hope I gave a better picture of my problem now. I've not got any article on net which uses caching without SQLdatasource.

Can Someone please help me with this...

Thanks,

MehulMistry

No comments:

Post a Comment