Asp.net 2.0 提供了一个新的数据缓存功能,就是利用sql server2005 的异步通知功能来实现缓存
1.首先在sqlserver2005 中创建一个test的数据库.添加一个 employee的数据库表.
1
CREATE TABLE [dbo].[employee](
2
[id] [int] IDENTITY(1,1) NOT NULL,
3
[name] [varchar](50)
4
)
5
2
3
4
5
2使用 vs2005 创建一个新的asp.net项目.
web.config如下
1
<?xml version="1.0"?>
2
<configuration xmlns="http://schemas.microsoft.com/.NetConfiguration/v2.0">
3
<appSettings/>
4
<connectionStrings>
5
<add name="mySource" connectionString="Data Source=.\sql2005;Initial Catalog=test;Persist Security Info=True;User ID=sa;Password=sasa" providerName="System.Data.SqlClient"></add>
6
</connectionStrings>
7
<system.web>
8
<compilation debug="true"/>
9
<authentication mode="Windows"/>
10
</system.web>
11
</configuration>
12
2
3
4
5
6
7
8
9
10
11
12
3.编写global.asax文件,启动监听sql2005通知事件.
4.编写数据访问代码.创建一个EmployeeData的类,代码如下
这里需要注意的是 select语句的写法, 不能使用 select * 的方式,一定要在表名前加架构名称 如我们这里的 dbo.employee.
5.编写测试页面代码.
6.插入后台代码