本文整理汇总了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();
}
}
示例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();
}
}
}
}
示例3: CreateConnection
protected override ICSDbConnection CreateConnection()
{
SqliteConnection conn = new SqliteConnection(ConnectionString);
conn.Open();
return new CSSqliteConnection(conn);
}
示例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();
}
}
示例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);
}
}
}
示例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;
}
}
示例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;
}
示例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();
}
示例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;
}
示例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();
}
}
示例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);
}
}
示例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();
}
}
示例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.");
}
示例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;
}
示例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;
}