Пример #1
0
        protected override void OnSetConnectionString(XDbConnectionStringBuilder builder)
        {
            base.OnSetConnectionString(builder);

            // 正常情况下INSERT, UPDATE和DELETE语句不返回数据。 当开启count-changes,以上语句返回一行含一个整数值的数据——该语句插入,修改或删除的行数。
            if (!builder.ContainsKey("count_changes"))
            {
                builder["count_changes"] = "1";
            }

            // 优化SQLite,如果原始字符串里面没有这些参数,就设置这些参数
            if (!builder.ContainsKey("Pooling"))
            {
                builder["Pooling"] = "true";
            }
            if (!builder.ContainsKey("Cache Size"))
            {
                builder["Cache Size"] = "50000";
            }
            // 这两个设置可以让SQLite拥有数十倍的极限性能,但同时又加大了风险,如果系统遭遇突然断电,数据库会出错,而导致系统无法自动恢复
            if (!builder.ContainsKey("Synchronous"))
            {
                builder["Synchronous"] = "Off";
            }
            if (!builder.ContainsKey("Journal Mode"))
            {
                builder["Journal Mode"] = "Memory";
            }
        }
Пример #2
0
        protected override void OnSetConnectionString(XDbConnectionStringBuilder builder)
        {
            base.OnSetConnectionString(builder);

            //// 正常情况下INSERT, UPDATE和DELETE语句不返回数据。 当开启count-changes,以上语句返回一行含一个整数值的数据——该语句插入,修改或删除的行数。
            //if (!builder.ContainsKey("count_changes")) builder["count_changes"] = "1";

            // 优化SQLite,如果原始字符串里面没有这些参数,就设置这些参数
            if (!builder.ContainsKey("Pooling"))
            {
                builder["Pooling"] = "true";
            }
            //if (!builder.ContainsKey("Cache Size")) builder["Cache Size"] = "5000";
            if (!builder.ContainsKey("Cache Size"))
            {
                builder["Cache Size"] = (512 * 1024 * 1024 / -1024) + "";
            }
            // 加大Page Size会导致磁盘IO大大加大,性能反而有所下降
            //if (!builder.ContainsKey("Page Size")) builder["Page Size"] = "32768";
            // 这两个设置可以让SQLite拥有数十倍的极限性能,但同时又加大了风险,如果系统遭遇突然断电,数据库会出错,而导致系统无法自动恢复
            if (!builder.ContainsKey("Synchronous"))
            {
                builder["Synchronous"] = "Off";
            }
            // Journal Mode的内存设置太激进了,容易出事,关闭
            //if (!builder.ContainsKey("Journal Mode")) builder["Journal Mode"] = "Memory";
            // 数据库中一种高效的日志算法,对于非内存数据库而言,磁盘I/O操作是数据库效率的一大瓶颈。
            // 在相同的数据量下,采用WAL日志的数据库系统在事务提交时,磁盘写操作只有传统的回滚日志的一半左右,大大提高了数据库磁盘I/O操作的效率,从而提高了数据库的性能。
            if (!builder.ContainsKey("Journal Mode"))
            {
                builder["Journal Mode"] = "WAL";
            }
            // 绝大多数情况下,都是小型应用,发生数据损坏的几率微乎其微,而多出来的问题让人觉得很烦,所以还是采用内存设置
            // 将来可以增加自动恢复数据的功能
            //if (!builder.ContainsKey("Journal Mode")) builder["Journal Mode"] = "Memory";

            // 自动清理数据
            if (builder.ContainsKey("autoVacuum"))
            {
                AutoVacuum = builder["autoVacuum"].ToBoolean();
                builder.Remove("autoVacuum");
            }

            // 默认超时时间
            //if (!builder.ContainsKey("Default Timeout")) builder["Default Timeout"] = 5 + "";

            // 繁忙超时
            //var busy = Setting.Current.CommandTimeout;
            //if (busy > 0)
            {
                // SQLite内部和.Net驱动都有Busy重试机制,多次重试仍然失败,则会出现dabase is locked。通过加大重试次数,减少高峰期出现locked的几率
                // 繁忙超时时间。出现Busy时,SQLite内部会在该超时时间内多次尝试
                //if (!builder.ContainsKey("BusyTimeout")) builder["BusyTimeout"] = 50 + "";
                // 重试次数。SQLite.Net驱动在遇到Busy时会多次尝试,每次随机等待1~150ms
                //if (!builder.ContainsKey("PrepareRetries")) builder["PrepareRetries"] = 10 + "";
            }

            DAL.WriteLog(builder.ToString());
        }
