本文整理汇总了C#中DatabaseVersion.ToString方法的典型用法代码示例。如果您正苦于以下问题:C# DatabaseVersion.ToString方法的具体用法?C# DatabaseVersion.ToString怎么用?C# DatabaseVersion.ToString使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类DatabaseVersion
的用法示例。
在下文中一共展示了DatabaseVersion.ToString方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: LoadDatabaseSchema
public override DatabaseSchema LoadDatabaseSchema(string databaseName, DatabaseVersion version)
{
DatabaseSchema result = new DatabaseSchema();
var connectionString = RepositoryLocation;
using (var connection = new System.Data.SqlClient.SqlConnection(connectionString))
{
connection.Open();
using (var command = connection.CreateCommand())
{
command.CommandText = "DatabaseSchema_Load";
command.CommandType = System.Data.CommandType.StoredProcedure;
command.Parameters.Add(new System.Data.SqlClient.SqlParameter(){
ParameterName = "@databaseName",
SqlDbType = System.Data.SqlDbType.NVarChar,
Direction = System.Data.ParameterDirection.Input,
Value = databaseName
});
command.Parameters.Add(new System.Data.SqlClient.SqlParameter(){
ParameterName = "@databaseVersion",
SqlDbType = System.Data.SqlDbType.NVarChar,
Direction = System.Data.ParameterDirection.Input,
Value = version.ToString()
});
command.Parameters.Add(new System.Data.SqlClient.SqlParameter(){
ParameterName = "@ReturnValue",
Direction = System.Data.ParameterDirection.ReturnValue,
});
using(var reader = command.ExecuteReader())
{
while (reader.Read())
{
result.Name = reader["Name"].ToString();
result.Version = new DatabaseVersion(reader["Version"].ToString());
}
reader.NextResult();
while (reader.Read())
{
Materialize(result, reader);
}
}
}
}
return result;
}
示例2: LoadDatabaseSchema
public override DatabaseSchema LoadDatabaseSchema(string databaseName, DatabaseVersion version)
{
DatabaseSchema schema = null;
var dbDir = RepositoryLocation + @"\" + databaseName;
if (!Directory.Exists(dbDir))
{
return schema;
}
var versionDir = dbDir + @"\" + version.ToString();
if (!Directory.Exists(versionDir))
{
return schema;
}
var repoDir = versionDir;
var dbInfo = Directory.GetFiles(repoDir, "DatabaseSchema.info").FirstOrDefault();
var sprocDir = Directory.GetDirectories(repoDir, "StoredProcedures").FirstOrDefault();
var dbSerializer = new XmlSerializer(typeof(DatabaseSchema));
using (var fileStream = new FileStream(dbInfo,FileMode.Open))
{
schema = (DatabaseSchema) dbSerializer.Deserialize(fileStream);
}
schema.StoredProcedures = new List<StoredProcedure>();
var sprocSerializer = new XmlSerializer(typeof (StoredProcedure));
foreach(var sprocInfo in Directory.GetFiles(sprocDir,"*.info"))
{
using (var fileStream = new FileStream(sprocInfo,FileMode.Open))
{
var sproc = (StoredProcedure) sprocSerializer.Deserialize(fileStream);
schema.StoredProcedures.Add(sproc);
}
}
return schema;
}
示例3: ensureDatabaseIsSetup
private void ensureDatabaseIsSetup(DatabaseVersion version)
{
if (databaseFiles.ContainsKey(version))
return;
string dbName = databaseBaseName + "_" + version;
string connectionString = ConfigurationManager.ConnectionStrings[version.ToString()].ConnectionString;
// Create paths to datafiles
var dataFiles = new string[GetNumberOfFiles()];
for (int i = 0; i < GetNumberOfFiles(); i++)
dataFiles[i] = Path.Combine(DataFileRootPath, dbName + "_" + i + "." + (i == 0 ? "mdf" : "ndf"));
databaseFiles[version] = dataFiles;
// Create CREATE DATABASE statement
string createStatement = @"
CREATE DATABASE
[<DBNAME>]
ON PRIMARY ";
// Add data files, trim trailing comma
for (int i = 0; i < dataFiles.Length; i++)
createStatement += @"
(
NAME = N'<DBNAME>_" + i + @"',
FILENAME = N'" + dataFiles[i] + @"',
SIZE = 3MB,
FILEGROWTH = 1MB
),";
createStatement = createStatement.Substring(0, createStatement.Length - 1);
// Finish off CREATE statement
createStatement += @"
LOG ON
(
NAME = N'<DBNAME>_log',
FILENAME = N'<TEMPPATH>\<DBNAME>.ldf',
SIZE = 1MB,
FILEGROWTH = 1MB
)";
// Connect to DB and CREATE database
using (var conn = new SqlConnection(connectionString))
{
conn.Open();
var cmd = new SqlCommand(replaceDBParameters(createStatement, dbName), conn);
cmd.ExecuteNonQuery();
cmd.CommandText = replaceDBParameters("ALTER DATABASE [<DBNAME>] SET PAGE_VERIFY CHECKSUM", dbName);
cmd.ExecuteNonQuery();
try
{
using (var userConn = new SqlConnection(connectionString + ";Initial Catalog=" + dbName))
{
userConn.Open();
try
{
RunSetupQueries(userConn, version);
}
finally
{
new SqlCommand("USE master", userConn).ExecuteNonQuery();
}
}
}
finally
{
cmd.CommandText = replaceDBParameters(@"
ALTER DATABASE [<DBNAME>] SET SINGLE_USER WITH ROLLBACK IMMEDIATE;
EXEC master.dbo.sp_detach_db @dbname = N'<DBNAME>'", dbName);
cmd.ExecuteNonQuery();
}
}
}