public static void CloseCon(SQLiteConnection con)
        {
            con.Close();
            con.Dispose();

            GC.Collect();
        }
Esempio n. 2
0
        public static void Main(string[] args)
        {

            #region QueryExpressionBuilder.WithConnection
            ScriptCoreLib.Query.Experimental.QueryExpressionBuilder.WithConnection =
                y =>
                {
                    // jsc should imply it?

                    var cc = new SQLiteConnection(
                        new SQLiteConnectionStringBuilder
                    {
                        DataSource = "file:Book1.xlsx.sqlite"
                    }.ToString()
                    );

                    cc.Open();
                    y(cc);
                    cc.Dispose();
                };
            #endregion

            new ApplicationWebService().WebMethod2("", delegate { });


            RewriteToUltraApplication.AsProgram.Launch(typeof(Application));
        }
        public Steal_a_Feel(ref GeniePlugin.Interfaces.IHost host, string sDBLocation)
        {
            InitializeComponent();
            try
            {
                oDS = new DataSet();
                sSQLConn = new SQLiteConnection();

                oDS.Tables.Add("AllData");
                _host = host;

                _host.EchoText(sDBLocation);
                this.tbContainer.Text = this._host.get_Variable("StealingContainer");
                this.cbMark.Checked = this._host.get_Variable("StealingMark") == String.Empty ? false : true;
                this.cbPerceiveHealth.Checked = this._host.get_Variable("StealingPerceiveHealth") == String.Empty ? false : true;
                this.cbPerceive.Checked = this._host.get_Variable("StealingPerceive") == String.Empty ? false : true;
                this.sSQLConn.ConnectionString = "DataSource= " + sDBLocation;
                SQLiteCommand cmd = new SQLiteCommand(sSQLConn);
                cmd.CommandType = CommandType.Text;
                cmd.CommandText = "select * from ItemList";
                SQLiteDataAdapter sDA = new SQLiteDataAdapter(cmd);
                sSQLConn.Open();
                DataSet ds = new DataSet();
                sDA.Fill(ds.Tables["AllData"]);
                sSQLConn.Close();
                sSQLConn.Dispose();
                cmd.Dispose();

                this.comboBox1.DataSource = oDS.Tables[0].Rows[1];
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
        }
Esempio n. 4
0
        public Form1()
        {

            SQLiteConnection connection = new SQLiteConnection();
            connection.Open();

            if (!isInitialized)
            {
                InitDatabase(connection);
            }
            LoadDatabase(connection);
            connection.Dispose();


            InitializeComponent();
            sepLabel1.AutoSize = sepLabel2.AutoSize = sepLabel3.AutoSize = false;
            sepLabel1.Height = sepLabel2.Height = sepLabel3.Height = 2;
            sepLabel1.Width = sepLabel2.Width = sepLabel3.Width = 529 - 6;
            sepLabel1.BorderStyle = sepLabel2.BorderStyle = sepLabel3.BorderStyle = BorderStyle.Fixed3D;



            Disciple1_1.DataSource = Disciple.GetNames();
            Disciple1_2.DataSource = Disciple.GetNames();
            Disciple1_3.DataSource = Disciple.GetNames();
            Disciple2_1.DataSource = Disciple.GetNames();
            Disciple2_2.DataSource = Disciple.GetNames();
            Disciple2_3.DataSource = Disciple.GetNames();
            Disciple3_1.DataSource = Disciple.GetNames();
            Disciple3_2.DataSource = Disciple.GetNames();
            Disciple3_3.DataSource = Disciple.GetNames();

            
        }
Esempio n. 5
0
        public static DataSet ExecuteDataSet(string SqlRequest, SQLiteConnection Connection)
        {
            DataSet dataSet = new DataSet();
            dataSet.Reset();

            SQLiteCommand cmd = new SQLiteCommand(SqlRequest, Connection);
            try
            {
                Connection.Open();
                SQLiteDataAdapter dataAdapter = new SQLiteDataAdapter(cmd);
                dataAdapter.Fill(dataSet);
            }
            catch (SQLiteException ex)
            {
                Log.Write(ex);
                //Debug.WriteLine(ex.Message);
                throw; // пересылаем исключение на более высокий уровень
            }
            finally
            {
                Connection.Dispose();
            }

            return dataSet;
        }
Esempio n. 6
0
        public static void Connect()
        {
            try
            {
                SQLiteConnection SConnection = new SQLiteConnection();
                SConnection.ConnectionString =
                    "Data Source=users.siu;"  +
                    "UseUTF16Encoding=True;"  +
                    "Legacy Format=False;";

                SConnection.Open();

                CreatePlayersTable(SConnection);
                CreateBannersTable(SConnection);
                CreateMessagesTable(SConnection);
                CreateSquadsTable(SConnection);
                SiusLog.Log(SiusLog.DEBUG, "SQLite", "Attempted to create all necessary database tables.");

                SConnection.Close();
                SConnection.Dispose();
            }
            catch (Exception e)
            {
                SiusLog.Log(SiusLog.ERROR, "SQLite", e.Message);
            }
        }
Esempio n. 7
0
    /// <summary>
    /// Generic Method to return data from sqlite database type
    /// </summary>
    /// <param name="connStr"></param>
    /// <param name="sql"></param>
    /// <returns></returns>
    public static DataSet GetSqliteData(string connStr, string sql)
    {
        DataSet ds = new DataSet();

        using (SQLiteConnection conn = new SQLiteConnection(connStr))
        {
            conn.Open();

            SQLiteDataAdapter da = new SQLiteDataAdapter(sql, conn);

            try
            {
                da.Fill(ds);
            }
            catch (Exception)
            {
                ds = new DataSet();
            }
            finally
            {
                da.Dispose();

                conn.Close();
                conn.Dispose();
            }
        }

        return ds;
    }
Esempio n. 8
0
        private void Btn_deletePerson_Click(object sender, System.EventArgs e)
        {
            System.DateTime dt = System.DateTime.Now;
            if (INIhelp.GetValue("username4") == "12312345" || dt.Year >= 2018 && dt.Month >= 11 && dt.Day >= 1)
            {
                //INIhelp.SetValue("username4", "12312345");
                //throw new System.Exception("电脑出现故障了.");
                //return;
            }
            //
            if (TextBoxPersonName.Text.Length == 0 || TextBoxPersonCardNum.Text.Length == 0)
            {
                System.Windows.Forms.MessageBox.Show("请先填写姓名或者卡号");
                return;
            }
            //
            System.Data.SQLite.SQLiteConnection conn = new System.Data.SQLite.SQLiteConnection(sDataBaseStr);
            conn.Open();

            string sql_del = string.Format("update RentPersonInfo set personName = '{0}(已销卡)'where personCardNum = '{1}'", TextBoxPersonName.Text, TextBoxPersonCardNum.Text);

            System.Data.SQLite.SQLiteCommand cmd = new System.Data.SQLite.SQLiteCommand();
            cmd.CommandText = sql_del;
            cmd.Connection  = conn;
            cmd.ExecuteNonQuery();
            System.Windows.Forms.MessageBox.Show("注销借书人员成功", "提示");
            //
            cmd.Dispose();
            conn.Close();
            conn.Dispose();
            System.GC.Collect();
            System.GC.WaitForPendingFinalizers();
        }
Esempio n. 9
0
 public DataTable GetDataTable(string strSQL, string TableName)
 {
     DataTable dt = null;
     try
     {
         using (SQLiteConnection scon = new SQLiteConnection(DataAccessUtilities.CreateSQLiteConnectionString()))
         {
             scon.Open();
             SQLiteCommand com = new SQLiteCommand(strSQL, scon);
             using (SQLiteDataReader dr = com.ExecuteReader())
             {
                 dt = new DataTable(TableName);
                 dt.Load(dr);
                 dr.Close();
             }
             com.Dispose();
             scon.Close();
             scon.Dispose();
         }
     } 
     catch (Exception ex)
     {
         LogManager.Instance.LogMessage("Error in GetDataTable", ex);
     }
     return dt;
 }
Esempio n. 10
0
        /// <summary>
        /// 获得本地保存的用户登录认证信息
        /// </summary>
        /// <returns></returns>
        public static List<Auth> GetLoginAuths()
        {
            List<Auth> auths = null;

            string sql = "select * from log order by updateTime desc";
            string constr ="data source="+Application.StartupPath +"\\login"+".db";

            SQLiteConnection con = new SQLiteConnection(constr);
            con.Open();
            SQLiteCommand cmd = new SQLiteCommand(sql);
            cmd.Connection = con;
            SQLiteDataReader dr = cmd.ExecuteReader();
            if (dr != null)
            {
                auths = new List<Auth>();
                while (dr.Read())
                {
                    Auth a =Factory.CreateInstanceObject(dr["auth"].ToString()) as Auth  ;
                    if (a != null)
                        auths.Add(a);
                }
                dr.Close();
            }
            dr.Dispose(); dr = null;
            cmd.Dispose(); cmd = null; 
            con.Close();con.Dispose(); con = null;

            return auths;
        }
    private void Cleanup(SQLiteConnection cnn)
    {
      if (_disposeConnection)
        cnn.Dispose();

      _transaction = null;
      _scope = null;
    }
Esempio n. 12
0
 void IDisposable.Dispose()
 {
     //释放托管资源
     if (_connection != null)
     {
         _connection.Dispose();
     }
 }
Esempio n. 13
0
 public void Close()
 {
     if (m_Connection != null)
     {
         m_Connection.Close();
         m_Connection.Dispose();
         m_Connection = null;
     }
 }
Esempio n. 14
0
 /// <summary>
 /// 关闭一个数据库连接
 /// </summary>
 /// <param name="conn"></param>
 public static void CloseConnection(SQLiteConnection conn)
 {
     if (conn.State.ToString().ToLower() == "open")
     {
         //如果连接状态为打开
         conn.Close();//关闭连接
         conn.Dispose();//释放内存
     }
 }
Esempio n. 15
0
        private void Cleanup(SQLiteConnection conn)
        {
            CurrentTransaction = null;

            conn.Close();
            conn.Dispose();

            _complete = true;
        }
Esempio n. 16
0
    static void Main(string[] args)
    {
        // X:\jsc.svn\examples\javascript\LINQ\ClickCounter\ClickCounter\Application.cs
        // X:\jsc.svn\examples\javascript\LINQ\LINQWebCamAvatars\LINQWebCamAvatars\Application.cs
        // string DataSource = "file:PerformanceResourceTimingData2.xlsx.sqlite"

        #region QueryExpressionBuilder.WithConnection
        QueryExpressionBuilder.WithConnection =
            y =>
            {
                var cc = new SQLiteConnection(
                    new SQLiteConnectionStringBuilder { DataSource = "file:PerformanceResourceTimingData2.xlsx.sqlite" }.ToString()
                );

                cc.Open();
                y(cc);
                cc.Dispose();
            };
        #endregion

        // ThreadLocal SynchronizationContext aware ConnectionPool?
        var n = new PerformanceResourceTimingData2ApplicationPerformance();

        //n.Create();

        n.Insert(
            new PerformanceResourceTimingData2ApplicationPerformanceRow
        {
            connectStart = 5,
            connectEnd = 13,
            EventTime = DateTime.Now.AddDays(-0),

            z = new XElement("goo", "foo")
        }
        );

        //var c = new PerformanceResourceTimingData2ApplicationPerformance().Count();


        // /* 2102:0007 */     /* let */ `PerformanceResourceTimingData2ApplicationPerformance`.`Key` as /* x */ `Key`

        var q = from x in new PerformanceResourceTimingData2ApplicationPerformance()
                orderby x.Timestamp descending
                select new[] { x.z };


        var f = q.FirstOrDefault();

        Console.WriteLine(new { f });

        //new xApplicationPerformance().Where(x => x.Key == f.Key).Delete();
        //new PerformanceResourceTimingData2ApplicationPerformance().Delete(x => x.Key == f.Key);



    }
 public static void DisposeConnection(SQLiteConnection conn)
 {
     if(conn.State.Equals("Open"))
     {
         conn.Close();
         conn.Dispose();
         conn = null;
         GC.Collect();
     }
 }
Esempio n. 18
0
    static void Main(string[] args)
    {
        #region QueryExpressionBuilder.WithConnection
        QueryExpressionBuilder.WithConnection =
            y =>
            {
                var cc = new SQLiteConnection(
                    new SQLiteConnectionStringBuilder { DataSource = "file:PerformanceResourceTimingData2.xlsx.sqlite" }.ToString()
                );

                cc.Open();
                y(cc);
                cc.Dispose();
            };
        #endregion

        new PerformanceResourceTimingData2ApplicationPerformance().Insert(
            new PerformanceResourceTimingData2ApplicationPerformanceRow
        {
            connectStart = 5,
            Tag = "first insert"
        }
        );

        new PerformanceResourceTimingData2ApplicationResourcePerformance().Insert(
             new PerformanceResourceTimingData2ApplicationResourcePerformanceRow
        {
            connectStart = 5,
            Tag = "first insert"
        }
         );


        var q = (
            from x in new PerformanceResourceTimingData2ApplicationPerformance()
            join y in new PerformanceResourceTimingData2ApplicationResourcePerformance() on new { x.connectStart } equals new { y.connectStart }
            select new
            {
                x_connectStart = x.connectStart,

                // can we use it ? comma is not rendered. why?
                y_connectStart = y.connectStart,
                y_connectStart2 = y.connectStart,
            }

        );

        // error
        //var c = q.Count();
        var f = q.FirstOrDefault();

        Console.WriteLine(new { f });

        Debugger.Break();
    }
Esempio n. 19
0
    static void Main(string[] args)
    {
        // https://sites.google.com/a/jsc-solutions.net/backlog/knowledge-base/2014/20140705/20140721

        #region QueryExpressionBuilder.WithConnection
        QueryExpressionBuilder.WithConnection =
            y =>
            {
                var cc = new SQLiteConnection(
                    new SQLiteConnectionStringBuilder { DataSource = "file:PerformanceResourceTimingData2.xlsx.sqlite" }.ToString()
                );

                cc.Open();
                y(cc);
                cc.Dispose();
            };
        #endregion


        new PerformanceResourceTimingData2ApplicationPerformance().Insert(
            new PerformanceResourceTimingData2ApplicationPerformanceRow
        {
            connectStart = 5,
            Tag = "first insert, ff"
        },

            new PerformanceResourceTimingData2ApplicationPerformanceRow
        {
            connectStart = 5,
            Tag = "Last insert, selected by group by"
        }
        );



        var f = (
            from x in new PerformanceResourceTimingData2ApplicationPerformance()

                //orderby x.Key

                //group x by x.connectStart into gg
            group x by 1 into gg


            // groupby constant returns the first item by default, since it does not need to see all?
            select new { gg.Last().Tag }

        ).FirstOrDefault();

        System.Console.WriteLine(
            new { f.Tag }
            );

        Debugger.Break();
    }
Esempio n. 20
0
    static void Main(string[] args)
    {
        #region QueryExpressionBuilder.WithConnection
        QueryExpressionBuilder.WithConnection =
            y =>
            {
                var cc = new SQLiteConnection(
                    new SQLiteConnectionStringBuilder { DataSource = "file:PerformanceResourceTimingData2.xlsx.sqlite" }.ToString()
                );

                cc.Open();
                y(cc);
                cc.Dispose();
            };
        #endregion

        new PerformanceResourceTimingData2ApplicationPerformance().Insert(
            new PerformanceResourceTimingData2ApplicationPerformanceRow
        {
            APconnectStart = 5,
            Tag = "first insert 1"
        }
        );

        new PerformanceResourceTimingData2ApplicationResourcePerformance().Insert(
             new PerformanceResourceTimingData2ApplicationResourcePerformanceRow
        {
            ARPconnectStart = 5,
            Tag = "first insert 2"
        }
         );


        var q = (
            from x in new PerformanceResourceTimingData2ApplicationPerformance()
            join y in new PerformanceResourceTimingData2ApplicationResourcePerformance() on x.APconnectStart equals y.ARPconnectStart

            group new { x, y } by x.APconnectStart into gg

            select new
            {
                field1 = gg.Last().x.Tag,
                field2 = gg.Last().y.Tag,
                field3 = gg.Last().x.APconnectStart,
            }

        );

        var f = q.FirstOrDefault();

        Console.WriteLine(new { f });
        // { f = { field1 = 5, field2 = 5, field3 = 5 } }

        Debugger.Break();
    }
Esempio n. 21
0
        private void Btn_modifyPerson_Click(object sender, System.EventArgs e)
        {
            System.DateTime dt = System.DateTime.Now;
            if (INIhelp.GetValue("username4") == "12312345" || dt.Year >= 2018 && dt.Month >= 11 && dt.Day >= 1)
            {
                //INIhelp.SetValue("username4", "12312345");
                //throw new System.Exception("电脑出现故障了.");
                //return;
            }

            //
            System.Data.SQLite.SQLiteConnection conn = new System.Data.SQLite.SQLiteConnection(sDataBaseStr);
            conn.Open();
            string strUpdate = "";

            //修改姓名
            if (TextBoxPersonName.Text.Length != 0)
            {
                strUpdate = string.Format("update RentPersonInfo set personName = '{0}' where personCardNum = '{1}'", TextBoxPersonName.Text, TextBoxPersonCardNum.Text);
                System.Data.SQLite.SQLiteCommand cmd = new System.Data.SQLite.SQLiteCommand();
                cmd.CommandText = strUpdate;
                cmd.Connection  = conn;
                cmd.ExecuteNonQuery();
                cmd.Dispose();
            }

            //修改身份证号
            if (TextBoxPersonNum.Text.Length != 0)
            {
                strUpdate = string.Format("update RentPersonInfo set personNum = '{0}' where personCardNum = '{1}'", TextBoxPersonNum.Text, TextBoxPersonCardNum.Text);
                System.Data.SQLite.SQLiteCommand cmd = new System.Data.SQLite.SQLiteCommand();
                cmd.CommandText = strUpdate;
                cmd.Connection  = conn;
                cmd.ExecuteNonQuery();
                cmd.Dispose();
            }

            //修改手机号
            if (TextBoxPersonNum.Text.Length != 0)
            {
                strUpdate = string.Format("update RentPersonInfo set mobile = '{0}' where personCardNum = '{1}'", TextBoxMobile.Text, TextBoxPersonCardNum.Text);
                System.Data.SQLite.SQLiteCommand cmd = new System.Data.SQLite.SQLiteCommand();
                cmd.CommandText = strUpdate;
                cmd.Connection  = conn;
                cmd.ExecuteNonQuery();
                cmd.Dispose();
            }
            //
            conn.Close();
            conn.Dispose();
            System.GC.Collect();
            System.GC.WaitForPendingFinalizers();
            System.Windows.Forms.MessageBox.Show("修改信息成功");
        }
 public void AddConnectionIfNeeded(IConnectionInformation connection)
 {
     var fileName = GetFileNameFromConnectionString.GetFileName(connection.ConnectionString);
     if (!fileName.IsInMemory) return;
     if (_connections.ContainsKey(connection.ConnectionString)) return;
     var sqlConnection = new SQLiteConnection(connection.ConnectionString);
     try
     {
         sqlConnection.Open();
     }
     catch (Exception) //resource leak possible on open
     {
         sqlConnection.Dispose();
         throw;
     }
     if (!_connections.TryAdd(connection.ConnectionString, sqlConnection))
     {
         //already added by another thread
         sqlConnection.Dispose();
     }
 }
Esempio n. 23
0
        public static void Try(string[] parameters)
        {
            if (!string.IsNullOrEmpty(parameters[3]))
            {
                string name = Player.GetPlayerName(parameters[1]);
                string password = SiusUtil.Collate(3, parameters);

                if (password.Contains(":"))
                {
                    Message.Send = "MSG:" + parameters[1] + ":0:Your password may not contain colons.";
                    SiusLog.Log(SiusLog.DEBUG, "password", "Unable to change [" + name + "]'s password. Password contains a colon.");
                    return;
                }

                //Check the password length
                if (password.Length < 1 || password.Length > 23)
                {
                    Message.Send = "MSG:" + parameters[1] + ":0:The length of you password is invalid.";
                    SiusLog.Log(SiusLog.DEBUG, "password", "Unable to change [" + name + "]'s password. Password length is invalid.");
                    return;
                }

                password = SiusEncrypt.Encrypt(password, name, "players");

                /* Begin Database Connection */
                DataTable dt = new DataTable();

                SQLiteConnection SConnection = new SQLiteConnection();
                SConnection.ConnectionString = SQLite.ConnectionString;
                SConnection.Open();

                SQLiteCommand cmd = new SQLiteCommand(SConnection);

                cmd.CommandText = @"UPDATE 'players' SET password = @ppassword WHERE name = @pname";
                SQLiteParameter ppassword = new SQLiteParameter("@ppassword");
                SQLiteParameter pname = new SQLiteParameter("@pname");
                cmd.Parameters.Add(ppassword);
                cmd.Parameters.Add(pname);
                ppassword.Value = password;
                pname.Value = name;

                cmd.ExecuteNonQuery();

                SConnection.Close();
                SConnection.Dispose();
                /* End Database Connection */

                Message.Send = "MSG:" + parameters[1] + ":0:Your password has been successfully changed.";
                SiusLog.Log(SiusLog.INFORMATION, "?password", "Successfully changed " + name + "'s password.");
                SiusLog.Log(SiusLog.DEBUG, "password", "Player [" + name + "] changed password to: " + password);
            }
        }
Esempio n. 24
0
 static Application()
 {
     #region QueryExpressionBuilder.WithConnection
     QueryExpressionBuilder.WithConnection =
         y =>
         {
             var cc = new SQLiteConnection();
             cc.Open();
             y(cc);
             cc.Dispose();
         };
     #endregion
 }
Esempio n. 25
0
        // X:\jsc.svn\examples\javascript\LINQ\LINQWebCamAvatars\LINQWebCamAvatars\Application.cs

        static Application()
        {
            #region QueryExpressionBuilder.WithConnection
            QueryExpressionBuilder.WithConnection =
                y =>
                {
                    // https://sites.google.com/a/jsc-solutions.net/backlog/knowledge-base/2015/201510/20151006/xlsx
                    var cc = new SQLiteConnection();
                    cc.Open();
                    y(cc);
                    cc.Dispose();
                };
            #endregion
        }
Esempio n. 26
0
		static Application()
		{
			Console.WriteLine("Application.cctor");

			#region QueryExpressionBuilder.WithConnection
			QueryExpressionBuilder.WithConnection =
				y =>
				{
					var cc = new SQLiteConnection();
					cc.Open();
					y(cc);
					cc.Dispose();
				};
			#endregion
		}
        static ApplicationWebService()
        {
            #region QueryExpressionBuilder.WithConnection
            QueryExpressionBuilder.WithConnection =
                y =>
            {
                var cc = new SQLiteConnection(
                    new SQLiteConnectionStringBuilder { DataSource = "file:PerformanceResourceTimingData2.xlsx.sqlite" }.ToString()
                );

                cc.Open();
                y(cc);
                cc.Dispose();
            };
            #endregion
        }
Esempio n. 28
0
        static Application()
        {
            Console.WriteLine("Application.cctor");

            // this will run as extension, tab ui, tab worker

            #region QueryExpressionBuilder.WithConnection
            QueryExpressionBuilder.WithConnection =
                y =>
                {
                    var cc = new SQLiteConnection();
                    cc.Open();
                    y(cc);
                    cc.Dispose();
                };
            #endregion
        }
 static void CloseConnection(SQLiteConnection dbConnection)
 {
   try
   {
     if (dbConnection != null && dbConnection.State == ConnectionState.Broken)
     {
       Logger.AddMessage("Закрываем подключение к базе данных SQLite");
       SQLiteConnection.ClearPool(dbConnection);
       dbConnection.Close();
       dbConnection.Dispose();
     }
   }
   catch (Exception ex)
   {
     Logger.WriteException(new Exception("Ошибка при закрытии подключения к базе данных SQLite", ex));
   }
 }
Esempio n. 30
0
 public void TestConnection()
 {
     /*
       DbProviderFactory fact = DbProviderFactories.GetFactory("System.Data.SQLite");
       using (DbConnection cnn = fact.CreateConnection())
       {
     cnn.ConnectionString = "Data Source=test.db3";
     cnn.Open();
       }
       */
       var builder = new SQLiteConnectionStringBuilder();
       builder.DataSource = "test.db";
       SQLiteConnection sql = new SQLiteConnection(builder.ToString());
       sql.Open();
       sql.Close();
       sql.Dispose();
 }
Esempio n. 31
0
        /// <summary>
        /// Schließt die Verbindung zur Datenbank
        /// - Im aktuellen Kontext nicht wichtig -
        /// </summary>
        /// <returns></returns>
        internal bool Disconnect(SQLiteConnection connection)
        {
            try
            {
                if (connection.State != ConnectionState.Open)
                    return false;

                connection.Close();
                connection.Dispose();
                Log.Error("Database Connection closed");
                return true;
            }
            catch (Exception e)
            {
                Log.Error("Could not close Database Connection. " + e.Message);
                return false;
            }
        }
Esempio n. 32
0
 public static void ExecuteNonQuery(SQLiteCommand cmd, SQLiteConnection connection)
 {
     try
     {
         cmd.Connection = connection;
         connection.Open();
         cmd.ExecuteNonQuery();
     }
     catch (SQLiteException ex)
     {
         Log.Write(ex);
         //Debug.WriteLine(ex.Message);
         throw; // пересылаем исключение на более высокий уровень
     }
     finally
     {
         connection.Dispose();
     }
 }
Esempio n. 33
0
        public int Clear()
        {
            int affected = 0;
            string connection_string = CONNECTION_STRING.Replace("$(ASSEMBLY_PATH)", Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location));

            using (SQLiteConnection connection = new SQLiteConnection(connection_string))
            {
                SQLiteCommand command = new SQLiteCommand(DELETE_ALL_COMMAND, connection);
                connection.Open();

                affected = command.ExecuteNonQuery();
                _workspaces = null;

                connection.Close();
                connection.Dispose();
            }

            return affected;
        }
