简体   繁体   English

我可以通过Web.Config连接字符串优化数据库连接吗?

[英]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.

相关问题 我正在尝试通过web.config文件建立与数据库的连接-只是不起作用 - I'm trying to set up a connection to my database via the web.config file - It's just not working 如何在Web.Config中的2个连接字符串之间切换(为DBML激活一个) - How can I switch between 2 Connection Strings in my Web.Config (Activate one for DBML) 如何更改Web.config中数据库的连接字符串,这些字符串具有基于LOGIN数据库的Login_User表的数据库名称 - How can I change connection strings for database in my web.config that have database name based on Login_User table from LOGIN database 如何在连接字符串上使用Web.Config转换? - How do I use Web.Config transform on my connection strings? 我在web.config中需要两个连接字符串吗? - Do I need two connection strings in web.config? 在C#中,如何读取存储在web.config文件连接字符串中的连接字符串? - In C# , how can I read a connection string stored in my web.config file connection string? 如何通过Windows应用程序访问Web.Config文件中的连接字符串 - How can I access the connection string in my Web.Config file through a Windows Application 我如何通过C#更改web.config中的applicationSettings - How I can change the applicationSettings in my web.config via C# 在Web.config中更改连接字符串以访问本地数据库而不是联机数据库 - Changing Connection Strings in Web.config to access local database instead of online database 为什么使用WebConfigurationManager在Web.Config中找不到AppSetting? - Why can I not find an AppSetting in my Web.Config with WebConfigurationManager?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM