SqlCacheDependency和ObjectDataSource [英] SqlCacheDependency and ObjectDataSource

查看:79
本文介绍了SqlCacheDependency和ObjectDataSource的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述




我一直在尝试使用ObjectDataSource和SQL

Server 2005来尝试SqlCacheDependency。它在配置最少的情况下运行良好,例如


< asp:ObjectDataSource ID =" odsAccounts" RUNAT = QUOT;服务器" ...

EnableCaching =" true" SqlCacheDependency =" CommandNotification">

....

< / asp:ObjectDataSource>


我的SelectMethod返回一个Typed DataTable(使用DataSet设计器)。我的

问题是:


1.我可以访问缓存的DataTable吗?

2.我可以使缓存无效吗? br />
3.如果我需要在

返回结果之前过滤DataTable,我应该使用什么方法?我想查询缓存的DataTable。


非常感谢

Andrew


PS。使用它的文档是粗略的。有人提到'我需要

来向web.config文件添加一些信息。我没有。文档

表示''ObjectDataSource仅支持轮询''。但是这是什么:

SqlCacheDependency =" CommandNotification"?有点暗示它正在使用

SQL 2005通知?

Hi

I''ve been trying out SqlCacheDependency using the ObjectDataSource and SQL
Server 2005. It all works quite well with the minimum of configuration, e.g.

<asp:ObjectDataSource ID="odsAccounts" runat="server" ...
EnableCaching="true" SqlCacheDependency="CommandNotification">
....
</asp:ObjectDataSource>

My SelectMethod returns a Typed DataTable (using the DataSet designer). My
questions are:

1. Can I access the cached DataTable?
2. Can I invalidate the cache?
3. What approach should I use if I need to filter the DataTable before
returning the results? I''d like to query the cached DataTable.

Many thanks
Andrew

PS. The documentation on using this is sketchy. Some mention''s that I need
to add some infomation to the web.config file. I didn''t. The documentation
says ''The ObjectDataSource supports only polling''. But what is this:
SqlCacheDependency="CommandNotification"? It kind of suggests it''s using the
SQL 2005 notification?

推荐答案

Hello Andrew,


至于ObjectDataSource控件,它的缓存机制由

ObjectDataSourceView类(内部使用)管理,如果你配置了

objectDataSource控制使用缓存,我们无法手动使底层缓存对象无效。

#ObjectDataSource.Selected事件
http://msdn2.microsoft.com/en-us/lib ... rols.objectdat

asource.selected.aspx

对于你的三个问题,这是我的理解:


1.我可以访问缓存的DataTable吗?

==============================

ObjectDataSource控件定义了一个已选择的对象。事件,在这个

事件中,我们可以通过event参数获取返回的数据对象。例如


protected void ObjectDataSource1_Selected(object sender,

ObjectDataSourceStatusEventArgs e)

