示例#1
0
        private DbConnection CreateConn(string key)
        {
            DBConfig     dbConfig = _config[key];
            DbConnection conn     = null;

            if (dbConfig.Driver.ToUpper() == "SQLITE")
            {
                conn = new SQLiteConnection($"data source={dbConfig.ConnStr}");
            }
            return(conn);
        }
示例#2
0
        public void CreateDB()
        {
            DBConfig dbConfig = _config["MainDB"];

            if (!File.Exists(dbConfig.ConnStr))
            {
                DbConnection conn = CreateConn("MainDB");
                try
                {
                    string strSQL = $@"
CREATE TABLE [Ticket](
    [ID] INT PRIMARY KEY NOT NULL, 
    [Name] VARCHAR(50) NOT NULL, 
    [Seat] VARCHAR(50) NOT NULL, 
    [Amount] FLOAT NOT NULL, 
    [DateTime] DATETIME NOT NULL);
CREATE TABLE [Auth_User](
    [Account] NVARCHAR(50) PRIMARY KEY NOT NULL, 
    [Password] VARCHAR(50) NOT NULL);
INSERT INTO Auth_User
       ( Account,  Password)
VALUES ('hyflame', 'password')
";
                    conn.Execute(strSQL);
                }
                catch (Exception ex)
                {
                    _logger.Error(ex, "CreateDB");
                    throw ex;
                }
                finally
                {
                    conn?.Close();
                }
            }
        }