本文整理汇总了C#中PetaPoco.Database.OpenSharedConnection方法的典型用法代码示例。如果您正苦于以下问题:C# Database.OpenSharedConnection方法的具体用法?C# Database.OpenSharedConnection怎么用?C# Database.OpenSharedConnection使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类PetaPoco.Database
的用法示例。
在下文中一共展示了Database.OpenSharedConnection方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: CreateDB
public void CreateDB()
{
db = new Database(_connectionStringName);
db.OpenSharedConnection(); // <-- Wow, this is crucial to getting SqlCE to perform.
db.Execute(Utils.LoadTextResource(string.Format("PetaPoco.Tests.{0}_init.sql", _connectionStringName)));
}
示例2: HaveDb
private static Database HaveDb()
{
string message = "";
if ((UseFileSystem == false) && (_db == null))
{
InitDb();
string rootPath = IOManager.RootDirectory;
string dataPath = IOManager.Combine(rootPath, "App_Data");
if (ConnectionString.Contains("|DataDirectory|") == true)
{
ConnectionString = ConnectionString.Replace("|DataDirectory|", dataPath + IOManager.DirectorySeparator);
}
bool checkDb = true;
if ((ProviderNameFactory.ToUpper() == AppCommon.SQLiteProviderNameFactory.ToUpper()) && (ConnectionString.Contains("AutoFill") == false))
{
string sqliteDbPath = "";
int idxOfSemiColon =ConnectionString.IndexOf(";");
if (idxOfSemiColon > -1)
{
int idxOfEqual = ConnectionString.IndexOf("=");
sqliteDbPath = ConnectionString.Substring(idxOfEqual + 1, idxOfSemiColon - idxOfEqual -1);
}
else
{
sqliteDbPath = ConnectionString.Substring(ConnectionString.IndexOf("=") + 1);
}
if (IOManager.CachedFileExists(sqliteDbPath, true, true) ==false)
{
checkDb =false ;
LogManager.Log(LogLevel.Critical, "DataSource-HaveDb", "Sqlite Db Not found in Path [" + sqliteDbPath + "]");
}
}
if (checkDb == true)
{
_db = DataStore.HaveDb(ConnectionString, ProviderNameFactory, out message);
if (_db != null) {
_db.OnDBException -= new PetaPoco.DBException(OnDBException);
_db.OnDBException += new PetaPoco.DBException(OnDBException);
if (ProviderNameFactory == AppCommon.SQLiteProviderNameFactory)
{
_db.KeepConnectionAlive = true;
UseSharedConnection = true;
//_db.Execute("PRAGMA journal_mode=WAL;");
//_db.Execute("PRAGMA journal_mode=DELETE;");
}
if (ProviderNameFactory == AppCommon.MySQLProviderNameFactory)
{
_db.KeepConnectionAlive = false;
UseSharedConnection = false;
//_db.Execute("set wait_timeout=28800");
//_db.Execute("set interactive_timeout=28800");
//_db.Execute("set net_write_timeout=999");
}
if (UseSharedConnection == true)
{
_db.OpenSharedConnection();
}
}
}
}
if (_db == null) {
if (UseFileSystem ==false)
{
LogManager.Log(LogLevel.Critical, "Priya.InfoList.DataSource-HaveDb", "Have Db is false for " + DbName + "[" + message + "]");
}
else
{
LogManager.Log(LogLevel.Critical, "Priya.InfoList.DataSource-HaveDb", "Have Db is false for " + DbName + ". Use FileSystem is true");
}
}
return _db;
}