C#Webservices有关性能的问题 [英] C# Webservices Question about Performance

查看:68
本文介绍了C#Webservices有关性能的问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,

如今我在一个项目上工作,我在asp.net 4.0 webservices下管理我的mysql查询,

我想举一个Webmethod的例子

Hello guys,

nowdays i''m workin'' on a project, i manage my mysql query''s under asp.net 4.0 webservices,

i''d like to give a example of Webmethod

[WebMethod]
        public MysqlServisleri.Userdata UserLogin(String uid, String pwd, String getApikey)
        {
            if (apikey != getApikey) { return new MysqlServisleri.Userdata(); }
            MysqlServisleri Baglanti = new MysqlServisleri("127.0.0.1", "root", "", "csm");
            return Baglanti.UserLogin(uid, pwd);
        }





[WebMethod]

        public bool ChangeUserPerms(String uid, String perms, String parola, String getApikey)
        {
            if (apikey != getApikey) { return false; }
            MysqlServisleri Baglanti = new MysqlServisleri("127.0.0.1", "root", "", "csm");
            return Baglanti.ChangeUserPerms(uid, perms, parola);
        }



我有很多这样的空白和功能.您如何看待我声明我的mysql对象并在每个子对象上进行连接,这是否会对我的性能造成严重影响,我的意思是声明如何在我的代码顶部声明Mysql连接,并且仅对每个子对象使用Baglanti对象,所以我'' d能够只连接一次到mysql.这是我的硬道理..

等待任何评论和建议..谢谢



I got lot''s of void''s and function''s like this. How you can see i declare my mysql object and connect on each sub, does it effects my performance badly, i mean how about declaring the Mysql connection to the top of my codes and just use the Baglanti object for each sub, so i''d be able to just connect one time to the mysql. Is my tought true about this..

Waiting any comments and suggestions.. Thanks

推荐答案

MySql连接是一种稀缺资源:它们在连接到服务器的用户之间共享.如果您在代码的开头抓取了一个连接,并且在应用程序关闭之前不释放它,那么您将占用该连接,这意味着没有其他人可以使用它.这可能会导致整个系统出现问题,因此不建议这样做.您应该创建,使用和处置连接对象(以及命令对象,DataReader对象等).目前,您尚未处理它们,这可能会给您自己的应用程序带来麻烦!
MySql connections are a scarce resource: they are shared among the users connecting to the server. If you grab a connection at the start of your code, and do not release it until the application is closed, you are hogging the connection and that means that no-one else can use it. This may cause problems with the system as a whole, and is not recommended. You should create, use, and Dispose your connection objects (and your command objects, your DataReader objects, and so forth). At present you do not Dispose them, which may cause problems for your own app!


这篇关于C#Webservices有关性能的问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