Пример #3
0
        protected override void OnSetConnectionString(XDbConnectionStringBuilder builder)
        {
            base.OnSetConnectionString(builder);

            // 关闭底层连接池,使用XCode连接池
            if (!builder.ContainsKey(Pooling))
            {
                builder[Pooling] = "false";
            }
        }
Пример #4
0
        protected override void OnSetConnectionString(XDbConnectionStringBuilder builder)
        {
            base.OnSetConnectionString(builder);

            if (builder.ContainsKey(Server_Key) && (builder[Server_Key] == "." || builder[Server_Key] == "localhost"))
            {
                //builder[Server_Key] = "127.0.0.1";
                builder[Server_Key] = IPAddress.Loopback.ToString();
            }
        }
Пример #5
0
        protected override void OnSetConnectionString(XDbConnectionStringBuilder builder)
        {
            base.OnSetConnectionString(builder);

            String file;
            if (!builder.TryGetValue("Database", out file)) return;

            file = ResolveFile(file);
            builder["Database"] = file;
            FileName = file;
        }
Пример #6
0
        protected override void OnSetConnectionString(XDbConnectionStringBuilder builder)
        {
            base.OnSetConnectionString(builder);

            String file;
            //if (!builder.TryGetValue(_.DataSource, out file)) return;
            // 允许空,当作内存数据库处理
            builder.TryGetValue(_.DataSource, out file);
            file = OnResolveFile(file);
            builder[_.DataSource] = file;
            FileName = file;
        }
Пример #7
0
        protected override void OnSetConnectionString(XDbConnectionStringBuilder builder)
        {
            base.OnSetConnectionString(builder);

            if (!builder.TryGetValue("Database", out var file))
            {
                return;
            }

            file = ResolveFile(file);
            builder["Database"] = file;
            FileName            = file;
        }
Пример #8
0
        /// <summary>设置连接字符串时允许从中取值或修改,基类用于读取拥有者Owner,子类重写时应调用基类</summary>
        /// <param name="builder"></param>
        protected virtual void OnSetConnectionString(XDbConnectionStringBuilder builder)
        {
            String value;

            if (builder.TryGetAndRemove(_.Owner, out value) && !String.IsNullOrEmpty(value))
            {
                Owner = value;
            }
            if (builder.TryGetAndRemove(_.ShowSQL, out value) && !String.IsNullOrEmpty(value))
            {
                ShowSQL = value.ToBoolean();
            }
        }
Пример #9
0
        protected override void OnSetConnectionString(XDbConnectionStringBuilder builder)
        {
            String str = null;
            // 获取数据目录,用于反向工程创建数据库
            if (builder.TryGetAndRemove("DataPath", out str) && !String.IsNullOrEmpty(str)) DataPath = str;

            base.OnSetConnectionString(builder);

            if (!builder.ContainsKey(Application_Name))
            {
                String name = Runtime.IsWeb ? HostingEnvironment.SiteName : AppDomain.CurrentDomain.FriendlyName;
                builder[Application_Name] = String.Format("XCode_{0}_{1}", name, ConnName);
            }
        }
