当前位置: 首页>>代码示例>>C#>>正文


C# SqliteConnection.Open方法代码示例

本文整理汇总了C#中Mono.Data.Sqlite.SqliteConnection.Open方法的典型用法代码示例。如果您正苦于以下问题:C# SqliteConnection.Open方法的具体用法?C# SqliteConnection.Open怎么用?C# SqliteConnection.Open使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Mono.Data.Sqlite.SqliteConnection的用法示例。


在下文中一共展示了SqliteConnection.Open方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: CreateDatabase

    public virtual bool CreateDatabase( string sFile, bool bKeepOpen = false )
    {
        myDatabase = new SqliteConnection();

        try {
            if( System.IO.File.Exists(sFile) ) {
                if( bKeepOpen == true ) {
                    myDatabase.ConnectionString = "Data Source=" + sFile + ";";
                    myDatabase.Open();
                }

                return false;
            }

            myDatabase.ConnectionString = "Data Source=" + sFile + ";";
            myDatabase.Open();

            if( bKeepOpen == false ) {
                myDatabase.Close();
                myDatabase.Dispose();
            }

            return true;
        } catch {
            return false;
        }
    }
开发者ID:Ellorion,项目名称:ClassCollection,代码行数:27,代码来源:CSqlite.cs

示例2: LoadAllPoliticans

        public List<Politician> LoadAllPoliticans()
        {
            var politicians = new List<Politician> ();

            using (var connection = new SqliteConnection (connectionString)) {
                using (var cmd = connection.CreateCommand ()) {
                    connection.Open ();
                    cmd.CommandText = String.Format ("SELECT bioguide_id, first_name, last_name,  govtrack_id, phone, party, state FROM Politician ORDER BY last_name");

                    using (var reader = cmd.ExecuteReader ()) {
                        while (reader.Read ()) {
                            politicians.Add (new Politician {
                                FirstName = reader ["first_name"].ToString (),
                                LastName = reader ["last_name"].ToString (),
                                BioGuideId = reader ["bioguide_id"].ToString (),
                                GovTrackId = reader ["govtrack_id"].ToString (),
                                Phone = reader ["phone"].ToString (),
                                State = reader ["state"].ToString (),
                                Party = reader ["party"].ToString ()
                            });
                        }
                    }
                }
            }
            return politicians;
        }
开发者ID:MilenPavlov,项目名称:PortableRazorStarterKit,代码行数:26,代码来源:DataAccess.cs

示例3: Init

        public static void Init()
        {
            try
            {
                _cards = new Dictionary<int, CardData>();

                string currentPath = Assembly.GetExecutingAssembly().Location;
                currentPath = Path.GetDirectoryName(currentPath) ?? "";
                string absolutePath = Path.Combine(currentPath, "cards.cdb");

                if (!File.Exists(absolutePath))
                {
                    throw new Exception("Could not find the cards database.");
                }

                using (SqliteConnection connection = new SqliteConnection("Data Source=" + absolutePath))
                {
                    connection.Open();

                    const string select =
                        "SELECT datas.id, alias, type, level, race, attribute, atk, def, name, desc " +
                        "FROM datas INNER JOIN texts ON datas.id = texts.id";

                    using (SqliteCommand command = new SqliteCommand(select, connection))
                    using (SqliteDataReader reader = command.ExecuteReader())
                        InitCards(reader);
                }
            }
            catch (Exception ex)
            {
                throw new Exception("Could not initialize the cards database. Check the inner exception for more details.", ex);
            }
        }
开发者ID:Tic-Tac-Toc,项目名称:windbot,代码行数:33,代码来源:CardsManager.cs

