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


C# SqliteConnection.Open方法代码示例

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


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

示例1: ExecuteCommand

        /// <summary>
        /// Execute command on the database, commands are serialized
        /// </summary>
        /// <param name="database"></param>
        /// <param name="commandText"></param>
        /// <returns></returns>
        public static IEnumerable<SqliteDataReader> ExecuteCommand(string database, string commandText)
        {
            SqliteConnection conn;
            if (!_Connection.TryGetValue(database, out conn))
            {
                conn = new SqliteConnection(SqliteConnectionManager.GetConnectionString(database));
                conn.Open();
                _Connection.Add(database, conn);
            }

            lock (conn)
            {
                var command = conn.CreateCommand();
                command.CommandText = commandText;

                using (var result = command.ExecuteReader())
                {
                    while (result.Read())
                    {
                        yield return result;
                    }
                }

                command.Dispose();
            }
        }
开发者ID:Clancey,项目名称:Wp7Sqlite,代码行数:32,代码来源:ConnectionManager.cs

示例2: CodeProjectDatabase

        public CodeProjectDatabase()
        {
            dbPath = "items.db3";

            IsolatedStorageFile isf = IsolatedStorageFile.GetUserStoreForApplication();
            bool exists = isf.FileExists(dbPath);

            var connection = new SqliteConnection("data source=" + dbPath);
            connection.Open();
                
            if (!exists)
            {
                var commands = new[]{
					"CREATE TABLE [Member] (Key integer, Name ntext, ArticleCnt integer, BlogCnt integer, Reputation ntext, IsMe integer);"
				};
                foreach (var command in commands)
                {
                    using (var c = connection.CreateCommand())
                    {
                        c.CommandText = command;
                        c.ExecuteNonQuery();
                    }
                }
            }

        }
开发者ID:Trojka,项目名称:monoCPVanity,代码行数:26,代码来源:CodeProjectDatabase.WP7.cs

示例3: CreateConnection

        protected override ICSDbConnection CreateConnection()
        {
            SqliteConnection conn = new SqliteConnection(ConnectionString);

            conn.Open();
            
            return new CSSqliteConnection(conn);
        }
开发者ID:TheMouster,项目名称:coolstorage,代码行数:8,代码来源:CSDataProviderSqliteWinRT.cs

示例4: ExecuteNonQuery

        public static int ExecuteNonQuery(string sql)
        {
            using (SqliteConnection connection = new SqliteConnection())
            {
                connection.ConnectionString = ConnectionString;
                System.Data.IDbCommand cmd = connection.CreateCommand();
                cmd.CommandText = sql;

                connection.Open();
                return cmd.ExecuteNonQuery();
            }
        }
开发者ID:pisceanfoot,项目名称:codeshare,代码行数:12,代码来源:SQLHepler.cs

示例5: Open

 /// <summary>
 /// Open a connection to the database.
 /// </summary>
 private void Open()
 {
     if (db == null)
     {
         try
         {
             db = new SqliteConnection(Constants.Database.connectionString);
             db.Open();
         }
         catch (Exception e)
         {
             System.Windows.MessageBox.Show("Error while connecting to Database: \n" + e.Message + "\n" + e.StackTrace);
         }
     }
 }
开发者ID:Frannsoft,项目名称:dnd35encyclopedia,代码行数:18,代码来源:DBHelper.cs

示例6: OpenDatabase

 public static bool OpenDatabase(string dbFileName)
 {
     try
     {
         Log.log("Opening sqlite database connection: "+dbFileName);
         string cs = string.Format("Version=3,uri=file:{0}", dbFileName);
         connection = new SqliteConnection(cs);
         connection.Open();
         trans =  connection.BeginTransaction();
         return true;
     }
     catch (Exception e)
     {
         return false;
     }
 }
开发者ID:Xplo1T,项目名称:l2tower-database-repository,代码行数:16,代码来源:SqliteManager.cs

示例7: ExecuteNonQuery

        /// <summary>
        /// Shortcut to ExecuteNonQuery with SqlStatement and object[] param values
        /// </summary>
        /// <param name="connectionString">SQLite Connection String</param>
        /// <param name="commandText">Sql Statement with embedded "@param" style parameters</param>
        /// <param name="paramList">object[] array of parameter values</param>
        /// <returns></returns>
        public static int ExecuteNonQuery(string connectionString, string commandText, object[] paramList)
        {
            SqliteConnection cn = new SqliteConnection(connectionString);
            IDbCommand cmd = cn.CreateCommand();
            cmd.CommandText = commandText;
            if (paramList != null)
            {
                cmd.CommandText = string.Format(commandText, paramList);
            }

            if (cn.State == ConnectionState.Closed)
                cn.Open();
            int result = cmd.ExecuteNonQuery();
            cmd.Dispose();
            cn.Close();

            return result;
        }