Пример #10
0
Файл: DbBase.cs Проект: xchit/X
 /// <summary>设置连接字符串时允许从中取值或修改,基类用于读取拥有者Owner,子类重写时应调用基类</summary>
 /// <param name="builder"></param>
 protected virtual void OnSetConnectionString(XDbConnectionStringBuilder builder)
 {
     if (builder.TryGetAndRemove(_.Owner, out var value) && !String.IsNullOrEmpty(value))
     {
         Owner = value;
     }
     if (builder.TryGetAndRemove(_.ShowSQL, out value) && !String.IsNullOrEmpty(value))
     {
         ShowSQL = value.ToBoolean();
     }
     if (builder.TryGetAndRemove(_.UserParameter, out value) && !String.IsNullOrEmpty(value))
     {
         UserParameter = value.ToBoolean();
     }
     if (builder.TryGetAndRemove(_.Migration, out value) && !String.IsNullOrEmpty(value))
     {
         Migration = (Migration)Enum.Parse(typeof(Migration), value, true);
     }
 }
Пример #11
0
        protected override void OnSetConnectionString(XDbConnectionStringBuilder builder)
        {
            base.OnSetConnectionString(builder);

            SqlCeVer = SQLCEVersion.SQLCE40;

            if (!String.IsNullOrEmpty(FileName) && File.Exists(FileName))
            {
                try
                {
                    SqlCeVer = SqlCeHelper.DetermineVersion(FileName);
                }
                catch (Exception ex)
                {
                    XTrace.WriteException(ex);

                    SqlCeVer = SQLCEVersion.SQLCE40;
                }
            }
        }
Пример #12
0
        protected override void OnSetConnectionString(XDbConnectionStringBuilder builder)
        {
            base.OnSetConnectionString(builder);

            // 正常情况下INSERT, UPDATE和DELETE语句不返回数据。 当开启count-changes,以上语句返回一行含一个整数值的数据——该语句插入,修改或删除的行数。
            if (!builder.ContainsKey("count_changes")) builder["count_changes"] = "1";

            // 优化SQLite,如果原始字符串里面没有这些参数,就设置这些参数
            if (!builder.ContainsKey("Pooling")) builder["Pooling"] = "true";
            if (!builder.ContainsKey("Cache Size")) builder["Cache Size"] = "50000";
            // 加大Page Size会导致磁盘IO大大加大,性能反而有所下降
            //if (!builder.ContainsKey("Page Size")) builder["Page Size"] = "32768";
            // 这两个设置可以让SQLite拥有数十倍的极限性能,但同时又加大了风险,如果系统遭遇突然断电,数据库会出错,而导致系统无法自动恢复
            if (!builder.ContainsKey("Synchronous")) builder["Synchronous"] = "Off";
            // Journal Mode的内存设置太激进了,容易出事,关闭
            //if (!builder.ContainsKey("Journal Mode")) builder["Journal Mode"] = "Memory";
            // 数据库中一种高效的日志算法,对于非内存数据库而言,磁盘I/O操作是数据库效率的一大瓶颈。
            // 在相同的数据量下,采用WAL日志的数据库系统在事务提交时,磁盘写操作只有传统的回滚日志的一半左右,大大提高了数据库磁盘I/O操作的效率,从而提高了数据库的性能。
            if (!builder.ContainsKey("Journal Mode")) builder["Journal Mode"] = "WAL";
            // 绝大多数情况下,都是小型应用,发生数据损坏的几率微乎其微,而多出来的问题让人觉得很烦,所以还是采用内存设置
            // 将来可以增加自动恢复数据的功能
            //if (!builder.ContainsKey("Journal Mode")) builder["Journal Mode"] = "Memory";

            // 自动清理数据
            if (builder.ContainsKey("autoVacuum"))
            {
                AutoVacuum = builder["autoVacuum"].ToBoolean();
                builder.Remove("autoVacuum");
            }

            // 默认超时时间
            if (!builder.ContainsKey("Default Timeout")) builder["Default Timeout"] = 5 + "";

            //var value = "";
            //if (builder.TryGetAndRemove("UseLock", out value) && !String.IsNullOrEmpty(value))
            //{
            //    UseLock = value.ToBoolean();
            //    if (UseLock) DAL.WriteLog("[{0}]使用SQLite文件锁", ConnName);
            //}
        }