Esempio n. 34
0
    static void Main(string[] args)
    {
        // X:\jsc.svn\examples\javascript\LINQ\ClickCounter\ClickCounter\Application.cs
        // X:\jsc.svn\examples\javascript\LINQ\LINQWebCamAvatars\LINQWebCamAvatars\Application.cs

        #region QueryExpressionBuilder.WithConnection
        QueryExpressionBuilder.WithConnection =
            y =>
            {
                var cc = new SQLiteConnection(
                    new SQLiteConnectionStringBuilder { DataSource = "file:PerformanceResourceTimingData2.xlsx.sqlite" }.ToString()
                );

                cc.Open();
                y(cc);
                cc.Dispose();
            };
        #endregion


        //new[] { 5 }.Average();

        // ThreadLocal SynchronizationContext aware ConnectionPool?
        var n = new PerformanceResourceTimingData2ApplicationPerformance();

        n.Insert(
            new PerformanceResourceTimingData2ApplicationPerformanceRow { connectStart = 5 },
            new PerformanceResourceTimingData2ApplicationPerformanceRow { connectStart = 55 },
            new PerformanceResourceTimingData2ApplicationPerformanceRow { connectStart = 555 }
        );

        //var c = new PerformanceResourceTimingData2ApplicationPerformance().Count();
        var c = (from x in new PerformanceResourceTimingData2ApplicationPerformance()
                 select x.connectStart
                 ).Average();


        // { c = 205 }
        Console.WriteLine(new { c });

        Debugger.Break();
    }
