CryptographicException附加信息:系统找不到指定的文件

时间:2015-07-06 15:46:45

标签: c# azure cryptography azure-sql-database x509

我正在尝试连接到azure以创建一个sql数据库dinamically

这是我的代码

 public static class SqlAzureDbHelper
    {
        public static string subscriptionId = SettingsHelper.AzureSubscriptionId;
        public static string base64EncodedCertificate = SettingsHelper.AzureSubscriptionManagementCertificate;

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

        public static void CreateDatabase(string companyName,string nit)
        {
            SqlManagementClient client = new SqlManagementClient(getCredentials());
            //Server Name is your SQL Azure DataBase server name, for example:da0dt6hrt6 
            client.Databases.Create(SettingsHelper.AzureSqlServer, new Microsoft.WindowsAzure.Management.Sql.Models.DatabaseCreateParameters()
            {
                Name = companyName+"-"+nit,
                MaximumDatabaseSizeInGB = 1,
                CollationName = "SQL_Latin1_General_CP1_CI_AS",
                Edition = "Web"
            });

        }
    }

这是我的堆栈跟踪

 at System.Security.Cryptography.CryptographicException.ThrowCryptographicException(Int32 hr)
   at System.Security.Cryptography.X509Certificates.X509Utils._LoadCertFromBlob(Byte[] rawData, IntPtr password, UInt32 dwFlags, Boolean persistKeySet, SafeCertContextHandle& pCertCtx)
   at System.Security.Cryptography.X509Certificates.X509Certificate.LoadCertificateFromBlob(Byte[] rawData, Object password, X509KeyStorageFlags keyStorageFlags)
   at System.Security.Cryptography.X509Certificates.X509Certificate..ctor(Byte[] data)
   at System.Security.Cryptography.X509Certificates.X509Certificate2..ctor(Byte[] rawData)
   at Inspinia_MVC5.Data.SqlAzureDbHelper.getCredentials() in C:\Proyectos\SaasAppDemo1\Main\SaasAppDemo1\SaasAppDemo1\Data\SqlAzureDbHelper.cs:line 19
   at Inspinia_MVC5.Data.SqlAzureDbHelper.CreateDatabase(String companyName, String nit) in C:\Proyectos\SaasAppDemo1\Main\SaasAppDemo1\SaasAppDemo1\Data\SqlAzureDbHelper.cs:line 24
   at Inspinia_MVC5.Areas.GlobalAdmin.Controllers.EmpresasController.Create(Empresa empresa) in C:\Proyectos\SaasAppDemo1\Main\SaasAppDemo1\SaasAppDemo1\Areas\GlobalAdmin\Controllers\EmpresasController.cs:line 86
   at lambda_method(Closure , ControllerBase , Object[] )
   at System.Web.Mvc.ActionMethodDispatcher.Execute(ControllerBase controller, Object[] parameters)
   at System.Web.Mvc.ReflectedActionDescriptor.Execute(ControllerContext controllerContext, IDictionary`2 parameters)
   at System.Web.Mvc.ControllerActionInvoker.InvokeActionMethod(ControllerContext controllerContext, ActionDescriptor actionDescriptor, IDictionary`2 parameters)
   at System.Web.Mvc.Async.AsyncControllerActionInvoker.<BeginInvokeSynchronousActionMethod>b__39(IAsyncResult asyncResult, ActionInvocation innerInvokeState)
   at System.Web.Mvc.Async.AsyncResultWrapper.WrappedAsyncResult`2.CallEndDelegate(IAsyncResult asyncResult)
   at System.Web.Mvc.Async.AsyncResultWrapper.WrappedAsyncResultBase`1.End()
   at System.Web.Mvc.Async.AsyncControllerActionInvoker.EndInvokeActionMethod(IAsyncResult asyncResult)
   at System.Web.Mvc.Async.AsyncControllerActionInvoker.AsyncInvocationWithFilters.<InvokeActionMethodFilterAsynchronouslyRecursive>b__3d()
   at System.Web.Mvc.Async.AsyncControllerActionInvoker.AsyncInvocationWithFilters.<>c__DisplayClass46.<InvokeActionMethodFilterAsynchronouslyRecursive>b__3f()

0 个答案:

没有答案