当前位置: 首页>>代码示例>>C#>>正文


C# DatabaseVersion.ToString方法代码示例

本文整理汇总了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;
        }
开发者ID:apalmer,项目名称:DatabaseUtility,代码行数:49,代码来源:DbDatabaseSchemaRepository.cs

示例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;
        }
开发者ID:apalmer,项目名称:DatabaseUtility,代码行数:39,代码来源:DirectoryDatabaseSchemaRepository.cs

示例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();
                }
            }
        }
开发者ID:Robin--,项目名称:OrcaMDF,代码行数:79,代码来源:SqlServerSystemTestBase.cs


注:本文中的DatabaseVersion.ToString方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。