Пример #13
0
        protected override void OnSetConnectionString(XDbConnectionStringBuilder builder)
        {
            String str = null;

            // 获取OCI目录
            if (builder.TryGetAndRemove("DllPath", out str) && !String.IsNullOrEmpty(str))
            {
                SetDllPath(str);
                //else if (!String.IsNullOrEmpty(str = DllPath))
                //    SetDllPath(str);
            }
            else
            {
                if (!String.IsNullOrEmpty(str = DllPath))
                {
                    SetDllPath(str);
                }
                // 异步设置DLL目录
                //ThreadPool.QueueUserWorkItem(ss => SetDllPath(DllPath));
                //Thread.Sleep(500);
            }
        }
Пример #14
0
 protected override void OnSetConnectionString(XDbConnectionStringBuilder builder)
 {
     String str = null;
     // 获取OCI目录
     if (builder.TryGetAndRemove("DllPath", out str) && !String.IsNullOrEmpty(str))
         SetDllPath(str);
     //else if (!String.IsNullOrEmpty(str = DllPath))
     //    SetDllPath(str);
     else
     {
         //if (!String.IsNullOrEmpty(str = DllPath)) SetDllPath(str);
         // 异步设置DLL目录
         ThreadPool.QueueUserWorkItem(ss => SetDllPath(DllPath));
         Thread.Sleep(500);
     }
 }
Пример #15
0
 /// <summary>设置连接字符串时允许从中取值或修改,基类用于读取拥有者Owner,子类重写时应调用基类</summary>
 /// <param name="builder"></param>
 protected virtual void OnSetConnectionString(XDbConnectionStringBuilder builder)
 {
     String value;
     if (builder.TryGetAndRemove(_.Owner, out value) && !String.IsNullOrEmpty(value)) Owner = value;
     if (builder.TryGetAndRemove(_.ShowSQL, out value) && !String.IsNullOrEmpty(value)) ShowSQL = value.ToBoolean();
 }
Пример #16
0
        protected override void OnSetConnectionString(XDbConnectionStringBuilder builder)
        {
            base.OnSetConnectionString(builder);

            // 特别处理一下Excel
            if (!String.IsNullOrEmpty(FileName))
            {
                String ext = Path.GetExtension(FileName);
                if (ext.EqualIgnoreCase(".xls"))
                {
                    if (!builder.ContainsKey("Extended Properties")) builder["Extended Properties"] = "Excel 8.0";
                }
            }
        }
Пример #17
0
 /// <summary>设置连接字符串时允许从中取值或修改,基类用于读取拥有者Owner,子类重写时应调用基类</summary>
 /// <param name="builder"></param>
 protected virtual void OnSetConnectionString(XDbConnectionStringBuilder builder)
 {
     String value;
     if (builder.TryGetAndRemove(KEY_OWNER, out value) && !String.IsNullOrEmpty(value)) Owner = value;
 }
Пример #18
0
 protected override void OnSetConnectionString(XDbConnectionStringBuilder builder)
 {
     String str = null;
     // ��ȡOCIĿ¼
     if (builder.TryGetAndRemove("DllPath", out str) && !String.IsNullOrEmpty(str))
     {
         SetDllPath(str);
         //else if (!String.IsNullOrEmpty(str = DllPath))
         //    SetDllPath(str);
     }
     else
     {
         if (!String.IsNullOrEmpty(str = DllPath)) SetDllPath(str);
         // �첽����DLLĿ¼
         //ThreadPool.QueueUserWorkItem(ss => SetDllPath(DllPath));
         //Thread.Sleep(500);
     }
 }