无法在Azure服务器上安装VHD驱动器

时间:2012-04-04 10:27:24

标签: c# azure

请帮帮我。我正在编写以下代码来安装vhd文件。但是我无法安装它。它在本地工作正常,但是当我在azure服务器上部署它时,webrole仍然处于脱机状态。我尝试删除下面的foreach块但是徒劳无功。但当我删除代码“Global.driveLetter = drive.Mount(localCache.MaximumSizeInMegabytes - 20,DriveMountOptions.Force);”角色在服务器上准备好了。但我不能这样做,因为这是安装驱动器的关键声明。

会出现什么问题?

    private static void MountAzureDrive()
    {
        string connectionStringSettingName = "AzureConnectionString";
        string azureDriveContainerName = "azuredrives";
        string azureDrivePageBlobName = Guid.NewGuid().ToString("N").ToLowerInvariant();
        string azureDriveCacheDirName = Path.Combine(Environment.CurrentDirectory, "cache");

        CloudStorageAccount.SetConfigurationSettingPublisher((a, b) =>
        {
            b(RoleEnvironment.GetConfigurationSettingValue(connectionStringSettingName));
        });

        //CloudStorageAccount storageAccount=CloudStorageAccount.FromConfigurationSetting(connectionStringSettingName);
CloudStorageAccount storageAccount=CloudStorageAccount.DevelopmentStorageAccount;

        LocalResource localCache=RoleEnvironment.GetLocalResource("InstanceDriveCache");
        CloudDrive.InitializeCache(localCache.RootPath + "cache", localCache.MaximumSizeInMegabytes);

        // Just checking: make sure the container exists
        CloudBlobClient blobClient = storageAccount.CreateCloudBlobClient();
        blobClient.GetContainerReference("drives").CreateIfNotExist();

        // Create cloud drive
     //WebRole.drive=storageAccount.CreateCloudDrive(blobClient.GetContainerReference("drives").GetPageBlobReference("Test.VHD").Uri.ToString());
        WebRole.drive = storageAccount.CreateCloudDrive("drives/Test.VHD");

        try
        {
            WebRole.drive.CreateIfNotExist(512);
        }
        catch (CloudDriveException ex)
        {
            // handle exception here
            // exception is also thrown if all is well but the drive already exists
        }

        foreach (var d in CloudDrive.GetMountedDrives())
        {
            var mountedDrive = storageAccount.CreateCloudDrive(d.Value.PathAndQuery);
            mountedDrive.Unmount();
        }
        //Global.driveLetter = drive.Mount(25, DriveMountOptions.Force);
        Global.driveLetter = drive.Mount(localCache.MaximumSizeInMegabytes - 20, DriveMountOptions.Force);
    }

提前致谢。

1 个答案:

答案 0 :(得分:1)

也许这说明显而易见,但......当您部署到Windows Azure时,您是否从存储库中更改了存储帐户?您的dev存储模拟器是硬编码的:

CloudStorageAccount storageAccount=CloudStorageAccount.DevelopmentStorageAccount;