Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / ASP.NET / Caching / May 2007

Tip: Looking for answers? Try searching our database.

Cache problem

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
zino - 04 May 2007 22:04 GMT
in ASP net 2.0
a function that query/add item to cache:
public function1
... ... ..
If HttpContext.Current.Cache(myKey) Is Nothing Then
     Dim ds As DataSet = functionToCreateDataset.... ...
      HttpContext.Current.Cache.Insert(myKey, ds, Nothing)
End If
Return HttpContext.Current.Cache

in the web form code behind, I have:
Dim ds As DataSet = Cache("myKey")
dim ds as dataset
ds.Tables(0).Columns.Add("customCol", GetType(String), "col1+'- '+col2")

the problem is, when "function1"  create the cache the first time,  the
statement:
ds.Tables(0).Columns.Add("col1", GetType(String), "col1+'- '+col2")
works fine. But when "function1" returned the cached item, the same
statement display the error:
"A column named 'customCol' already belongs to this DataTable."

it looks like  the cache get changed too when the dataset derived from it is
changed.
how can I fix that ?
Alvin Bruney [MVP] - 05 May 2007 14:30 GMT
This is an error, you have ds declared twice, it's most likely a typo. I
wouldn't expect that to compile:

Dim ds As DataSet = Cache("myKey")
dim ds as dataset

When you first create your dataset, it contains a column named customCol.
You can, at any point later, add another column with that name because
column names are explicitly unique.

Signature

Regards,
Alvin Bruney
------------------------------------------------------
Shameless author plug
Excel Services for .NET is coming...
OWC Black book on Amazon and
www.lulu.com/owc
Professional VSTO 2005 - Wrox/Wiley

> in ASP net 2.0
> a function that query/add item to cache:
[quoted text clipped - 22 lines]
> changed.
> how can I fix that ?
zino - 07 May 2007 14:47 GMT
there is a little confusion here.
the issue is :
- a datatable consisting of 2 column is created and added to the cache.
(cache("myDt") )

- a variable derived from a call to this cache :
Dim dt2 As DataTable = CType(Cache("myDt"), DataTable)

the following: dt2.Columns.Count       will return: 2

now,
any change to dt2  as:
dt2.Columns.Add("customCol", GetType(String), "col1+'- '+col2") , is
changing cache("myDt")  too.

after the previous statement:
the following:
Dim dt3 As DataTable = CType(Cache("myDt"), DataTable)
dt3.Columns.Count  will return: 3

why 3 ??
Why the change done on dt2 propagated back to the cache ?
Alvin Bruney [MVP] - 08 May 2007 00:20 GMT
Sorry if I am out of left field because the original thread isn't included.
Cache holds live object references not copies. Well, the copy is a pointer
reference that *points to the live object.

Signature

Regards,
Alvin Bruney
------------------------------------------------------
Shameless author plug
Excel Services for .NET is coming...
OWC Black book on Amazon and
www.lulu.com/owc
Professional VSTO 2005 - Wrox/Wiley

> there is a little confusion here.
> the issue is :
[quoted text clipped - 18 lines]
> why 3 ??
> Why the change done on dt2 propagated back to the cache ?
zino - 08 May 2007 13:20 GMT
Thank you.
that answers my question.

> Sorry if I am out of left field because the original thread isn't included.
> Cache holds live object references not copies. Well, the copy is a pointer
[quoted text clipped - 22 lines]
> > why 3 ??
> > Why the change done on dt2 propagated back to the cache ?

Rate this thread:







Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.