开发者ID:pnhlong,项目名称:fingerPointSys,代码行数:25,代码来源:CsharpSQLiteHelper.cs

示例8: ConnectToDatabase

        public override void ConnectToDatabase(string connectionString, string migratorName, bool validateTables)
        {
            _connectionString = connectionString;
            string[] s1 = _connectionString.Split(new[] {"Data Source=", ","}, StringSplitOptions.RemoveEmptyEntries);

            s1[0] = s1[0].Remove(0, 7);

            _fileName = Path.GetFileName(s1[0]);
            if (_fileName == s1[0]) //Only add this if we arn't an absolute path already
                _connectionString = string.Format("Data Source=file://{0}", Path.Combine(Util.BasePathCombine(""), _fileName));

            SqliteConnection connection = new SqliteConnection(_connectionString);
            connection.Open();
            var migrationManager = new MigrationManager(this, migratorName, validateTables);
            migrationManager.DetermineOperation();
            migrationManager.ExecuteOperation();
            connection.Close();
        }
开发者ID:velus,项目名称:Async-Sim-Testing,代码行数:18,代码来源:SQLiteDataManager.cs

示例9: AddMember

		public bool AddMember(CodeProjectMember member)
		{
            var connection = new SqliteConnection("Data Source=" + dbPath);
            connection.Open();

            using (var command = connection.CreateCommand())
            {
                command.CommandText = "SELECT [Key] FROM [Member] WHERE [Key]=" + member.Id;
                var r = command.ExecuteReader();
                if (r.HasRows)
                {
                    using (var uc = connection.CreateCommand())
                    {
                        uc.CommandText = "UPDATE [Member] SET " +
                            " [Name] = '" + member.Name + "'," +
                            " [ArticleCnt] = '" + member.ArticleCount + "'," +
                            " [BlogCnt] = '" + member.BlogCount + "'," +
                            " [Reputation] = '" + member.Reputation + "'," +
                            " WHERE [Key]=" + member.Id;
                        uc.ExecuteNonQuery();
                    }
                }
                else
                {
                    using (var ic = connection.CreateCommand())
                    {
                        ic.CommandText = "INSERT INTO [Member] ([Key], [Name], [ArticleCnt], [BlogCnt], [Reputation])"
                            + " VALUES(" + member.Id + ", '" + member.Name + "', '" + member.ArticleCount + "', '" + member.BlogCount + "', '" + member.Reputation + "')";
                        ic.ExecuteNonQuery();
                    }
                }
            }

            connection.Close();

            FileStorageService storage = new FileStorageService();
            if (member.Avatar != null)
            {
                storage.WriteBytes(member.Avatar, member.Id.ToString());
            }

            return true;
        }
开发者ID:Trojka,项目名称:monoCPVanity,代码行数:43,代码来源:CodeProjectDatabase.WP7.cs

示例10: Apply

 public void Apply(SqliteConnection connection)
 {
     _connection = connection;
     _log.Info("Start updating db");
     _connection.Open();
     try
     {
         CreateVcard();
         SetupVersion();
     }
     catch (Exception e)
     {
         _log.Fatal("Unexpected error", e);
         throw;
     }
     finally
     {
         _connection.Close();
     }
 }
开发者ID:Irdis,项目名称:VSTalk,代码行数:20,代码来源:Migration2.cs

示例11: MainPage_Loaded

        protected void MainPage_Loaded(object sender, EventArgs e)
         {

             //SQLiteClientTests.SQLiteClientTestDriver.Main(null);
             IDbConnection cnn;

             try
             {
                 System.IO.IsolatedStorage.IsolatedStorageFile.GetUserStoreForApplication().DeleteFile("test.db3");
             }
             catch { }


             using (cnn = new SqliteConnection())
             {
                 TestCases tests = new TestCases();

                 cnn.ConnectionString = "data source=test.db3,password=0x01010101010101010101010101010101";
                 cnn.Open();
                 tests.Run(cnn, this);
             }
         }
开发者ID:CryptoManiac,项目名称:csharpsqlite,代码行数:22,代码来源:MainPage.xaml.cs

示例12: QueryVersion

 private int QueryVersion(SqliteConnection connection)
 {
     connection.Open();
     try
     {
         var tableExists = connection.CreateCommand();
         tableExists.CommandText = "SELECT name FROM sqlite_master WHERE type='table' AND name='version';";
         var versionNumber = connection.CreateCommand();
         versionNumber.CommandText = "SELECT num FROM version;";
         _log.Info("Query version table");
         using (var reader = tableExists.ExecuteReader())
         {
             if (!reader.HasRows)
             {
                 _log.Info("Database is empty");
                 return 0;
             }
         }
         _log.Info("Query version number");
         using (var reader = versionNumber.ExecuteReader())
         {
             reader.Read();
             var numb = (int) reader.GetValue(0);
             _log.Info(string.Format("Database version is {0}", numb));
             return numb;
         }
     }
     catch (Exception e)
     {
         _log.Fatal("Unexpected exception", e);
         throw;
     }
     finally
     {
         connection.Close();
     }
 }