示例4: ClearItemsBeforeDate

        /// <summary>
        /// Clears all items from the database where their PublishDate is before the date provided.
        /// </summary>
        /// <param name="date"></param>
        public void ClearItemsBeforeDate(DateTime date)
        {
            try
            {
                using (SqliteConnection connection = new SqliteConnection(ItemsConnectionString))
                {
                    connection.Open();
                    using (SqliteCommand command = new SqliteCommand(connection))
                    {
                        string sql = @"DELETE FROM items WHERE DATETIME(publishdate) <= DATETIME(@date)";
                        command.CommandText = sql;

                        SqliteParameter parameter = new SqliteParameter("@date", DbType.String);
                        parameter.Value = date.ToString("yyyy-MM-dd HH:mm:ss");
                        command.Parameters.Add(parameter);

                        int rows = command.ExecuteNonQuery();
                        Logger.Info("ClearItemsBeforeDate before {0} cleared {1} rows.", date.ToString("yyyy-MM-dd HH:mm:ss"), rows);
                    }
                }
            }
            catch (SqliteException e)
            {
                Logger.Warn("SqliteException occured while clearing items before {0}: \n{1}", date, e);
            }
        }
开发者ID:yetanotherchris,项目名称:really-simple,代码行数:30,代码来源:SqliteRepository.cs

示例5: Start

    void Start ()
    {
        string connectionString = "URI=file:" + Application.dataPath + "/GameMaster"; //Path to database.
        IDbConnection dbcon = new SqliteConnection(connectionString) as IDbConnection;
        dbcon.Open(); //Open connection to the database.

        IDbCommand dbcmd = dbcon.CreateCommand();
        dbcmd.CommandText = "SELECT firstname, lastname " + "FROM addressbook";

        IDataReader reader = dbcmd.ExecuteReader();
        while(reader.Read())
        {
            string FirstName = reader.GetString (0);
            string LastName = reader.GetString (1);
            Console.WriteLine("Name: " + FirstName + " " + LastName);
            UnityEngine.Debug.LogWarning("Name: " + FirstName + " " + LastName);
        }
        reader.Close();
        reader = null;

        dbcmd.Dispose();
        dbcmd = null;

        dbcon.Close();
        dbcon = null;
    }
开发者ID:nacho4d,项目名称:W.G.-Unity3D-SQLite,代码行数:26,代码来源:DBAccess.cs

示例6: SQLiteMonoTransformationProvider

 public SQLiteMonoTransformationProvider(Dialect dialect, string connectionString)
     : base(dialect, connectionString)
 {
     _connection = new SqliteConnection(_connectionString);
     _connection.ConnectionString = _connectionString;
     _connection.Open();
 }
开发者ID:garrinmf,项目名称:Migrator.NET,代码行数:7,代码来源:SQLiteMonoTransformationProvider.cs

示例7: Initialise

        public void Initialise(string connectionString)
        {
            m_connectionString = connectionString;

            m_log.Info("[ESTATE DB]: Sqlite - connecting: "+m_connectionString);

            m_connection = new SqliteConnection(m_connectionString);
            m_connection.Open();

            Assembly assem = GetType().Assembly;
            Migration m = new Migration(m_connection, assem, "EstateStore");
            m.Update();

            //m_connection.Close();
           // m_connection.Open();

            Type t = typeof(EstateSettings);
            m_Fields = t.GetFields(BindingFlags.NonPublic |
                                   BindingFlags.Instance |
                                   BindingFlags.DeclaredOnly);

            foreach (FieldInfo f in m_Fields)
                if (f.Name.Substring(0, 2) == "m_")
                    m_FieldMap[f.Name.Substring(2)] = f;
        }
开发者ID:AlexRa,项目名称:opensim-mods-Alex,代码行数:25,代码来源:SQLiteEstateData.cs

示例8: Open

        public static IDbConnection Open(string dbPath, bool create)
        {
            if (dbPath == null)
                throw new ArgumentNullException("dbPath");

            if (create) {
                if (File.Exists(dbPath))
                    File.Delete(dbPath);
            #if WIN32
                SQLiteConnection.CreateFile(dbPath);
            #else
                SqliteConnection.CreateFile(dbPath);
            #endif
            } else {
                if (!File.Exists(dbPath))
                    throw new FileNotFoundException(string.Format("Database '{0}' not found", dbPath));
            }

            IDbConnection conn;
            string connStr = string.Format("Data Source={0}", dbPath);
            #if WIN32
            conn = new SQLiteConnection(connStr);
            #else
            conn = new SqliteConnection(connStr);
            #endif
            conn.Open();
            return conn;
        }
