没有进程时出现IOException错误 [英] Error with IOException when no process

查看:89
本文介绍了没有进程时出现IOException错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

你好,
我正在一个打算租车的网站上工作.我已经创建了SQL数据库并且可以正常工作,但是当我创建一个民意调查并尝试从文件中读取时,我得到IOException-它正在被另一个进程使用.有什么办法可以解决此问题,还是应该在数据库中创建另一个表?

P.S.这是我的代码:

Hello,
I am working on a website that is soposed to rent cars. I have created SQL Database and it works, but when i create a poll, and try to read from a file, i get IOException - It is being used by another process. Is there any way to fix this, or should I create another table in the database?

P.S. Here''s my code:

public enum Answer
{ Yes, StillLooking, Close, No }
.
.
.
        [WebMethod]
        public int Count(Answer a)
        {
            StreamReader sr = new StreamReader(Server.MapPath(String.Format("{0}.txt", a)));
            return int.Parse(sr.ReadToEnd());
        }
        [WebMethod]
        public void AddVote(Answer a)
        {
            StreamWriter sw = new StreamWriter(Server.MapPath(String.Format("{0}.txt", a)));
            int num = Count(a);
            num++;
            sw.Write(num.ToString());
            sw.Close();
        }

推荐答案

您可以处置StreamReader和StreamWriter,这可能会改善问题,但我仍然会创建一个数据库或数据库表:由于这将是多用户的,所以我将寻求一个多用户解决方案.文本文件不是多用户的,实际上不应像对待它们一样...
You could dispose the StreamReader and StreamWriter which may improve matters, but I would still create a database or database table: since this is going to be multiuser I would go for a multiuser solution. Text files aren''t multiuser, and really shouldn''t be treated as if they are...


这篇关于没有进程时出现IOException错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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