sqladapter caching data?

D

DC Gringo

I am having a problem reading a simple update to the database. Basically
I'm testing a small change to the pubs database -- changing the price of the
Busy Executive's Database Guide from 19.99 to 1997 and back. Unfortunately,
it seems does reflect the change on my web form. Perhaps it's caching the
data retrieved by the SQLDataAdapter? (All of my code is generated by
VS.NET '03.

FYI, it works fine when I test on my developer workstation and database
LocalHost. It's only when I run the application on my development box that
it fails to "notice" the updates. I'm using the "copy project" method to
move it over.

----------------


Public Class Component1
Inherits System.ComponentModel.Component
#Region " Component Designer generated code "
Public Sub New(ByVal Container As System.ComponentModel.IContainer)
MyClass.New()
'Required for Windows.Forms Class Composition Designer support
Container.Add(Me)
End Sub
Public Sub New()
MyBase.New()
'This call is required by the Component Designer.
InitializeComponent()
'Add any initialization after the InitializeComponent() call
End Sub
'Component overrides dispose to clean up the component list.
Protected Overloads Overrides Sub Dispose(ByVal disposing As Boolean)
If disposing Then
If Not (components Is Nothing) Then
components.Dispose()
End If
End If
MyBase.Dispose(disposing)
End Sub
'Required by the Component Designer
Private components As System.ComponentModel.IContainer
'NOTE: The following procedure is required by the Component Designer
'It can be modified using the Component Designer.
'Do not modify it using the code editor.
Friend WithEvents SqlDataAdapter1 As System.Data.SqlClient.SqlDataAdapter
Friend WithEvents SqlSelectCommand1 As System.Data.SqlClient.SqlCommand
Friend WithEvents SqlInsertCommand1 As System.Data.SqlClient.SqlCommand
Friend WithEvents SqlUpdateCommand1 As System.Data.SqlClient.SqlCommand
Friend WithEvents SqlDeleteCommand1 As System.Data.SqlClient.SqlCommand
Friend WithEvents SqlConnection1 As System.Data.SqlClient.SqlConnection
<System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()
Me.SqlDataAdapter1 = New System.Data.SqlClient.SqlDataAdapter
Me.SqlDeleteCommand1 = New System.Data.SqlClient.SqlCommand
Me.SqlConnection1 = New System.Data.SqlClient.SqlConnection
Me.SqlInsertCommand1 = New System.Data.SqlClient.SqlCommand
Me.SqlSelectCommand1 = New System.Data.SqlClient.SqlCommand
Me.SqlUpdateCommand1 = New System.Data.SqlClient.SqlCommand
'
'SqlDataAdapter1
'
Me.SqlDataAdapter1.DeleteCommand = Me.SqlDeleteCommand1
Me.SqlDataAdapter1.InsertCommand = Me.SqlInsertCommand1
Me.SqlDataAdapter1.SelectCommand = Me.SqlSelectCommand1
Me.SqlDataAdapter1.TableMappings.AddRange(New
System.Data.Common.DataTableMapping() {New
System.Data.Common.DataTableMapping("Table", "titles", New
System.Data.Common.DataColumnMapping() {New
System.Data.Common.DataColumnMapping("title_id", "title_id"), New
System.Data.Common.DataColumnMapping("title", "title"), New
System.Data.Common.DataColumnMapping("price", "price"), New
System.Data.Common.DataColumnMapping("notes", "notes"), New
System.Data.Common.DataColumnMapping("pubdate", "pubdate")})})
Me.SqlDataAdapter1.UpdateCommand = Me.SqlUpdateCommand1
'
'SqlDeleteCommand1
'
Me.SqlDeleteCommand1.CommandText = "DELETE FROM titles WHERE (title_id =
@Original_title_id) AND (notes = @Original_n" & _
"otes OR @Original_notes IS NULL AND notes IS NULL) AND (price =
@Original_price " & _
"OR @Original_price IS NULL AND price IS NULL) AND (pubdate =
@Original_pubdate) " & _
"AND (title = @Original_title)"
Me.SqlDeleteCommand1.Connection = Me.SqlConnection1
Me.SqlDeleteCommand1.Parameters.Add(New
System.Data.SqlClient.SqlParameter("@Original_title_id",
System.Data.SqlDbType.VarChar, 6, System.Data.ParameterDirection.Input,
False, CType(0, Byte), CType(0, Byte), "title_id",
System.Data.DataRowVersion.Original, Nothing))
Me.SqlDeleteCommand1.Parameters.Add(New
System.Data.SqlClient.SqlParameter("@Original_notes",
System.Data.SqlDbType.VarChar, 200, System.Data.ParameterDirection.Input,
False, CType(0, Byte), CType(0, Byte), "notes",
System.Data.DataRowVersion.Original, Nothing))
Me.SqlDeleteCommand1.Parameters.Add(New
System.Data.SqlClient.SqlParameter("@Original_price",
System.Data.SqlDbType.Money, 8, System.Data.ParameterDirection.Input, False,
CType(0, Byte), CType(0, Byte), "price",
System.Data.DataRowVersion.Original, Nothing))
Me.SqlDeleteCommand1.Parameters.Add(New
System.Data.SqlClient.SqlParameter("@Original_pubdate",
System.Data.SqlDbType.DateTime, 8, System.Data.ParameterDirection.Input,
False, CType(0, Byte), CType(0, Byte), "pubdate",
System.Data.DataRowVersion.Original, Nothing))
Me.SqlDeleteCommand1.Parameters.Add(New
System.Data.SqlClient.SqlParameter("@Original_title",
System.Data.SqlDbType.VarChar, 80, System.Data.ParameterDirection.Input,
False, CType(0, Byte), CType(0, Byte), "title",
System.Data.DataRowVersion.Original, Nothing))
'
'SqlConnection1
'
Me.SqlConnection1.ConnectionString =
"server=2k01;uid=sa;pwd=mypassword;database=pubs"
'
'SqlInsertCommand1
'
Me.SqlInsertCommand1.CommandText = "INSERT INTO titles(title_id, title,
price, notes, pubdate) VALUES (@title_id, @ti" & _
"tle, @price, @notes, @pubdate); SELECT title_id, title, price, notes,
pubdate FR" & _
"OM titles WHERE (title_id = @title_id)"
Me.SqlInsertCommand1.Connection = Me.SqlConnection1
Me.SqlInsertCommand1.Parameters.Add(New
System.Data.SqlClient.SqlParameter("@title_id",
System.Data.SqlDbType.VarChar, 6, "title_id"))
Me.SqlInsertCommand1.Parameters.Add(New
System.Data.SqlClient.SqlParameter("@title", System.Data.SqlDbType.VarChar,
80, "title"))
Me.SqlInsertCommand1.Parameters.Add(New
System.Data.SqlClient.SqlParameter("@price", System.Data.SqlDbType.Money, 8,
"price"))
Me.SqlInsertCommand1.Parameters.Add(New
System.Data.SqlClient.SqlParameter("@notes", System.Data.SqlDbType.VarChar,
200, "notes"))
Me.SqlInsertCommand1.Parameters.Add(New
System.Data.SqlClient.SqlParameter("@pubdate",
System.Data.SqlDbType.DateTime, 8, "pubdate"))
'
'SqlSelectCommand1
'
Me.SqlSelectCommand1.CommandText = "SELECT title_id, title, price, notes,
pubdate FROM titles"
Me.SqlSelectCommand1.Connection = Me.SqlConnection1
'
'SqlUpdateCommand1
'
Me.SqlUpdateCommand1.CommandText = "UPDATE titles SET title_id = @title_id,
title = @title, price = @price, notes = @" & _
"notes, pubdate = @pubdate WHERE (title_id = @Original_title_id) AND (notes
= @Or" & _
"iginal_notes OR @Original_notes IS NULL AND notes IS NULL) AND (price =
@Origina" & _
"l_price OR @Original_price IS NULL AND price IS NULL) AND (pubdate =
@Original_p" & _
"ubdate) AND (title = @Original_title); SELECT title_id, title, price,
notes, pub" & _
"date FROM titles WHERE (title_id = @title_id)"
Me.SqlUpdateCommand1.Connection = Me.SqlConnection1
Me.SqlUpdateCommand1.Parameters.Add(New
System.Data.SqlClient.SqlParameter("@title_id",
System.Data.SqlDbType.VarChar, 6, "title_id"))
Me.SqlUpdateCommand1.Parameters.Add(New
System.Data.SqlClient.SqlParameter("@title", System.Data.SqlDbType.VarChar,
80, "title"))
Me.SqlUpdateCommand1.Parameters.Add(New
System.Data.SqlClient.SqlParameter("@price", System.Data.SqlDbType.Money, 8,
"price"))
Me.SqlUpdateCommand1.Parameters.Add(New
System.Data.SqlClient.SqlParameter("@notes", System.Data.SqlDbType.VarChar,
200, "notes"))
Me.SqlUpdateCommand1.Parameters.Add(New
System.Data.SqlClient.SqlParameter("@pubdate",
System.Data.SqlDbType.DateTime, 8, "pubdate"))
Me.SqlUpdateCommand1.Parameters.Add(New
System.Data.SqlClient.SqlParameter("@Original_title_id",
System.Data.SqlDbType.VarChar, 6, System.Data.ParameterDirection.Input,
False, CType(0, Byte), CType(0, Byte), "title_id",
System.Data.DataRowVersion.Original, Nothing))
Me.SqlUpdateCommand1.Parameters.Add(New
System.Data.SqlClient.SqlParameter("@Original_notes",
System.Data.SqlDbType.VarChar, 200, System.Data.ParameterDirection.Input,
False, CType(0, Byte), CType(0, Byte), "notes",
System.Data.DataRowVersion.Original, Nothing))
Me.SqlUpdateCommand1.Parameters.Add(New
System.Data.SqlClient.SqlParameter("@Original_price",
System.Data.SqlDbType.Money, 8, System.Data.ParameterDirection.Input, False,
CType(0, Byte), CType(0, Byte), "price",
System.Data.DataRowVersion.Original, Nothing))
Me.SqlUpdateCommand1.Parameters.Add(New
System.Data.SqlClient.SqlParameter("@Original_pubdate",
System.Data.SqlDbType.DateTime, 8, System.Data.ParameterDirection.Input,
False, CType(0, Byte), CType(0, Byte), "pubdate",
System.Data.DataRowVersion.Original, Nothing))
Me.SqlUpdateCommand1.Parameters.Add(New
System.Data.SqlClient.SqlParameter("@Original_title",
System.Data.SqlDbType.VarChar, 80, System.Data.ParameterDirection.Input,
False, CType(0, Byte), CType(0, Byte), "title",
System.Data.DataRowVersion.Original, Nothing))
End Sub
#End Region
Public Sub FillDataSet(ByVal dSet As MyDataSet)
SqlDataAdapter1.Fill(dSet)
End Sub
End Class

_____
DC G
 
H

Herfried K. Wagner [MVP]

* "DC Gringo said:
I am having a problem reading a simple update to the database. Basically
I'm testing a small change to the pubs database -- changing the price of the
Busy Executive's Database Guide from 19.99 to 1997 and back. Unfortunately,
it seems does reflect the change on my web form. Perhaps it's caching the
data retrieved by the SQLDataAdapter? (All of my code is generated by
VS.NET '03.

Post this question in the ADO.NET group, there you will more likely get
an answer:

<
Web interface:

<http://msdn.microsoft.com/newsgroup...roup=microsoft.public.dotnet.framework.adonet>
 
C

Cor

Hi DC Gringo,

Did you put your adapter.update in a try catch end try block.
Try
da.Fill(ds)
Catch sqlExc As SqlClient.SqlException
messagebox.show(sqlExc.ToString) 'for a windowsform
Catch exc As Exception
messagebox.show(exc.ToString) ' for a windowsform
Finally
conn.Close()
End Try
End If
 
D

DC Gringo

Actually, what I'm doing is making changes directly to the database via
Enterprise Manager (not via VB code)...then refreshing my browser.

_____
DC G
 
C

Cor

Hi DC,

Than I think you are probably doing the updates on the wrong server.

The pubs database is maybe several times installed.

Cor
 
D

DC Gringo

Must have been...I tried it again this morning with no problem. <doink!!!>

Thanks for listening!
_____
DC G
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top