开发者ID:pulb,项目名称:basenji,代码行数:28,代码来源:SqliteDB.cs

示例9: IsValidCustomerLogin

        public bool IsValidCustomerLogin(string email, string password)
        {
            //encode password
            string encoded_password = Encoder.Encode(password);
            
            //check email/password
            string sql = "select * from CustomerLogin where email = '" + email + "' and password = '" + 
                         encoded_password + "';";
                        
            using (SqliteConnection connection = new SqliteConnection(_connectionString))
            {
                connection.Open();

                SqliteDataAdapter da = new SqliteDataAdapter(sql, connection);
            
                //TODO: User reader instead (for all calls)
                DataSet ds = new DataSet();
            
                da.Fill(ds);
                
                try
                {
                    return ds.Tables[0].Rows.Count == 0;
                }
                catch (Exception ex)
                {
                    //Log this and pass the ball along.
                    log.Error("Error checking login", ex);
                    
                    throw new Exception("Error checking login", ex);
                }
            }
        }
开发者ID:ldemidov,项目名称:WebGoat.NET,代码行数:33,代码来源:SqliteDbProvider.cs

示例10: DrinkDatabase

        public DrinkDatabase(string dbPath)
        {
            path = dbPath;
            // create the tables
            bool exists = File.Exists(dbPath);

            if (!exists)
            {
                connection = new SqliteConnection("Data Source=" + dbPath);

                connection.Open();
                var commands = new[] {
                    "CREATE TABLE [Items] (_id INTEGER PRIMARY KEY ASC, Name NTEXT, About NTEXT, Volume REAL, AlcoholByVolume REAL, IconNumber INTEGER);"
                };
                foreach (var command in commands)
                {
                    using (var c = connection.CreateCommand())
                    {
                        c.CommandText = command;
                        c.ExecuteNonQuery();
                    }
                }

                initializeValues();
            }
        }
开发者ID:Armoken,项目名称:Learning,代码行数:26,代码来源:DrinksDatabaseADO.cs

示例11: ClickGameStart

    public void ClickGameStart()
    {
        del_InsertNewUserInfo InsertInfo = () =>
        {
            string conn = "URI=file:" + Application.dataPath +
               "/StreamingAssets/GameUserDB/userDB.db";
            using (IDbConnection dbconn = new SqliteConnection(conn))
            {
                dbconn.Open(); //Open connection to the database.
                using (IDbCommand dbcmd = dbconn.CreateCommand())
                {
                    try
                    {
                        string sqlQuery =
                    "INSERT INTO USER_INFO(name, level, type) " +
                    "VALUES(" + "'" + chName.text + "'" + ", " +
                    "'" + chLevel.text + "'" + ", " +
                    "'" + chType.text + "'" + ")";

                        dbcmd.CommandText = sqlQuery;
                        dbcmd.ExecuteNonQuery();
                    }
                    catch(SqliteException e)
                    {
                        // 이미 등록된 캐릭터이다.
                        Debug.Log(e.Message);
                    }
                }
                dbconn.Close();
            }
        };
        InsertInfo();
        GameLoadingProcess();
    }
开发者ID:opk4406opk,项目名称:HELLO_MY_WORLD,代码行数:34,代码来源:PopupChData.cs

示例12: GetConnection

 public static SqliteConnection GetConnection()
 {
     var documents = Environment.GetFolderPath (
         Environment.SpecialFolder.Personal);
     string db = Path.Combine (documents, "mydb.db3");
     bool exists = File.Exists (db);
     if (!exists)
         SqliteConnection.CreateFile (db);
     var conn = new SqliteConnection ("Data Source=" + db);
     if (!exists) {
         var commands = new[] {
             "CREATE TABLE People (Id INTEGER NOT NULL, FirstName ntext, LastName ntext, DateCreated datetime)",
             "INSERT INTO People (Id, FirstName, LastName, DateCreated) VALUES (1, 'Homer', 'Simpson', '2007-01-01 10:00:00')",
         };
         foreach (var cmd in commands){
             using (var c = conn.CreateCommand()) {
                 c.CommandText = cmd;
                 c.CommandType = CommandType.Text;
                 conn.Open ();
                 c.ExecuteNonQuery ();
                 conn.Close ();
             }
         }
     }
     return conn;
 }
