我注册了一个Azure帐户,并将一个网站和一个数据库一起部署得非常顺利。
首先我在免费服务上使用它,但在遇到性能问题后,将其升级到共享模型(具有相同的性能)。 “链接资源”数据库是一个网络版数据库。在门户网站中它看起来像这样:
以下代码用于在我的网站的管理部分启用缓存失效:
ConnectionStringSettings Config = ConfigurationManager.ConnectionStrings["MyConnectionString"];
System.Web.Caching.SqlCacheDependencyAdmin.EnableNotifications(Config.ConnectionString);
System.Web.Caching.SqlCacheDependencyAdmin.EnableTableForNotifications(Config.ConnectionString, "MyTable");
它适用于我的本地SqlServer Express,以及我的某个托管服务提供商的实时数据库。仅在Azure上,我得到以下异常:
System.Data.SqlClient.SqlException (0x80131904): Could not find stored procedure 'sp_addrole'.
Cannot find the user 'aspnet_ChangeNotification_ReceiveNotificationsOnlyAccess', because it does not exist or you do not have permission.
at System.Data.SqlClient.SqlConnection.OnError(SqlException exception, Boolean breakConnection, Action`1 wrapCloseInAction)
at System.Data.SqlClient.SqlInternalConnection.OnError(SqlException exception, Boolean breakConnection, Action`1 wrapCloseInAction)
at System.Data.SqlClient.TdsParser.ThrowExceptionAndWarning(TdsParserStateObject stateObj, Boolean callerHasConnectionLock, Boolean asyncClose)
at System.Data.SqlClient.TdsParser.TryRun(RunBehavior runBehavior, SqlCommand cmdHandler, SqlDataReader dataStream, BulkCopySimpleResultSet bulkCopyHandler, TdsParserStateObject stateObj, Boolean& dataReady)
at System.Data.SqlClient.SqlCommand.RunExecuteNonQueryTds(String methodName, Boolean async, Int32 timeout)
at System.Data.SqlClient.SqlCommand.InternalExecuteNonQuery(TaskCompletionSource`1 completion, String methodName, Boolean sendToPipe, Int32 timeout, Boolean asyncWrite)
at System.Data.SqlClient.SqlCommand.ExecuteNonQuery()
at System.Web.Caching.SqlCacheDependencyAdmin.SetupNotifications(Int32 flags, String table, String connectionString)
因此,似乎缺少存储过程和“用户”(?)。我希望网络版默认具有这些功能吗?
如果可用的话,我会选择Express版本,但是我只能从Azure控制面板中选择“Web Edition”和“Business Edition”。
有什么方法可以让它发挥作用吗?
答案 0 :(得分:1)
您正在使用SQL数据库并调用存储过程 sp_addrole 。因为错误反映了此存储过程不可用。
如果查看下面的链接,您会看到SQL数据库中不支持sp_addrole: http://msdn.microsoft.com/en-us/library/windowsazure/ee336237.aspx#sqlazure
The following table lists the security stored procedures that
Windows Azure SQL Database does not support:
sp_addrole sp_dropremotelogin sp_helpuser
所以你真正需要的是首先在SQL数据库上直接完成这样的工作项,而不是直接在你的代码中使用它。