1

我在连接到 Windows Azure 管理 API 时遇到困难,我认为这是因为我没有正确的 X509 证书信息。

我正在尝试遵循本教程:https ://code.msdn.microsoft.com/windowsazure/How-to-create-a-Azure-SQL-5157ce03

我尝试创建自己的自签名证书并将其上传到 Azure,然后从证书中复制指纹,但出现以下错误。

这是我的代码:

public class CreateAzureDatabase {

    protected static string subscriptionId = "{xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx}";
    protected static string serverName = "xxxxxxxxxx.database.windows.net";
    public static string base64EncodedCertificate = "xxxxxxxxxxxxxxxxxxxxxxxxxx";

    public void DoDatabase(string newDatabaseName) {

        SqlManagementClient client = new SqlManagementClient(getCredentials());
        //Server Name is your SQL Azure DataBase server name, for example:da0dt6hrt6 
        client.Databases.Create(serverName, new Microsoft.WindowsAzure.Management.Sql.Models.DatabaseCreateParameters() {
            Name = newDatabaseName,
            MaximumDatabaseSizeInGB = 1,
            CollationName = "SQL_Latin1_General_CP1_CI_AS"
        });

        Console.ReadLine(); 
    }
    static SubscriptionCloudCredentials getCredentials() {
        return new CertificateCloudCredentials(subscriptionId, new X509Certificate2(Convert.FromBase64String(base64EncodedCertificate)));
    } 

}

我得到的错误是:CryptographicException

An unhandled exception of type 'System.Security.Cryptography.CryptographicException' occurred in mscorlib.dll

Additional information: Cannot find the requested object.

为什么会发生此错误?

如何为我的 Azure 门户获取正确的 base64EncodedCertificate?

4

0 回答 0