{

响应。写入(< br />" + e.ReturnValue.GetType());

}

如果objectdatasource控件配置为
使用一个

DataSet + TableAdapter,returnValue是底层数据表。

2.我可以使缓存无效吗?

====== ========================

您无法手动使底层缓存对象无效。

3.如果我需要在

返回结果之前过滤DataTable,我应该使用什么方法?我想查询缓存的DataTable。

============================== br />
你可以考虑使用#1


或更多一般提到的ReturnValue,你可以在原来的周围定义一个自定义包装类

数据访问类(如DataSet + TableAdaper),在这个包装类上你可以定义自定义方法,自定义如何过滤原始数据返回的原始结果集访问类并将其返回到

ObjectDatasource控件。


ObjectDataSource控件具有ObjectCreated控件。事件,我们可以访问创建的类对象(通过TypeName属性配置),因此

你可以调用该对象上的任何自定义方法(你的包装类) 。


#ObjectDataSource.ObjectCreated事件
http://msdn2.microsoft.com/en-us/lib...rols.objectdat

asource.objectcreated .aspx

BTW,对于你提到的以下事项:


=================== ======

PS。使用它的文档是粗略的。有人提到'我需要

来向web.config文件添加一些信息。我没有。文档

表示''ObjectDataSource仅支持轮询''。但是这是什么:

SqlCacheDependency =" CommandNotification"?它有点暗示它使用

SQL 2005通知吗?

============ ==============

SQL 2005本身通过

NotificationService支持查询通知,而SQL Server 2000则不支持吨。当对SQL Server 2000使用ASP.NET

SqlCacheDependency时,我们需要在

web.config中添加配置,ASP.NET将使用后台线程来轮询SQL服务器

2000数据库,以使其工作。


希望这会有所帮助。如果您有任何其他信息,请感觉

免费让我知道。


此致,


Steven Cheng


Microsoft MSDN在线支持主管


================== ================================

通过我的帖子收到通知电子邮件?请参阅
http://msdn.microsoft .com / subscripti ... ult.aspx#notif

ications。


注意:MSDN托管新闻组支持服务是针对非紧急问题

如果社区或微软支持人员在1个工作日内做出初步回复是可以接受的。请注意,每个跟随

的响应可能需要大约2个工作日作为支持

专业人士与您合作可能需要进一步调查才能达到

最有效的分辨率。该产品不适用于需要紧急,实时或基于电话的交互或复杂的b $ b项目分析和转储分析问题的情况。这种性质的问题最好通过联系

Microsoft客户支持服务(CSS)处理
href =http://msdn.microsoft.com/subscriptions/support/default.aspx\"target =_ blank> http://msdn.microsoft.com/subscripti...t/default.aspx


==================================== ==============


此帖子按原样提供。没有保证,也没有授予任何权利。


Hello Andrew,

As for the ObjectDataSource control, its caching mechnism is managed by the
ObjectDataSourceView class (used internally) and if you have configured the
objectDataSource control to use cache , we can not manually invalid the
underlying cached object.
#ObjectDataSource.Selected Event
http://msdn2.microsoft.com/en-us/lib...rols.objectdat
asource.selected.aspx
For your three questions, here are my understanding:

1. Can I access the cached DataTable?
==============================
The ObjectDataSource control has defined a "Selected" event, and in this
event we can get the returned data object through the event argument. e.g.

protected void ObjectDataSource1_Selected(object sender,
ObjectDataSourceStatusEventArgs e)
{
Response.Write("<br/>" + e.ReturnValue.GetType());
}

if the objectdatasource control is configured to use a
DataSet+TableAdapter, the returnValue is underlying datatable.
2. Can I invalidate the cache?
==============================
You can not manually invalid the underlying cached object.
3. What approach should I use if I need to filter the DataTable before
returning the results? I''d like to query the cached DataTable.
==============================
You can consider use the ReturnValue mentioned in #1

or more general, you can define a custom wrapper class around the original
data access class(like the DataSet+TableAdaper), on this wrapper class you
can define custom methods which will customize how to filter the raw
resultset returned by original data access class and return it to
ObjectDatasource control.

The ObjectDataSource control has an "ObjectCreated" event and we can access
the created class object( configured through "TypeName" attribute), thus
you can call any custom methods on that object(your wrapper class).

#ObjectDataSource.ObjectCreated Event
http://msdn2.microsoft.com/en-us/lib...rols.objectdat
asource.objectcreated.aspx
BTW, for the following things you mentioned:

=========================
PS. The documentation on using this is sketchy. Some mention''s that I need
to add some infomation to the web.config file. I didn''t. The documentation
says ''The ObjectDataSource supports only polling''. But what is this:
SqlCacheDependency="CommandNotification"? It kind of suggests it''s using
the
SQL 2005 notification?
==========================

SQL 2005 natively support query notification through the
NotificationService while SQL Server 2000 doesn''t. When using ASP.NET
SqlCacheDependency against SQL Server 2000, we need to add configuration in
web.config, and ASP.NET will use a background thread to poll the SQL Server
2000 database so as to make it work.

Hope this helps. If there is any other information you wonder, please feel
free to let me know.

Sincerely,

Steven Cheng

Microsoft MSDN Online Support Lead

==================================================

Get notification to my posts through email? Please refer to
http://msdn.microsoft.com/subscripti...ult.aspx#notif
ications.

Note: The MSDN Managed Newsgroup support offering is for non-urgent issues
where an initial response from the community or a Microsoft Support
Engineer within 1 business day is acceptable. Please note that each follow
up response may take approximately 2 business days as the support
professional working with you may need further investigation to reach the
most efficient resolution. The offering is not appropriate for situations
that require urgent, real-time or phone-based interactions or complex
project analysis and dump analysis issues. Issues of this nature are best
handled working with a dedicated Microsoft Support Engineer by contacting
Microsoft Customer Support Services (CSS) at
http://msdn.microsoft.com/subscripti...t/default.aspx.

==================================================

This posting is provided "AS IS" with no warranties, and confers no rights.



嗨史蒂文


感谢您提供的信息。
Hi Steven

Thanks for the information.

1.我可以访问缓存的DataTable吗?

================ ==============

ObjectDataSource控件定义了一个已选择的对象。事件,在这个

事件中,我们可以通过event参数获取返回的数据对象。例如


protected void ObjectDataSource1_Selected(object sender,

ObjectDataSourceStatusEventArgs e)

{

响应。写入(< br />" + e.ReturnValue.GetType());

}

如果objectdatasource控件配置为
使用一个

DataSet + TableAdapter,returnValue是底层数据表。
1. Can I access the cached DataTable?
==============================
The ObjectDataSource control has defined a "Selected" event, and in this
event we can get the returned data object through the event argument. e.g.

protected void ObjectDataSource1_Selected(object sender,
ObjectDataSourceStatusEventArgs e)
{
Response.Write("<br/>" + e.ReturnValue.GetType());
}

if the objectdatasource control is configured to use a
DataSet+TableAdapter, the returnValue is underlying datatable.



看起来这些事件(Selected和ObjectCreated)不会随着ObjectDataSource上的设置触发

。如果

缓存为空,它们似乎只会触发。


EnableCaching =" true" SqlCacheDependency =" CommandNotification"

另外,我想使用缓存的DataTable而不改变它,以便

它可供应用程序的其他用户使用。我想知道我是否需要

将我自己的缓存应用于我的Business Object,它返回Typed

DataSet。这样做的问题是我无法从SQL 2005

通知中受益,因此必须手动使缓存无效以进行更新,

在业务中插入和删除对象。


您能就最佳方法提出任何建议吗?


谢谢

Andrew

It looks like these events (Selected and ObjectCreated) don''t fire with the
following settings on the ObjectDataSource. They only seem to fire if the
cache is empty.

EnableCaching="true" SqlCacheDependency="CommandNotification"

Also, I would like to use the cached DataTable without altering it so that
it is available to other users of the application. I''m wondering if I need
to apply my own caching to my Business Object which returns the Typed
DataSet. The problem with this is that I can''t benefit from the SQL 2005
notifications so would have to manually invalidate the cache for updates,
inserts and deletes in the Business Object.

Can you make any suggestions on the best approach?

Thanks
Andrew


感谢您的回复Andrew,


我认为你是对的。我已经省略了ObjectDataSource.Selected事件

在结果缓存时不会被触发。


对于你的场景,你想要将DataTable分享给ObjectDataSource中除了
之外的其他组件。我认为合理的方法是创建一个

包装器业务对象(在你的原始busniess对象周围返回

DataTable),在这个对象中,你可以先手动缓存

DataTable供以后使用。


SqlCacheDependency不仅限于ObjectDataSource的静态
配置,还支持programmatic接口。


#在ASP.NET应用程序中使用SqlDependency
http://msdn2.microsoft.com/en-us/library/9dz445ks.aspx


你有什么可以做的如下:


1.自定义包装类或原始业务/数据访问类。

在其选择中方法,而不是直接从TableAdapter返回查询的DataTable

,你可以先将DataTable存储到应用程序

缓存中,并始终让你的业务对象从缓存中返回DataTable。例如


if(Cache [" _datatable"] == null)

{

//初始化缓存的数据表< br $>
}


返回Cache [" _datatable"]

2.既然你想利用SqlCacheDependency和

SQL 2005查询通知功能,需要手动构建

SqlDependency。 class并将其添加为

数据表的缓存依赖项。所有这些都可以通过您自己的定制

商务课程中的代码来完成。因此,当SqlDependency到期时,存储在Cache中的数据表对象将无效,这与您在ObjectDatasource的属性中静态声明的
完全相同。


这是在ASP.NET应用程序中使用sqldependcy

以编程方式引入的msdn参考:


#在ASP中使用SqlDependency .NET应用程序
http://msdn2.microsoft .com / zh-CN / library / 9dz445ks.aspx

希望这会有所帮助。


此致,


Steven Cheng


Microsoft MSDN在线支持主管


=============== ===================================

获取通知我的帖子通过邮件?请参阅
http://msdn.microsoft .com / subscripti ... ult.aspx#notif

ications。


注意:MSDN托管新闻组支持服务是针对非紧急问题

如果社区或微软支持人员在1个工作日内做出初步回复是可以接受的。请注意,每个跟随

的响应可能需要大约2个工作日作为支持

专业人士与您合作可能需要进一步调查才能达到

最有效的分辨率。该产品不适用于需要紧急,实时或基于电话的交互或复杂的b $ b项目分析和转储分析问题的情况。这种性质的问题最好通过联系

Microsoft客户支持服务(CSS)处理
href =http://msdn.microsoft.com/subscriptions/support/default.aspx\"target =_ blank> http://msdn.microsoft.com/subscripti...t/default.aspx


==================================== ==============


此帖子按原样提供。没有保证,也没有授予任何权利。
Thanks for your reply Andrew,

I think you''re right. I''ve omitted that the ObjectDataSource.Selected event
won''t get fired when the result is cached.

For your scenario, you want to share the DataTable to other component in
addition to the ObjectDataSource. I think the reasonable way is creating a
wrapper business object (around your original busniess object whch return
the DataTable), and in this object, you can first manually cache the
DataTable for later use.

The SqlCacheDependency is not limited to ObjectDataSource''s static
confriguration, but also support programmatic interface.

#Using SqlDependency in an ASP.NET Application
http://msdn2.microsoft.com/en-us/library/9dz445ks.aspx

What you can do is as below:

1. Customize the wrapper class or your original business/dataaccess class.
In its "select" method, instead of directly return the DataTable queried
from TableAdapter, you can first store the DataTable into the application
cache, and always let your business object return DataTable from cache. e.g.

if(Cache["_datatable"] == null)
{
//initialize the cached datatable
}

return Cache["_datatable"]
2. And since you want to also take advantage of the SqlCacheDependency and
the SQL 2005 query notification feature, you need to manually construct
the "SqlDependency" class and add it as the cache dependency of your
datatable. All of this can be done through code in your own custom
business class. Therefore, the datatable object stored in Cache will
invalid when the SqlDependency expires, it is exactly the same as you
statically declare in ObjectDatasource''s property.

Here is the msdn reference introducing programmatically using sqldependcy
in ASP.NET application:

#Using SqlDependency in an ASP.NET Application
http://msdn2.microsoft.com/en-us/library/9dz445ks.aspx
Hope this helps.

Sincerely,

Steven Cheng

Microsoft MSDN Online Support Lead

==================================================

Get notification to my posts through email? Please refer to
http://msdn.microsoft.com/subscripti...ult.aspx#notif
ications.

Note: The MSDN Managed Newsgroup support offering is for non-urgent issues
where an initial response from the community or a Microsoft Support
Engineer within 1 business day is acceptable. Please note that each follow
up response may take approximately 2 business days as the support
professional working with you may need further investigation to reach the
most efficient resolution. The offering is not appropriate for situations
that require urgent, real-time or phone-based interactions or complex
project analysis and dump analysis issues. Issues of this nature are best
handled working with a dedicated Microsoft Support Engineer by contacting
Microsoft Customer Support Services (CSS) at
http://msdn.microsoft.com/subscripti...t/default.aspx.

==================================================

This posting is provided "AS IS" with no warranties, and confers no rights.


这篇关于SqlCacheDependency和ObjectDataSource的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