我可以在Web服务方法中使用Web缓存吗? [英] can i use web cache in web service method

查看:72
本文介绍了我可以在Web服务方法中使用Web缓存吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

嗨每个

我使用的是使用sql cache依赖的web服务方法 但问题是我总是有错误:

i use web service method which use sql cache dependency  but the problem is that i alwayes have error in:

DataTable categories =(DataTable)Cache.Get(" Categories"); 

DataTable categories = (DataTable)Cache.Get("Categories"); 

Cache.Insert(" Categories",categories,dependency);

Cache.Insert("Categories", categories, dependency);

我不知道为什么??

但如果该方法不是网络服务,此方法可以成功运行?? !!

but this method works successfully in if the method is not a web service??!!

 

这是我的方法:

[

  public bool GetCategories()

        {

         

           串的connectionString = ConfigurationManager.ConnectionStrings [" AttendanceConnectionString"]的ConnectionString;

 public bool GetCategories()
        {
         
            string connectionString = ConfigurationManager.ConnectionStrings["AttendanceConnectionString"].ConnectionString;

///我有错误这里

    &NBSP ;       DataTable类别=(DataTable)Cache.Get(" Categories");

           

            if(categories == null)

            {

                // DataTable categories = new DataTable();

               使用(SqlConnection的连接=

                  &NBSP ;    新的SqlConnection(的connectionString))

             &NBSP ;  {

                   的SqlCommand命令=新的SqlCommand(QUOT; SELECT AttendanceTransactionTmpID,DepartureTime FROM dbo.Attendance_Transaction_TMP" ;,连接);

          &NBSP ;        的SqlCacheDependency依赖性=新的SqlCacheDependency(命令);

                &NBSP ;   SqlDataAdapter的适配器=新的SqlDataAdapter();

                     adapter.SelectCommand =命令;

                    数据集的数据集=新的DataSet();

                     adapter.Fill(数据集);

                 &NBSP ;  categories = dataset.Tables [0];

///i have error here
            DataTable categories = (DataTable)Cache.Get("Categories");
           
            if (categories == null)
            {
                // DataTable categories = new DataTable();
                using (SqlConnection connection =
                        new SqlConnection(connectionString))
                {
                    SqlCommand command = new SqlCommand("SELECT AttendanceTransactionTmpID,DepartureTime FROM dbo.Attendance_Transaction_TMP", connection);
                    SqlCacheDependency dependency = new SqlCacheDependency(command);
                    SqlDataAdapter adapter = new SqlDataAdapter();
                    adapter.SelectCommand = command;
                    DataSet dataset = new DataSet();
                    adapter.Fill(dataset);
                    categories = dataset.Tables[0];

///我这里有错误。
                     Cache.Insert(QUOT;类别" ;,类别依赖性);

                    返回true;

                }
            }
           否则为
            {

               返回false;

            }

///and i have error here
                    Cache.Insert("Categories", categories, dependency);
                    return true;
                }
            }
            else
            {
                return false;
            }

        } 

        }

        } 
        }

 

 祝福

fatma

推荐答案

您是否使用了Context.Cache类?错误是什么?

Did you use the Context.Cache class? What is the error?

 


这篇关于我可以在Web服务方法中使用Web缓存吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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