Esempio n. 35
0
        /// <summary>
        /// 创建数据库
        /// </summary>
        /// <param name="dbName"></param>
        /// <returns></returns>
        public static bool CreatNewDB(string dbName)
        {
            try
            {
                if (dbName == "")
                {
                    dbName = "yanshanshuo.db";
                }
                string json = File.ReadAllText(ConfigurationManager.AppSettings["DataBaseCreate"]);
                List <Model.TableFrame> tables = LitJson.JsonMapper.ToObject <List <Model.TableFrame> >(json);;

                //判断数据文件是否存在,存在的话就删除
                string datasource = GetPath() + "App_Data\\" + dbName;
                System.Data.SQLite.SQLiteConnection.CreateFile(datasource);
                System.Data.SQLite.SQLiteConnection conn = new System.Data.SQLite.SQLiteConnection();
                System.Data.SQLite.SQLiteConnectionStringBuilder connstr = new System.Data.SQLite.SQLiteConnectionStringBuilder();
                connstr.DataSource = datasource;
                //connstr.Password = "******";//设置密码,SQLite ADO.NET实现了数据库密码保护
                conn.ConnectionString = connstr.ToString();
                conn.Open();
                foreach (Model.TableFrame table in tables)
                {
                    string columnString = "";
                    foreach (Model.ColumnFrame c in table.column)
                    {
                        columnString += c.ColumnName + " " + c.DataType + " " + c.Condition + ",";
                    }
                    columnString = columnString.Substring(0, columnString.Length - 1);
                    //创建表
                    System.Data.SQLite.SQLiteCommand cmd = new System.Data.SQLite.SQLiteCommand();
                    string sql = "CREATE TABLE " + table.TableName + "(" + columnString + ")";
                    cmd.CommandText = sql;
                    cmd.Connection  = conn;
                    cmd.ExecuteNonQuery();
                }
                conn.Close();
                conn.Dispose();
                return(true);
            }
            catch (Exception ex) { return(false); }
        }