开发者ID:Irdis,项目名称:VSTalk,代码行数:37,代码来源:ConnectionFactory.cs

示例13: Issue_119

    public void Issue_119()
    {
      Console.WriteLine("Test Start.");

      Console.WriteLine("Create connection...");
      SqliteConnection con = new SqliteConnection();

      string dbFilename = @"=SqliteTest3=.db";
      string cs = string.Format("Version=3,uri=file:{0}", dbFilename);

      Console.WriteLine("Set connection String: {0}", cs);

      if (File.Exists(dbFilename))
        File.Delete(dbFilename);

      con.ConnectionString = cs;

      Console.WriteLine("Open database...");
      con.Open();

      Console.WriteLine("create command...");
      IDbCommand cmd = con.CreateCommand();

      Console.WriteLine("create table TEST_TABLE...");
      cmd.CommandText = "CREATE TABLE TEST_TABLE ( COLA INTEGER, COLB TEXT, COLC DATETIME )";
      cmd.ExecuteNonQuery();

      Console.WriteLine("insert row 1...");
      cmd.CommandText = "INSERT INTO TEST_TABLE ( COLA, COLB, COLC ) VALUES (123,'ABC','2008-12-31 18:19:20' )";
      cmd.ExecuteNonQuery();

      Console.WriteLine("insert row 2...");
      cmd.CommandText = "INSERT INTO TEST_TABLE ( COLA, COLB, COLC ) VALUES (124,'DEF', '2009-11-16 13:35:36' )";
      cmd.ExecuteNonQuery();

      Console.WriteLine("SELECT data from TEST_TABLE...");
      cmd.CommandText = "SELECT RowID, COLA, COLB, COLC FROM TEST_TABLE";
      IDataReader reader = cmd.ExecuteReader();
      int r = 0;
      Console.WriteLine("Read the data...");
      while (reader.Read())
      {
        Console.WriteLine("  Row: {0}", r);
        int rowid = reader.GetInt32(reader.GetOrdinal("RowID"));
        Console.WriteLine("    RowID: {0}", rowid);

        int i = reader.GetInt32(reader.GetOrdinal("COLA"));
        Console.WriteLine("    COLA: {0}", i);

        string s = reader.GetString(reader.GetOrdinal("COLB"));
        Console.WriteLine("    COLB: {0}", s);

        DateTime dt = reader.GetDateTime(reader.GetOrdinal("COLC"));
        Console.WriteLine("    COLB: {0}", dt.ToString("MM/dd/yyyy HH:mm:ss"));

        r++;
      }

      Console.WriteLine("Close and cleanup...");
      con.Close();
      con = null;

      Console.WriteLine("Test Done.");
    }
开发者ID:Jaden-J,项目名称:csharp-sqlite,代码行数:64,代码来源:SQLiteClientTestDriver.cs

示例14: GetMembers

        public List<CodeProjectMember> GetMembers()
		{
            List<CodeProjectMember> memberList = new List<CodeProjectMember>();

            var connection = new SqliteConnection("Data Source=" + dbPath);
            connection.Open();

            using (var command = connection.CreateCommand())
            {
                command.CommandText = "SELECT [Key], [Name], [ArticleCnt], [BlogCnt], [Reputation], [IsMe] FROM [Member]";
                var r = command.ExecuteReader();
                while (r.Read())
                {
                    CodeProjectMember member = new CodeProjectMember();
                    FillMemberFromDataReader(member, r);
                    memberList.Add(member);
                }
            }

            connection.Close();

            return memberList;
        }
开发者ID:Trojka,项目名称:monoCPVanity,代码行数:23,代码来源:CodeProjectDatabase.WP7.cs

示例15: GetMember

		public CodeProjectMember GetMember(int memberId)
		{
            var connection = new SqliteConnection("Data Source=" + dbPath);
            connection.Open();

            CodeProjectMember member = new CodeProjectMember();
            member.Id = memberId;

            using (var command = connection.CreateCommand())
            {
                command.CommandText = "SELECT [Key], [Name], [ArticleCnt], [BlogCnt], [Reputation], [IsMe] FROM [Member] WHERE [Key]=" + memberId;
                var r = command.ExecuteReader();
                while (r.Read())
                {
                    FillMemberFromDataReader(member, r);
                }
            }

            connection.Close();

            return member;
        }
开发者ID:Trojka,项目名称:monoCPVanity,代码行数:22,代码来源:CodeProjectDatabase.WP7.cs


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