简体   繁体   中英

Possibility to add database in sqlCacheDependency collection without web.config

Situation is like this: I have two projects. One Asp.net and one project which does all data related stuff with database. I keep my connectionstring in a seperate encrypted XML file. Now instead of requesting all data constantly from sql. I want to use SqlCacheDependency to gain performance. If I follow the instruction they advice me to add a database name in web.config.

<caching>
  <sqlCacheDependency enabled ="true">
    <databases>
      <add name="dbName"  connectionStringName="connectionstringName" />
    </databases>
  </sqlCacheDependency>
</caching>

Is there any way to this in code. Like in Application Application_Start() event in global.asax file where I can link to a custom method that provides me that connectionstring?

Thanks in advance

Thanks to David Gardiner's work around. I found in the following post.

How do I set a connection string config programatically in .net?

I've put it in the Global.asax application load event. Now I can from my sqlcachedependency section in web.config. to that existing connectionStringName from the connectionstring collection.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM