简体   繁体   English

SqlCeConnection比SqlConnection慢

[英]SqlCeConnection is way slower than SqlConnection

In my C# app I can switch between Online SQL-Server connection and local SQLCE (sdf file) connection. 在我的C#应用​​程序中,我可以在在线SQL-Server连接和本地SQLCE(sdf文件)连接之间切换。 Both DBs are the same in structure and indexes. 两个数据库的结构和索引相同。

But using the local SDF file through SqlCeConnection is so much slower - 20 times slower when doing a lot of calls. 但是通过SqlCeConnection使用本地SDF文件的速度要慢得多-进行大量调用时速度要慢20倍。

Example: 例:

using (DbConnection connection = new SqlCeConnection(ConnectionString))
{
    connection.Open();
    using (DbCommand cmd = GetSqlCommand("select * from t", connection))
    {
        try
        {
            var reader = cmd.ExecuteReader();
            while (reader.Read())
            {
                ...
            }
            reader.Close();
        }
        catch (Exception e)  {  }
    }
}

What is going on here - can I optimize that? 这是怎么回事-我可以优化吗?

Keep a single connection open and unused for the lifetime of your app, SQL Compact does not have connection pooling. 在应用程序的生命周期内,保持单个连接处于打开状态且未使用,SQL Compact没有连接池。

In addition, opening a SqlCeConnection can be slow because of: 另外,由于以下原因,打开SqlCeConnection可能很慢:

  • The database file has been created on another platform 数据库文件已在另一个平台上创建
  • The ACL (Access Control List) on the RSA folder is corrupt RSA文件夹上的ACL(访问控制列表)已损坏
  • Invalid Internet Proxy configuration 无效的Internet代理配置

More info here: http://erikej.blogspot.dk/2013/08/faq-why-is-opening-my-sql-server.html 此处提供更多信息: http : //erikej.blogspot.dk/2013/08/faq-why-is-opening-my-sql-server.html

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM