本文整理汇总了C#中DataContext.DatabaseExists方法的典型用法代码示例。如果您正苦于以下问题:C# DataContext.DatabaseExists方法的具体用法?C# DataContext.DatabaseExists怎么用?C# DataContext.DatabaseExists使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类DataContext
的用法示例。
在下文中一共展示了DataContext.DatabaseExists方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Connect
public static void Connect(string connectionString, out string setConnectionString)
{
using (var db = new DataContext(connectionString))
{
if (!db.DatabaseExists())
throw new RepositoryException(string.Format("База данных '{0}' отсутствует на сервере '{1}'",
db.Connection.Database,
db.Connection.DataSource));
setConnectionString = connectionString;
}
}
示例2: CreateUpdate
/// <summary>
/// 创建数据库并更新版本信息
/// </summary>
/// <param name="context"></param>
public static void CreateUpdate(DataContext context)
{
if (!context.DatabaseExists())
{
Create(context);
}
else
{
Update(context);
}
}
示例3: dataContextByName
public static DataContext dataContextByName(string db)
{
string conn = Config.CONNSTR(db);
DataContext dc =new DataContext(conn);
if (!dc.DatabaseExists()) {
dc.CreateDatabase();
}
return dc;
}
示例4: ReCreateDatabaseFromAttributeMapping
protected void ReCreateDatabaseFromAttributeMapping(DataContext ctx)
{
bool success = false;
bool retry = false;
int retries = 0;
do
{
try
{
using (ctx)
{
CloseAllOpenConnections(ctx);
ctx.Log = new StringWriter();
if (ctx.DatabaseExists())
{
//drop all connections by disabling multi-user (and immediatly abort all current transactions)
ctx.ExecuteCommand("ALTER DATABASE " + _databaseName + " SET SINGLE_USER WITH ROLLBACK IMMEDIATE");
ctx.DeleteDatabase();
}
try
{
ctx.CreateDatabase();
}
catch (Exception e)
{
Debug.WriteLine(e);
Debug.WriteLine(ctx.Log);
throw;
}
//re-enable multi-user (again)
ctx.ExecuteCommand("ALTER DATABASE " + _databaseName + " SET MULTI_USER");
success = true;
}
}
catch (SqlException e)
{
retry = false;
if (e.Message.IndexOf("was deadlocked on lock resources with another process and has been chosen as the deadlock victim") > 0)
{
retry = true;
retries++;
}
}
} while (success == false && (retry && retries < 3));
}
示例5: ClearTpDB
private static void ClearTpDB(DataContext tpDatabaseDataContext)
{
if (!tpDatabaseDataContext.DatabaseExists())
{
tpDatabaseDataContext.CreateDatabase();
tpDatabaseDataContext.SubmitChanges();
}
else
{
tpDatabaseDataContext.ExecuteCommand("delete from Project");
tpDatabaseDataContext.ExecuteCommand("delete from TpUser");
tpDatabaseDataContext.ExecuteCommand("delete from General");
tpDatabaseDataContext.ExecuteCommand("delete from MessageUid");
tpDatabaseDataContext.ExecuteCommand("delete from PluginProfile");
tpDatabaseDataContext.ExecuteCommand("delete from Revision");
}
}
示例6: Run
/// <summary>Run operation.</summary>
public void Run(enumRun mode)
{
// Validate application configuration file.
if(String.IsNullOrEmpty(_paramGetStatusesSince) || String.IsNullOrEmpty(_paramGetStatusesCount)) {
EventLog.WriteEntry(logName, "Application Error: Missing values from configuration file.", EventLogEntryType.Error);
return;
}
// Init database.
_dbContext = new BaseDataContext(_dbConnectionString);
if(!_dbContext.DatabaseExists()) {
_dbContext.CreateDatabase();
}
// Create (INSERT) default data to database.
if(mode == enumRun.LoadData) {
CreateStatusesDefault();
Console.WriteLine("\nLoaded data successfully.");
} else if(mode == enumRun.LoadData) {
Console.WriteLine("\nCannot load data because it exists. If you want to try again, then you must either drop the database or delete all the records.");
}
// Iterate and process users.
TwitterStatus userStatus = null;
string userUrlGetStatuses = String.Empty;
var userIds = _paramGetStatusesUserValue.RemoveWhitespaces().Split(new char[] {','}, StringSplitOptions.RemoveEmptyEntries);
for(int i = 0;i < userIds.Length;i += 1) {
userUrlGetStatuses = String.Empty;
// Get (SELECT) status, most recent.
userStatus = GetStatusLatest(userIds[i]);
// Validate status.
if(userStatus != null) {
userUrlGetStatuses = _urlGetStatuses.AppendQueryString(String.Concat(_paramGetStatusesSince, "=", userStatus.Id));
} else {
userUrlGetStatuses = _urlGetStatuses.AppendQueryString(String.Concat(_paramGetStatusesCount, "=", _paramDataStatusesHistory));
}
// Create (INSERT) statue from XML.
CreateStatus(userUrlGetStatuses.AppendQueryString(String.Concat(_paramGetStatusesUser, "=", userIds[i])));
}
// Remove (DELETE) extra statuses based on maximum length.
RemoveStatuses(_paramDataStatusesHistory);
// Submit data changes.
_dbContext.SubmitChanges();
}
示例7: Run
/// <summary>Run operation.</summary>
public void Run(enumRun mode)
{
// Init database.
_dbContext = new BaseDataContext(_dbConnectionString);
if(!_dbContext.DatabaseExists()) {
_dbContext.CreateDatabase();
}
// Get (SELECT) locations from database.
var locations = GetLocations();
int locationsLength = locations.Count();
// Create (INSERT) default data to database.
if(mode == enumRun.LoadData && (locations == null || locationsLength <= 0)) {
locations = CreateLocationsDefault();
Console.WriteLine("\nLoaded data successfully.");
} else if(mode == enumRun.LoadData) {
Console.WriteLine("\nCannot load data because it exists. If you want to try again, then you must either drop the database or delete all the records.");
}
// Process condition from each location.
for(int i = 0;i < locationsLength;i += 1) {
// Create (INSERT) condition from XML.
CreateConditions(locations[i]);
// Remove (DELETE) extra conditions based on maximum length.
RemoveConditions(locations[i], _paramConditionHistory);
}
// Remove (DELETE) extra conditions based on maximum length.
RemoveConditions(_paramConditionHistory);
// Submit data changes.
_dbContext.SubmitChanges();
}