在没有数据库的情况下保留信息? [英] Retain information without a database?

查看:89
本文介绍了在没有数据库的情况下保留信息?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个使用我制作的Web服务的Web引用的类库. Web服务具有使用数据库还是不使用数据库的属性.如果我使用数据库,它将保留信息.但是我担心,由于Web服务不断插入和删除信息,因此使用数据库将成为程序的瓶颈.

因此,我现在的目标是通过操作系统的服务更新来保留我的信息.知道怎么做吗?

我也是一名CS学生,即将上大二,现在是暑假的实习生.在此实习期间,学习了C#并首次使用了Visual Studio.我喜欢它!另外,负责监督的人说他会很忙,如果需要帮助,我可以使用此网站!

[更新]
在我的网络服务中,我有

I have a class library that uses a web refrence of a web service I made. The web service has a property, to use a Database or not to use a database. If I use a database it retains the information. But I am worried that because the web service constantly insert and delete information, using the Database will become the bottle neck of the program.

So my goal now is to have my information be retained through OS refreshing of the service. Any idea how to do this?

Also I am an CS student who is going to their sophomore year, and currently an intern just for the summer. Learned C# and used Visual studio for the first time during this intern. I love it! Also the guy that is supervising said he will be busy and if I need help, I could use this website!

[UPDATE]
In my web service I have

public class Service1 : System.Web.Services.WebService
   {
       private SqlConnection connection;
       private List<ListData> ListOfMessages;
       public Service1()
       {
           if (Properties.Settings.Default.UseDatabase)
           {
               try
               {
                   connection = new SqlConnection(Properties.Settings.Default.DbConnectionStr);
                   connection.Open();
               }
               catch (Exception ex)
               {
                   Console.WriteLine(ex);
               }
               Dispose(false);
           }
           else
           {
               ListOfMessages = new List<ListData>();
               Dispose(false);
           }
       }
}

推荐答案

您合理地期望自己实际需要哪种性能/规模/用途?您可能会担心一些永远不会成为问题的事情.

不要花时间解决不需要解决的问题.

应该对数据库进行优化,以支持每秒大量的事务.那就是他们应该擅长的.

如果您真正需要的是数据库,那么您将无法实现比数据库更好的数据库替换.

如果您需要的是数据库,请使用数据库.

如果它成为瓶颈,则可以更好地配置数据库,或者用更快的数据库替换它(或者在上面扔硬件).

如果您不需要数据库,那么您实际上要尝试保留哪些数据?要持久化数据,本质上需要将其写入持久性存储(并且可能会在途中进行缓存以加快写入/读取速度),但这就是数据库的工作.

实际上,对文件的纯读/写操作实际上可能比使用数据库慢.

如果您实际上并不关心在电源故障中持续存在,则有内存数据库.
What sort of perfromance / scale / use do you reasonably expect you are actually going to need? You might be worried about something that isn''t ever going to be an issue.

Don''t spend time solving a problem that doesn''t need to be solved.

Databases are supposed to be optimised to support lots of transactions per second. That''s what they are supposed to be good at.

You aren''t going to be able to implement a database replacement that''s better than a database if what you really need is a database.

If what you need is a database, then use a database.

If it becomes a bottleneck, then configure your database better or replace it with a faster database (or throw hardware at it).

If you don''t need a database, then what data are you actually trying to persist? To persist data, it essentially needs to be written to persistent storage (and maybe cached on the way for faster write/read) -- but that''s what a database does.

A pure read/write of a file may actually be slower than using a database.

There are in-memory databases if you don''t actually care about persisting across a power failure.


我认为可以对您的代码进行一些改进:

  • 不要在构造函数中吃异常.如果出现问题,您的服务对象将不会可用".
  • 构造函数中的Dispose调用是什么?
    Dispose不能从构造函数中调用,而是从调用者中调用当他不再需要该对象时.
  • 如果您想准备支持其他数据存储选项,请使用该存储库的接口,并为每种可能的情况实现具体的类(SQL数据库) ,内存数据库...)
I think that a few improvement can be done to your code:

  • Don''t eat exceptions in a constructor. Your service object would not be "usable" if something goes wrong.
  • What is the Dispose call inside the constructor?
    Dispose is not intended to be called from the constructor but from the caller when he does not need the object anymore.
  • If you want to be ready to support different data store options, uses an interface to that repository and implement concrete class for each possible case (SQL Database, in-memory database...)

  • 服务返回的数据量(记录计数和数据大小)
  • 总存储量
  • 返回的数据是否随用户,时间或很少变化而变化?
  • 您每秒期望多少个请求
  • ...

  • The amont off data returned by the service (record count and data size)
  • The total amont of storage
  • Does the returned data vary by user, by time or seldom changes?
  • How many request you expect per second
  • ...


最好的方法是围绕界面定义服务:

The best thing to do is to define your service around an interface:

public interface IRepository
{
    void AppendData(string name, string value, DateTime timeStamp);
    string[] GetData(string name, DateTime from, DateTime to);
}



然后,您将获得concreate实现:



Then you will have concreate implementations:

public SqlRepository : IRepository
{
    void AppendData(string name, string value, DateTime timeStamp)
    {
        // SQL implementation
    }

    string[] GetData(string name, DateTime from, DateTime to)
    {
        // SQL implementation
    }
}

// Similar for MemoryRepository.



这样就很容易选择或比较每种可能性.您还可以实现其他可能性,例如SqlWithCacheRepository,将最常用的数据保存在内存中.



Then it will be easy to select or compare each possibilities. You could also implement other possibilities like SqlWithCacheRepository where you keep mostly used data in memory.


这篇关于在没有数据库的情况下保留信息?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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