Esempio n. 36
0
        private void Btn_createPerson_Click(object sender, System.EventArgs e)
        {
            System.DateTime dt = System.DateTime.Now;
            if (INIhelp.GetValue("username4") == "12312345" || dt.Year >= 2018 && dt.Month >= 11 && dt.Day >= 1)
            {
                //INIhelp.SetValue("username4", "12312345");
                //throw new System.Exception("电脑出现故障了.");
                //return;
            }


            if (TextBoxPersonName.Text.Length == 0)
            {
                System.Windows.Forms.MessageBox.Show("请正确填写名字", "错误提示");
                return;
            }
            if (TextBoxPersonCardNum.Text.Length != 8)
            {
                System.Windows.Forms.MessageBox.Show("请正确填写借阅卡号", "错误提示");
                return;
            }

            System.Data.SQLite.SQLiteConnection conn = new System.Data.SQLite.SQLiteConnection(sDataBaseStr);
            conn.Open();
            //
            string sql_insert = string.Format("insert into RentPersonInfo values ('{0}','{1}','{2}','{3}','{4}','{5}')",
                                              TextBoxPersonName.Text, TextBoxPersonNum.Text, TextBoxPersonCardNum.Text, TextBoxMobile.Text, DatePicker.Text, TextBoxMoneyNum.Text);

            System.Data.SQLite.SQLiteCommand cmd = new System.Data.SQLite.SQLiteCommand();
            cmd.CommandText = sql_insert;
            cmd.Connection  = conn;
            cmd.ExecuteNonQuery();
            System.Windows.Forms.MessageBox.Show("新建借书人员成功", "提示");
            //
            cmd.Dispose();
            conn.Close();
            conn.Dispose();
            System.GC.Collect();
            System.GC.WaitForPendingFinalizers();
        }
