本文整理汇总了C#中System.Data.SQLite.SQLiteConnectionStringBuilder.Add方法的典型用法代码示例。如果您正苦于以下问题:C# SQLiteConnectionStringBuilder.Add方法的具体用法?C# SQLiteConnectionStringBuilder.Add怎么用?C# SQLiteConnectionStringBuilder.Add使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.Data.SQLite.SQLiteConnectionStringBuilder
的用法示例。
在下文中一共展示了SQLiteConnectionStringBuilder.Add方法的12个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: ProfilingDataSQLiteWriter
/// <summary>
/// Creates a new SQLite profiling data provider and opens or creates a new database stored in a file.
/// </summary>
public ProfilingDataSQLiteWriter(string fileName, bool profileUnitTests, string[] unitTestNames)
{
if (File.Exists(fileName))
throw new IOException("File already exists!");
SQLiteConnectionStringBuilder conn = new SQLiteConnectionStringBuilder();
conn.Add("Data Source", fileName);
conn.Add("New", true);
// Disable protecting the database on crashes - it's a new database,
// it may go corrupt if we crash during DB creation. Disabling journalling
// makes Inserts faster.
conn.Add("Journal Mode", "OFF");
conn.Add("Synchronous", "OFF");
this.connection = new SQLiteConnection(conn.ConnectionString);
this.connection.Open();
InitializeTables();
File.SetAttributes(fileName, FileAttributes.Compressed);
this.profileUnitTests = profileUnitTests;
this.unitTestNames = unitTestNames;
if (profileUnitTests && unitTestNames == null)
throw new InvalidOperationException("Please add unit tests to filter!");
}
示例2: DatabaseDriver
/// <summary>
/// Constructor
/// </summary>
/// <param name="Engine">The string name, for the GetDatabaseEngine() method</param>
/// <param name="Host">The Database server IP Address</param>
/// <param name="Port">The Database server Port Number</param>
/// <param name="DatabaseName">The name of the database</param>
/// <param name="User">A username, with database privliages</param>
/// <param name="Pass">The password to the User</param>
public DatabaseDriver(string Engine, string Host, int Port, string DatabaseName, string User, string Pass)
{
// Set class variables, and create a new connection builder
this.DatabaseEngine = GetDatabaseEngine(Engine);
DbConnectionStringBuilder Builder;
// Establish the connection
if (this.DatabaseEngine == DatabaseEngine.Sqlite)
{
// Create the connection
Builder = new SQLiteConnectionStringBuilder();
Builder.Add("Data Source", Path.Combine(Program.RootPath, DatabaseName + ".sqlite3"));
Connection = new SQLiteConnection(Builder.ConnectionString);
}
else if (this.DatabaseEngine == DatabaseEngine.Mysql)
{
// Create the connection
Builder = new MySqlConnectionStringBuilder();
Builder.Add("Server", Host);
Builder.Add("Port", Port);
Builder.Add("User ID", User);
Builder.Add("Password", Pass);
Builder.Add("Database", DatabaseName);
Builder.Add("Convert Zero Datetime", "true");
Connection = new MySqlConnection(Builder.ConnectionString);
}
else
{
throw new Exception("Invalid Database type.");
}
}
示例3: ApplyRestrictedCredentials
static partial void ApplyRestrictedCredentials(SQLiteConnectionStringBuilder b, bool admin = false)
{
//b.Add("InternalHost", "invalidhost");
b.Add("InternalUser", "user3");
b.Password = "mypass";
}
示例4: DatabaseDriver
public DatabaseDriver()
{
this.DatabaseEngine = Config.GetDatabaseEngine();
DbConnectionStringBuilder Builder;
if (this.DatabaseEngine == DatabaseEngine.Sqlite)
{
Builder = new SQLiteConnectionStringBuilder();
string FullPath = Path.Combine(Utils.AssemblyPath, Config.GetType<string>("Database", "Database") + ".sqlite3");
IsNewDatabase = !File.Exists(FullPath) || new FileInfo(FullPath).Length == 0;
Builder.Add("Data Source", FullPath);
Connection = new SQLiteConnection(Builder.ConnectionString);
}
else if (this.DatabaseEngine == DatabaseEngine.Mysql)
{
Builder = new MySqlConnectionStringBuilder();
Builder.Add("Server", Config.GetType<string>("Database", "Hostname"));
Builder.Add("Port", Config.GetType<int>("Database", "Port"));
Builder.Add("User ID", Config.GetType<string>("Database", "Username"));
Builder.Add("Password", Config.GetType<string>("Database", "Password"));
Builder.Add("Database", Config.GetType<string>("Database", "Database"));
Connection = new MySqlConnection(Builder.ConnectionString);
}
else
{
throw new Exception("Invalid Database type.");
}
}
示例5: DatabaseDriver
/// <summary>
/// Constructor
/// </summary>
/// <param name="Engine">The string name, from the GetDatabaseEngine() method</param>
/// <param name="Host">The Database server IP Address</param>
/// <param name="Port">The Database server Port Number</param>
/// <param name="DatabaseName">The name of the database</param>
/// <param name="User">A username, with database privliages</param>
/// <param name="Pass">The password to the User</param>
public DatabaseDriver(string Engine, string Host, int Port, string DatabaseName, string User, string Pass)
{
// Set class variables, and create a new connection builder
this.DatabaseEngine = GetDatabaseEngine(Engine);
DbConnectionStringBuilder Builder;
if (this.DatabaseEngine == DatabaseEngine.Sqlite)
{
string FullPath = Path.Combine(MainForm.Root, DatabaseName + ".sqlite3");
IsNewDatabase = !File.Exists(FullPath) || new FileInfo(FullPath).Length == 0;
Builder = new SQLiteConnectionStringBuilder();
Builder.Add("Data Source", FullPath);
Connection = new SQLiteConnection(Builder.ConnectionString);
}
else if (this.DatabaseEngine == DatabaseEngine.Mysql)
{
IsNewDatabase = false;
Builder = new MySqlConnectionStringBuilder();
Builder.Add("Server", Host);
Builder.Add("Port", Port);
Builder.Add("User ID", User);
Builder.Add("Password", Pass);
Builder.Add("Database", DatabaseName);
Connection = new MySqlConnection(Builder.ConnectionString);
}
else
{
throw new Exception("Invalid Database type.");
}
}
示例6: OpenConnection
SQLiteConnection OpenConnection()
{
SQLiteConnectionStringBuilder conn = new SQLiteConnectionStringBuilder();
conn.Add("Data Source", databaseFileName);
SQLiteConnection connection = new SQLiteConnection(conn.ConnectionString);
connection.Open();
return connection;
}
示例7: GetSQLiteConnectionString
/// <summary>
/// To get the full SQLite connection string given the SQLite database path
/// </summary>
public static string GetSQLiteConnectionString(string dbFileName)
{
// returns "Data Source= " + dbFileName + ";New=False;Compress=True;Version=3";
SQLiteConnectionStringBuilder conn = new SQLiteConnectionStringBuilder();
conn.DataSource = dbFileName;
conn.Version = 3;
conn.FailIfMissing = true;
conn.Add("Compress", true);
return conn.ConnectionString;
}
示例8: ProfilingDataSQLiteProvider
/// <summary>
/// Creates a new SQLite profiling data provider and opens a database stored in a file.
/// </summary>
public ProfilingDataSQLiteProvider(string fileName)
{
this.nameMappingCache = new Dictionary<int, NameMapping>();
SQLiteConnectionStringBuilder conn = new SQLiteConnectionStringBuilder();
conn.Add("Data Source", fileName);
this.connection = new SQLiteConnection(conn.ConnectionString);
this.connection.Open();
CheckFileVersion();
}
示例9: GetConnectionString
private static string GetConnectionString(string dbPath)
{
var connectionBuilder = new SQLiteConnectionStringBuilder();
connectionBuilder.DataSource = dbPath;
connectionBuilder.CacheSize = (int)-10.Megabytes();
connectionBuilder.DateTimeKind = DateTimeKind.Utc;
connectionBuilder.JournalMode = OsInfo.IsOsx ? SQLiteJournalModeEnum.Truncate : SQLiteJournalModeEnum.Wal;
connectionBuilder.Pooling = true;
connectionBuilder.Version = 3;
if (OsInfo.IsOsx)
{
connectionBuilder.Add("Full FSync", true);
}
return connectionBuilder.ConnectionString;
}
示例10: UsageDataSessionWriter
/// <summary>
/// Opens/Creates the database and starts writing a new session to it.
/// </summary>
/// <exception cref="IncompatibleDatabaseException">The database version is not compatible with this
/// version of the AnalyticsSessionWriter.</exception>
public UsageDataSessionWriter(string databaseFileName)
{
SQLiteConnectionStringBuilder conn = new SQLiteConnectionStringBuilder();
conn.Add("Data Source", databaseFileName);
connection = new SQLiteConnection(conn.ConnectionString);
connection.Open();
try {
InitializeTables();
StartSession();
} catch {
connection.Close();
throw;
}
timer = new Timer(OnTimer, 0, TimeSpan.FromSeconds(60), TimeSpan.FromSeconds(60));
}
示例11: ProfilingDataSQLiteProvider
/// <summary>
/// Creates a new SQLite profiling data provider and opens a database stored in a file.
/// </summary>
ProfilingDataSQLiteProvider(string fileName, bool allowUpgrade)
{
this.nameMappingCache = new Dictionary<int, NameMapping>();
SQLiteConnectionStringBuilder conn = new SQLiteConnectionStringBuilder();
conn.Add("Data Source", fileName);
this.connection = new SQLiteConnection(conn.ConnectionString);
try {
this.connection.Open();
CheckFileVersion(allowUpgrade);
} catch {
try {
connection.Dispose();
} catch {
// ignore errors during cleanup, rethrow the first error instead
}
throw;
}
}
示例12: OpenDatabase
private void OpenDatabase()
{
SQLiteConnectionStringBuilder csb = new SQLiteConnectionStringBuilder();
csb.Add("data source", "brainstorm.sqlite");
dbConnection = new SQLiteConnection(csb.ConnectionString);
dbConnection.Open();
}