[英]Can I optimize my database connections via Web.Config connection strings?
I just want to know is there attribute or property in our connectionstring field so that we can maintain an optimized db connections with our clients. 我只想知道我们的连接字符串字段中是否有属性或属性,以便我们可以与客户保持优化的数据库连接。 Like in general I use.That contains just required info. 就像我一般使用的那样,其中只包含必需的信息。
<add name ="ConnectionString" connectionString="Data Source=118.225.221.7;Initial Catalog=mycatalogue;
User Id=dba; password=some_password"/>
Another Scenario, we can enhance our connection string for MARS and Asynchronous operations too: 另一种情况,我们也可以增强MARS和异步操作的连接字符串:
MARS
Server=myServerAddress;Database=myDataBase;Trusted_Connection=True;
MultipleActiveResultSets=true;
Asynchronous Processing
Server=myServerAddress;Database=myDataBase;Integrated Security=True;
Asynchronous Processing=True;
From our pages i have 4-5 or sometimes ~10 connections to access data. 在我们的页面中,我有4-5或有时〜10个连接来访问数据。 Take a case when I have 100 users accessing the same page simultaneously assuming the code is executing "SELECT"
statement and fetching some random rows for each client. 以我有100个用户同时访问同一页面的情况为例,假设代码正在执行"SELECT"
语句并为每个客户端获取一些随机行。 Then 400-500 connections will hit the db at a time, which I think, will definitely degrade the server/application performance. 然后400-500个连接将一次到达数据库,我认为这肯定会降低服务器/应用程序的性能。
So I want to know, should I minimize the number of queries, or leave it to the .Net framework intelligence. 所以我想知道,我应该减少查询数量还是让它留给.Net框架智能。
Firstly look at optimising your linq, make sure you are not making two queries when all the info can be pulled with one call for instance. 首先看一下如何优化您的linq,确保在可以一次调用所有信息的情况下,不要对两个查询进行查询。
Also look at caching. 另外看看缓存。 Here you will have to make the decision on how long the data should be cached for and when it should be invalidated (by someone inserting a record for example) and at what levels you do it. 在这里,您必须决定应将数据缓存多长时间以及何时使数据无效(例如,有人插入记录)以及在什么级别上进行数据存储。 If your page rarely changes and it is not so heavy on insertions/updates you could possible cache at the page level (page level caching). 如果您的页面很少更改,并且插入/更新不那么繁琐,则可以在页面级别缓存(页面级别缓存)。
If that is not an option you can look at caching your data returned from linq using something like httpcontext.current.cache
, a quick google search will show you the details, but in essence you cache the data returned from your linq queries, and on subsequent requests you check the cache first to see if the data is there, if it is, use that, if not go to the database and request it again. 如果不是这种选择,您可以使用httpcontext.current.cache
类的方法httpcontext.current.cache
从linq返回的数据,谷歌快速搜索将向您显示详细信息,但实际上您可以缓存从linq查询返回的数据,并继续在后续请求中,您将首先检查高速缓存,以查看数据是否存在,如果没有,请使用该数据,如果没有,请再次访问数据库。 This limits the hits to your database. 这将命中限制在您的数据库中。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.