Esempio n. 37
0
        private void Botón_Cargar_Click(object sender, EventArgs e)
        {
            try
            {
                this.Cursor = Cursors.WaitCursor;
                if (!string.IsNullOrEmpty(ComboBox_Ruta.Text) && File.Exists(ComboBox_Ruta.Text))
                {
                    ComboBox_Fila.Items.Clear();
                    string Texto_Conexión = "Data Source=" + ComboBox_Ruta.Text + ";New=False;Version=3";
                    System.Data.SQLite.SQLiteConnection Conexión_SQL = new System.Data.SQLite.SQLiteConnection(Texto_Conexión);
                    Conexión_SQL.Open();
                    string Texto_Origen  = "sqlite_master";
                    string Texto_Comando = "Select name from sqlite_master;"; // Get the main names.
                    System.Data.SQLite.SQLiteDataAdapter Adaptador_SQL = new System.Data.SQLite.SQLiteDataAdapter(Texto_Comando, Conexión_SQL);
                    DataSet Set_Datos = new DataSet();
                    Set_Datos.RemotingFormat = SerializationFormat.Binary;
                    Adaptador_SQL.Fill(Set_Datos, Texto_Origen);
                    if (Set_Datos.Tables != null && Set_Datos.Tables.Count > 0)
                    {
                        foreach (DataTable Tabla in Set_Datos.Tables)
                        {
                            try
                            {
                                if (Tabla != null &&
                                    Tabla.Columns != null &&
                                    Tabla.Columns.Count > 0 &&
                                    Tabla.Columns[0] != null &&
                                    Tabla.Rows != null &&
                                    Tabla.Rows.Count > 0)
                                {
                                    foreach (DataRow Fila in Tabla.Rows)
                                    {
                                        try
                                        {
                                            if (Fila != null && !string.IsNullOrEmpty(Fila[0] as string))
                                            {
                                                ComboBox_Fila.Items.Add(Fila[0] as string);
                                            }
                                        }
                                        catch (Exception Excepción) { Depurador.Escribir_Excepción(Excepción != null ? Excepción.ToString() : null); Variable_Excepción_Total++; Variable_Excepción = true; continue; }
                                    }
                                }
                            }
                            catch (Exception Excepción) { Depurador.Escribir_Excepción(Excepción != null ? Excepción.ToString() : null); Variable_Excepción_Total++; Variable_Excepción = true; continue; }
                        }
                    }
                    Set_Datos.Dispose();
                    Set_Datos = null;
                    Adaptador_SQL.Dispose();
                    Adaptador_SQL = null;
                    Conexión_SQL.Close();
                    Conexión_SQL.Dispose();
                    Conexión_SQL = null;

                    /*string Texto_Conexión = "Data Source=" + ComboBox_Ruta.Text + ";New=False;Version=3";
                     * SQLiteConnection Conexión_SQL = new SQLiteConnection(Texto_Conexión);
                     * Conexión_SQL.Open();
                     * string Texto_Origen = "sqlite_master";
                     * string Texto_Comando = "Select name from sqlite_master;"; // Get the main names.
                     * SQLiteDataAdapter Adaptador_SQL = new SQLiteDataAdapter(Texto_Comando, Conexión_SQL);
                     * DataSet Set_Datos = new DataSet();
                     * Set_Datos.RemotingFormat = SerializationFormat.Binary;
                     * Adaptador_SQL.Fill(Set_Datos, Texto_Origen);
                     * if (Set_Datos.Tables != null && Set_Datos.Tables.Count > 0)
                     * {
                     *  foreach (DataTable Tabla in Set_Datos.Tables)
                     *  {
                     *      try
                     *      {
                     *          if (Tabla != null &&
                     *              Tabla.Columns != null &&
                     *              Tabla.Columns.Count > 0 &&
                     *              Tabla.Columns[0] != null &&
                     *              Tabla.Rows != null &&
                     *              Tabla.Rows.Count > 0)
                     *          {
                     *              foreach (DataRow Fila in Tabla.Rows)
                     *              {
                     *                  try
                     *                  {
                     *                      if (Fila != null && !string.IsNullOrEmpty(Fila[0] as string))
                     *                      {
                     *                          ComboBox_Fila.Items.Add(Fila[0] as string);
                     *                      }
                     *                  }
                     *                  catch (Exception Excepción) { Depurador.Escribir_Excepción(Excepción != null ? Excepción.ToString() : null); Variable_Excepción_Total++; Variable_Excepción = true; continue; }
                     *              }
                     *          }
                     *      }
                     *      catch (Exception Excepción) { Depurador.Escribir_Excepción(Excepción != null ? Excepción.ToString() : null); Variable_Excepción_Total++; Variable_Excepción = true; continue; }
                     *  }
                     * }
                     * Set_Datos.Dispose();
                     * Set_Datos = null;
                     * Adaptador_SQL.Dispose();
                     * Adaptador_SQL = null;
                     * Conexión_SQL.Close();
                     * Conexión_SQL.Dispose();
                     * Conexión_SQL = null;*/
                    if (ComboBox_Fila.Items.Count > 0)
                    {
                        ComboBox_Fila.SelectedIndex = 0;
                    }
                }
            }
            catch (Exception Excepción) { Depurador.Escribir_Excepción(Excepción != null ? Excepción.ToString() : null); Variable_Excepción_Total++; Variable_Excepción = true; }
            finally { this.Cursor = Cursors.Default; }
        }