本文整理汇总了C#中DatabaseType.ToString方法的典型用法代码示例。如果您正苦于以下问题:C# DatabaseType.ToString方法的具体用法?C# DatabaseType.ToString怎么用?C# DatabaseType.ToString使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类DatabaseType
的用法示例。
在下文中一共展示了DatabaseType.ToString方法的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: GetMigration
private static string GetMigration(DatabaseType type, int version)
{
string resourceName = string.Format("Engine.DBMigrations.{0}.{1}.sql", type.ToString(), version);
Stream resourceStream = Assembly.GetExecutingAssembly().GetManifestResourceStream(resourceName);
if (resourceStream == null)
return null;
using (StreamReader reader = new StreamReader(resourceStream))
{
return reader.ReadToEnd();
}
}
示例2: CreateDatabaseInstance
public static IData.IDatabase CreateDatabaseInstance(DatabaseType databaseType)
{
string dllName = string.Empty;
if (databaseType == DatabaseType.SqlServer2000
|| databaseType == DatabaseType.SqlServer2005
|| databaseType == DatabaseType.SqlServer2008)
{
dllName = "SqlServer";
}
else
{
dllName = databaseType.ToString();
}
return (IData.IDatabase)CreateInstance(dllName, "DataBase");
}
示例3: GetMigrationVersions
private static List<int> GetMigrationVersions(DatabaseType type)
{
Assembly ass = Assembly.GetExecutingAssembly();
string[] resources = ass.GetManifestResourceNames();
string resourcePrefix = string.Format("Engine.DBMigrations.{0}.", type.ToString());
List<int> migrationNames = new List<int>();
foreach (string resourceName in resources)
{
if (resourceName.StartsWith(resourcePrefix))
{
string[] resourceNameBits = resourceName.Split('.');
migrationNames.Add(int.Parse(resourceNameBits[resourceNameBits.Length - 2])); // Lose the file extension
}
}
return migrationNames;
}
示例4: CreateDbProvider
private static DbProvider CreateDbProvider(DatabaseType databaseType, string connectionString)
{
string databaseTypeName = databaseType.ToString();
ConnectionStringSettings connectionStringSetting = ConfigurationManager.ConnectionStrings[databaseTypeName];
string providerName = connectionStringSetting.ProviderName;
string[] assemblyAndClassType = providerName.Split(new char[] { ',' });
if (assemblyAndClassType.Length.Equals(2))
{
return DbProviderFactory.CreateDbProvider(assemblyAndClassType[1].Trim(),
assemblyAndClassType[0].Trim(),
connectionString);
}
else
{
return DbProviderFactory.CreateDbProvider(string.Empty, providerName, connectionString);
}
}
示例5: SetConnectionString
/// <summary>
/// Sets a connection string for a website.
/// </summary>
/// <param name="name">Name of the website.</param>
/// <param name="key">Connection string key.</param>
/// <param name="value">Value for the connection string.</param>
/// <param name="connectionStringType">Type of connection string.</param>
public void SetConnectionString(string name, string key, string value, DatabaseType connectionStringType)
{
Site website = GetWebsite(name);
var update = WebsiteManagementClient.WebSites.GetConfiguration(website.WebSpace, website.Name).ToUpdate();
var csToUpdate = update.ConnectionStrings.FirstOrDefault(cs => cs.Name.Equals(key, StringComparison.OrdinalIgnoreCase));
if (csToUpdate == null)
{
csToUpdate = new WebSiteUpdateConfigurationParameters.ConnectionStringInfo
{
ConnectionString = value,
Name = key,
Type = connectionStringType.ToString()
};
update.ConnectionStrings.Add(csToUpdate);
}
else
{
csToUpdate.ConnectionString = value;
csToUpdate.Type = connectionStringType.ToString();
}
WebsiteManagementClient.WebSites.UpdateConfiguration(website.WebSpace, website.Name, update);
}
示例6: UnsupportedDatabaseTypeException
/// <summary>
/// Initializes a new instance of the <see cref="UnsupportedDatabaseTypeException"/> class.
/// </summary>
/// <param name="type">The type.</param>
public UnsupportedDatabaseTypeException(DatabaseType type)
: base(string.Format(Resources.EXCEPTION_UNSUPPORTED_DATABASETYPE, type.ToString()))
{
}
示例7: MakeConnectionString
/// <summary>
/// Assembles a OLEDB connection string that can be used to get a database connection.
/// All the parameters are optional for the purposes of this method, although obviously
/// it would be possible to create a useless connection string if you leave out important
/// parameters.
/// </summary>
/// <param name="providerType">Database type, will be used to determine provider string.</param>
/// <param name="server">Server name that is hosting the database</param>
/// <param name="database">Database name, if necessary to specify</param>
/// <param name="user">User name to use when accessing the db</param>
/// <param name="password">Password for above user.</param>
/// <param name="connectionTimeout">How long to wait before giving up on a command, in seconds.</param>
/// <returns>A connection string that can be used to create OleDbConnections.</returns>
public static string MakeConnectionString(DatabaseType providerType, string server,
string database, string user, string password, int? connectionTimeout)
{
string provider;
if (DatabaseType.SQLSERVER == providerType)
{
provider = "SQLOLEDB";
}
else if (DatabaseType.ORACLE == providerType)
{
provider = "OraOLEDB.Oracle.1";
// Oracle doesn't want this parameter.
database = null;
}
else if (DatabaseType.ACCESS == providerType)
{
provider = "Microsoft.Jet.OLEDB.4.0";
}
else
{
throw new ArgumentException(providerType + " is an unsupported type of database.", providerType.ToString());
}
return MakeConnectionString(provider, server, database, user, password, connectionTimeout);
}
示例8: WithDatabaseType
/// <summary>
/// Executes expression where it matches any of the provided database types
/// </summary>
/// <param name="type">The type</param>
/// <returns>An expression that can process the requested type</returns>
public IExecuteExpressionRoot WithDatabaseType(DatabaseType type)
{
if ( _context.QuerySchema is IMigrationProcessor)
{
var name = _context.QuerySchema.GetType().Name;
if (!string.IsNullOrEmpty(name))
name = name.Replace("Processor", "");
var types = type.ToString()
.Split(new[] {", "}, StringSplitOptions.None);
var match = types.FirstOrDefault(t => t == name || t.StartsWith(name));
if ( match != null)
return this;
}
return new NullExecuteExpression();
}
示例9: Remove
/// <summary>
/// 从指定文件中删除数据库连接信息。
/// </summary>
/// <param name="type">数据库类型</param>
/// <param name="databaseName">数据库名称</param>
/// <param name="file">文件路径</param>
public static void Remove(DatabaseType type, string databaseName, string file = null)
{
var xdoument = CreateXDocument(file);
if (xdoument != null)
{
var element = (from x in xdoument.Descendants("database")
where
x.Attribute("type").Value == type.ToString() && x.Attribute("name").Value == databaseName
select x).FirstOrDefault();
if (element != null)
{
element.Remove();
xdoument.Save(GetFullFilePath(file));
}
}
}
示例10: ExportServerDatabaseToEmbedded
private void ExportServerDatabaseToEmbedded(DatabaseType databaseType, DatabaseMenuCommandParameters parameters)
{
string filter = DataConnectionHelper.GetSqlCeFileFilter();
Scope scope = Scope.SchemaData;
if (databaseType == DatabaseType.SQLite)
{
filter = DataConnectionHelper.GetSqliteFileFilter();
scope = Scope.SchemaDataSQLite;
}
Debug.Assert(databaseType == DatabaseType.SQLite || databaseType == DatabaseType.SQLCE40, "Unexpected database type");
try
{
string connectionString = parameters.DatabaseInfo != null
? parameters.DatabaseInfo.ConnectionString :
DataConnectionHelper.PromptForConnectionString(package);
if (!string.IsNullOrEmpty(connectionString))
{
PickTablesDialog ptd = new PickTablesDialog();
int totalCount = 0;
using (IRepository repository = Helpers.DataConnectionHelper.CreateRepository(new DatabaseInfo
{ ConnectionString = connectionString, DatabaseType = DatabaseType.SQLServer }))
{
ptd.Tables = repository.GetAllTableNamesForExclusion();
totalCount = ptd.Tables.Count;
}
bool? res = ptd.ShowModal();
if (res.HasValue && res.Value == true && (ptd.Tables.Count < totalCount))
{
string dbName;
string dbConnectionString = null;
SaveFileDialog fd = new SaveFileDialog();
fd.Title = "Export as";
fd.Filter = filter;
fd.OverwritePrompt = true;
fd.ValidateNames = true;
bool? result = fd.ShowDialog();
if (result.HasValue && result.Value == true)
{
dbName = fd.FileName;
try
{
if (databaseType == DatabaseType.SQLCE40)
{
package.SetStatus("Creating SQL Server Compact database...");
SqlCeScripting.SqlCeHelper4 helper = new SqlCeScripting.SqlCeHelper4();
dbConnectionString = string.Format("Data Source={0};Max Database Size=4091", dbName);
if (System.IO.File.Exists(dbName))
File.Delete(dbName);
helper.CreateDatabase(dbConnectionString);
}
if (databaseType == DatabaseType.SQLite)
{
package.SetStatus("Creating SQLite database...");
var helper = new SqliteHelper();
dbConnectionString = string.Format("Data Source={0};", dbName);
if (System.IO.File.Exists(dbName))
File.Delete(dbName);
helper.CreateDatabase(dbConnectionString);
}
BackgroundWorker bw = new BackgroundWorker();
List<object> workerParameters = new List<object>();
workerParameters.Add(dbConnectionString);
workerParameters.Add(connectionString);
workerParameters.Add(ptd.Tables);
workerParameters.Add(databaseType.ToString());
workerParameters.Add(scope.ToString());
bw.DoWork += new DoWorkEventHandler(bw_DoWork);
bw.RunWorkerCompleted += (s, ea) =>
{
try
{
if (ea.Error != null)
{
Helpers.DataConnectionHelper.SendError(ea.Error, databaseType, false);
}
Helpers.DataConnectionHelper.LogUsage("DatabasesExportFromServer");
}
finally
{
bw.Dispose();
}
};
bw.RunWorkerAsync(workerParameters);
}
catch (Exception ex)
{
Helpers.DataConnectionHelper.SendError(ex, databaseType, false);
}
}
}
}
}
catch (Exception ex)
{
Helpers.DataConnectionHelper.SendError(ex, DatabaseType.SQLServer);
}
//.........这里部分代码省略.........