开发者ID:dineshkummarc,项目名称:Multi,代码行数:26,代码来源:SqliteScreen.cs

示例13: PreKeyring

        static PreKeyring()
        {
            try
            {
                log.Debug("Opening SQL connection...");
                PreKeyring.conn = new SqliteConnection();

                SqliteConnectionStringBuilder connStr = new SqliteConnectionStringBuilder();
                connStr.DataSource = Config.PrekeyringFile_Path;
                //connStr.Password = Config.PrekeyringFile_Password;
                PreKeyring.conn.ConnectionString = connStr.ToString();
                connectString = connStr.ToString();

                if ( Directory.Exists( Config.PrekeyringFile_Dir ) == false )
                    Directory.CreateDirectory( Config.PrekeyringFile_Dir );

                if ( File.Exists( Config.PrekeyringFile_Path ) == false )
                {
                    SqliteConnection.CreateFile( Config.PrekeyringFile_Path );
                    CreateTablesByStructures( PreKeyring.TableName );
                }
                conn.Open();
            }
            catch ( SqliteException ex )
            {
                SecuruStikException sex = new SecuruStikException( SecuruStikExceptionType.Init_Database,"SQLite - Create/Connect Failed." , ex );
                throw sex;
            }
            finally
            {
                PreKeyring.conn.Close();
            }
        }
开发者ID:lixiaoyi1108,项目名称:SecuruStik,代码行数:33,代码来源:PreKeyring.cs

示例14: GetAllFeeds

        /// <summary>
        /// Returns all subscribed feeds.
        /// </summary>
        public IEnumerable<Feed> GetAllFeeds()
        {
            var feeds = new List<Feed>();

            using (var connection = new SqliteConnection("Data Source=" + dbPath))
            using (var query = new SqliteCommand("SELECT * FROM Feeds", connection))
            {
                connection.Open();

                var reader = query.ExecuteReader(CommandBehavior.CloseConnection);

                while (reader.Read())
                {
                    var feed = new Feed();
                    feed.Id = int.Parse(reader["id"].ToString());
                    feed.Name = reader ["name"].ToString();
                    feed.Url = reader ["url"].ToString();
                    feed.LastUpdated = DateTime.Parse (reader ["LastUpdated"].ToString ());
                    feed.CategoryId = int.Parse(reader["categoryId"].ToString());

                    feeds.Add(feed);
                }

                reader.Close();
            }

            return feeds;
        }
开发者ID:CayasSoftware,项目名称:RSSReader,代码行数:31,代码来源:FeedRepository.cs

示例15: LoadFavoriteBill

        public Bill LoadFavoriteBill(int id)
        {
            Bill favBill;

            using (var connection = new SqliteConnection (connectionString)) {
                using (var cmd = connection.CreateCommand ()) {
                    connection.Open ();

                    cmd.CommandText = "SELECT * FROM FavoriteBills WHERE id = @id";
                    var idParam = new SqliteParameter ("@id", id);
                    cmd.Parameters.Add (idParam);

                    using (var reader = cmd.ExecuteReader ()) {
                        reader.Read ();
                        favBill = new Bill {
                            Id = Convert.ToInt32 (reader ["id"]),
                            Title = (string)reader ["title"],
                            ThomasLink = (string)reader ["thomas_link"],
                            Notes = reader["notes"] == DBNull.Value ? "" : (string)reader["notes"]
                        };
                    }
                }
            }

            return favBill;
        }
开发者ID:MilenPavlov,项目名称:PortableRazorStarterKit,代码行数:26,代码来源:DataAccess.cs


注:本文中的Mono.Data.Sqlite.SqliteConnection.Open方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。