为什么 Azure WebJob 无法连接到 Azure SQL,提示“存储帐户的类型不受支持 'Blob-Only/ZRS'。支持的类型是 'General Purpose'?
Why Azure WebJob cannot connect to Azure SQL saying "Storage account is of unsupported type 'Blob-Only/ZRS'. Supported types are 'General Purpose'?
所以我有一个 Azure Web 应用程序,它是一个 ASP.NET MVC 应用程序 Entity Framework。它使用 Azure SQL 数据库。我需要定期(每天一次)轮询金融市场利率数据并将其插入数据库。我为两个市场利率民意调查创建了两个 WebJobs(一个需要 运行 在市场开盘后,另一个在市场收盘后),并安排它们。
为了测试,我通过 Azure 门户手动触发它们,我在日志中收到以下错误:
[08/25/2018 22:28:43 > a6e3be: ERR ] Unhandled Exception: System.InvalidOperationException: Storage account 'blabla' is of unsupported type 'Blob-Only/ZRS'. Supported types are 'General Purpose'
[08/25/2018 22:28:43 > a6e3be: ERR ] at Microsoft.Azure.WebJobs.Host.Storage.StorageAccountExtensions.AssertTypeOneOf(IStorageAccount account, StorageAccountType[] types)
[08/25/2018 22:28:43 > a6e3be: ERR ] at Microsoft.Azure.WebJobs.Host.Executors.DefaultStorageAccountProvider.<CreateAndValidateAccountAsync>d__24.MoveNext()
[08/25/2018 22:28:43 > a6e3be: ERR ] --- End of stack trace from previous location where exception was thrown ---
[08/25/2018 22:28:43 > a6e3be: ERR ] at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
[08/25/2018 22:28:43 > a6e3be: ERR ] at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
[08/25/2018 22:28:43 > a6e3be: ERR ] at Microsoft.Azure.WebJobs.Host.Executors.DefaultStorageAccountProvider.<TryGetAccountAsync>d__25.MoveNext()
[08/25/2018 22:28:43 > a6e3be: ERR ] --- End of stack trace from previous location where exception was thrown ---
[08/25/2018 22:28:43 > a6e3be: ERR ] at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
[08/25/2018 22:28:43 > a6e3be: ERR ] at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
[08/25/2018 22:28:43 > a6e3be: ERR ] at System.Runtime.CompilerServices.TaskAwaiter.ValidateEnd(Task task)
[08/25/2018 22:28:43 > a6e3be: ERR ] at Microsoft.Azure.WebJobs.Host.Executors.JobHostConfigurationExtensions.<CreateJobHostContextAsync>d__1.MoveNext()
[08/25/2018 22:28:43 > a6e3be: ERR ] --- End of stack trace from previous location where exception was thrown ---
[08/25/2018 22:28:43 > a6e3be: ERR ] at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
[08/25/2018 22:28:43 > a6e3be: ERR ] at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
[08/25/2018 22:28:43 > a6e3be: ERR ] at Microsoft.Azure.WebJobs.JobHost.<InitializeHostAsync>d__44.MoveNext()
[08/25/2018 22:28:43 > a6e3be: ERR ] --- End of stack trace from previous location where exception was thrown ---
[08/25/2018 22:28:43 > a6e3be: ERR ] at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
[08/25/2018 22:28:43 > a6e3be: ERR ] at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
[08/25/2018 22:28:43 > a6e3be: ERR ] at Microsoft.Azure.WebJobs.JobHost.<CallAsyncCore>d__37.MoveNext()
[08/25/2018 22:28:43 > a6e3be: ERR ] --- End of stack trace from previous location where exception was thrown ---
[08/25/2018 22:28:43 > a6e3be: ERR ] at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
[08/25/2018 22:28:43 > a6e3be: ERR ] at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
[08/25/2018 22:28:43 > a6e3be: ERR ] at Microsoft.Azure.WebJobs.JobHost.Call(MethodInfo method)
[08/25/2018 22:28:43 > a6e3be: ERR ] at MarketRatePreviousCloseWebJob.Program.Main() in C:\Users\Csaba\Documents\BlablaSrc\MarketRatePreviousCloseWebJob\Program.cs:line 20
[08/25/2018 22:28:43 > a6e3be: SYS INFO] Status changed to Failed
[08/25/2018 22:28:43 > a6e3be: SYS ERR ] Job failed due to exit code -532462766
我无法理解这一点。 SQL Azure 数据库有点普通,一些 table 有 blob 列,但 MarketRates table 没有。
尝试访问数据库的代码:
string connectionString = "Copy of the the Azure SQL connection string";
SqlConnection sqlConnection = new SqlConnection(connectionString);
string selectStatement = "SELECT MAX(Id) FROM BlaBla.dbo.MarketRates";
SqlCommand selectCmd = new SqlCommand(selectStatement, sqlConnection);
sqlConnection.Open();
var id = (int)selectCmd.ExecuteScalar();
sqlConnection.Close();
string insertStatement = "INSERT INTO BlaBla.dbo.MarketRates(Id, Type, Rate, Date) " +
"VALUES(@Id, @Type, @Rate, @Date)";
SqlCommand insertCmd = new SqlCommand(insertStatement, sqlConnection);
var now = DateTime.Now;
insertCmd.Parameters.Add("@Id", SqlDbType.Int);
insertCmd.Parameters.Add("@Type", SqlDbType.VarChar, 64);
insertCmd.Parameters.Add("@Rate", SqlDbType.Float);
insertCmd.Parameters.Add("@Date", SqlDbType.DateTime);
insertCmd.Parameters["@Id"].Value = id + 1;
insertCmd.Parameters["@Type"].Value = rateType;
insertCmd.Parameters["@Rate"].Value = rate;
insertCmd.Parameters["@Date"].Value = now.Date;
sqlConnection.Open();
insertCmd.ExecuteNonQuery();
sqlConnection.Close();
"Storage account is of unsupported type 'Blob-Only/ZRS'. Supported types are 'General Purpose'?
看来您正在使用 blob storage account with Azure webjob. Please have to try to change AzureWebJobsStorageconnection string another General Purpose storage account 连接。
另外,在 WebJob app.settings
的开头用通用存储帐户的连接字符串填充 AzureWebJobsDashboard
和 AzureWebJobsStorage
连接字符串。
所以我有一个 Azure Web 应用程序,它是一个 ASP.NET MVC 应用程序 Entity Framework。它使用 Azure SQL 数据库。我需要定期(每天一次)轮询金融市场利率数据并将其插入数据库。我为两个市场利率民意调查创建了两个 WebJobs(一个需要 运行 在市场开盘后,另一个在市场收盘后),并安排它们。
为了测试,我通过 Azure 门户手动触发它们,我在日志中收到以下错误:
[08/25/2018 22:28:43 > a6e3be: ERR ] Unhandled Exception: System.InvalidOperationException: Storage account 'blabla' is of unsupported type 'Blob-Only/ZRS'. Supported types are 'General Purpose'
[08/25/2018 22:28:43 > a6e3be: ERR ] at Microsoft.Azure.WebJobs.Host.Storage.StorageAccountExtensions.AssertTypeOneOf(IStorageAccount account, StorageAccountType[] types)
[08/25/2018 22:28:43 > a6e3be: ERR ] at Microsoft.Azure.WebJobs.Host.Executors.DefaultStorageAccountProvider.<CreateAndValidateAccountAsync>d__24.MoveNext()
[08/25/2018 22:28:43 > a6e3be: ERR ] --- End of stack trace from previous location where exception was thrown ---
[08/25/2018 22:28:43 > a6e3be: ERR ] at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
[08/25/2018 22:28:43 > a6e3be: ERR ] at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
[08/25/2018 22:28:43 > a6e3be: ERR ] at Microsoft.Azure.WebJobs.Host.Executors.DefaultStorageAccountProvider.<TryGetAccountAsync>d__25.MoveNext()
[08/25/2018 22:28:43 > a6e3be: ERR ] --- End of stack trace from previous location where exception was thrown ---
[08/25/2018 22:28:43 > a6e3be: ERR ] at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
[08/25/2018 22:28:43 > a6e3be: ERR ] at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
[08/25/2018 22:28:43 > a6e3be: ERR ] at System.Runtime.CompilerServices.TaskAwaiter.ValidateEnd(Task task)
[08/25/2018 22:28:43 > a6e3be: ERR ] at Microsoft.Azure.WebJobs.Host.Executors.JobHostConfigurationExtensions.<CreateJobHostContextAsync>d__1.MoveNext()
[08/25/2018 22:28:43 > a6e3be: ERR ] --- End of stack trace from previous location where exception was thrown ---
[08/25/2018 22:28:43 > a6e3be: ERR ] at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
[08/25/2018 22:28:43 > a6e3be: ERR ] at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
[08/25/2018 22:28:43 > a6e3be: ERR ] at Microsoft.Azure.WebJobs.JobHost.<InitializeHostAsync>d__44.MoveNext()
[08/25/2018 22:28:43 > a6e3be: ERR ] --- End of stack trace from previous location where exception was thrown ---
[08/25/2018 22:28:43 > a6e3be: ERR ] at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
[08/25/2018 22:28:43 > a6e3be: ERR ] at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
[08/25/2018 22:28:43 > a6e3be: ERR ] at Microsoft.Azure.WebJobs.JobHost.<CallAsyncCore>d__37.MoveNext()
[08/25/2018 22:28:43 > a6e3be: ERR ] --- End of stack trace from previous location where exception was thrown ---
[08/25/2018 22:28:43 > a6e3be: ERR ] at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
[08/25/2018 22:28:43 > a6e3be: ERR ] at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
[08/25/2018 22:28:43 > a6e3be: ERR ] at Microsoft.Azure.WebJobs.JobHost.Call(MethodInfo method)
[08/25/2018 22:28:43 > a6e3be: ERR ] at MarketRatePreviousCloseWebJob.Program.Main() in C:\Users\Csaba\Documents\BlablaSrc\MarketRatePreviousCloseWebJob\Program.cs:line 20
[08/25/2018 22:28:43 > a6e3be: SYS INFO] Status changed to Failed
[08/25/2018 22:28:43 > a6e3be: SYS ERR ] Job failed due to exit code -532462766
我无法理解这一点。 SQL Azure 数据库有点普通,一些 table 有 blob 列,但 MarketRates table 没有。 尝试访问数据库的代码:
string connectionString = "Copy of the the Azure SQL connection string";
SqlConnection sqlConnection = new SqlConnection(connectionString);
string selectStatement = "SELECT MAX(Id) FROM BlaBla.dbo.MarketRates";
SqlCommand selectCmd = new SqlCommand(selectStatement, sqlConnection);
sqlConnection.Open();
var id = (int)selectCmd.ExecuteScalar();
sqlConnection.Close();
string insertStatement = "INSERT INTO BlaBla.dbo.MarketRates(Id, Type, Rate, Date) " +
"VALUES(@Id, @Type, @Rate, @Date)";
SqlCommand insertCmd = new SqlCommand(insertStatement, sqlConnection);
var now = DateTime.Now;
insertCmd.Parameters.Add("@Id", SqlDbType.Int);
insertCmd.Parameters.Add("@Type", SqlDbType.VarChar, 64);
insertCmd.Parameters.Add("@Rate", SqlDbType.Float);
insertCmd.Parameters.Add("@Date", SqlDbType.DateTime);
insertCmd.Parameters["@Id"].Value = id + 1;
insertCmd.Parameters["@Type"].Value = rateType;
insertCmd.Parameters["@Rate"].Value = rate;
insertCmd.Parameters["@Date"].Value = now.Date;
sqlConnection.Open();
insertCmd.ExecuteNonQuery();
sqlConnection.Close();
"Storage account is of unsupported type 'Blob-Only/ZRS'. Supported types are 'General Purpose'?
看来您正在使用 blob storage account with Azure webjob. Please have to try to change AzureWebJobsStorageconnection string another General Purpose storage account 连接。
另外,在 WebJob app.settings
的开头用通用存储帐户的连接字符串填充 AzureWebJobsDashboard
和 AzureWebJobsStorage
连接字符串。