M
mfreeman
The minimal code (VB.NET 2003) needed to show this problem is shown
below. All I do is loop through the records in the table and update
them without making any changes. Out of 600 records, about 40 of them
throw Concurrency violation errors in the update, and my GetAllColErrs
function provides no output. In comparing the rows that throw errors
with those that do not, I could find no pattern.
It is obviously a bogus error, as the database is an Access 2003 MDB
file on my PC and there is no concurrent access taking place. After
doing much research as to possible causes, I changed all decimal
columns in the database and XSD file (also provided below) to doubles.
No difference.
Dim FundsDS As DataSets.FundsDataset
Dim FundRow As DataSets.FundsDataset.FundsRow
Dim myCommand As OleDbDataAdapter
FundsDS = New DataSets.FundsDataset
myConnection = New
OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" &
strFileName & ";Persist Security Info=False")
myConnection.Open()
Try
myCommand = New OleDbDataAdapter("SELECT * FROM Funds ORDER BY
TICKER", myConnection)
myCommand.FillSchema(FundsDS, SchemaType.Source, "Funds")
myCommand.Fill(FundsDS, "Funds")
Dim myBuilder As OleDbCommandBuilder = New
OleDbCommandBuilder(myCommand)
myBuilder.QuotePrefix = "["
myBuilder.QuoteSuffix = "]"
OpenDB = True
Catch e As StrongTypingException
ErrorHandler(e.Source, e.Message)
Catch e As Exception
ErrorHandler(e.Source, e.Message)
End Try
For Each FundRow In FundsDS.Funds
'Code to do something useful would go here
Try
myCommand.Update(FundsDS.Tables(0))
FundRow.AcceptChanges()
Catch e As DBConcurrencyException
ErrorHandler(e.Source, e.Message & GetAllColErrs(FundRow))
FundRow.RejectChanges()
Catch e As OleDbException
ErrorHandler(e.Source, e.Message)
FundRow.RejectChanges()
Catch e As Exception
ErrorHandler(e.Source, e.Message)
FundRow.RejectChanges()
End Try
Next
Private Function GetAllColErrs(ByVal myRow As DataRow) As String
' Declare an array variable for DataColumn objects.
Dim colArr() As DataColumn
Dim myRows() As DataRow
Dim myCol As DataColumn
Dim myTable As DataTable
Dim myBuilder As New StringBuilder
myBuilder.Append(" Column(s):")
Dim intLoop As Integer
For Each myTable In FundsDS.Tables
If myTable.HasErrors Then
myRows = myTable.GetErrors
For Each myCol In myRow.GetColumnsInError
If intLoop > 0 Then
myBuilder.Append(vbCrLf)
End If
myBuilder.Append(myCol.ColumnName & " " &
myRows(intLoop).GetColumnError(myCol))
Next
End If
Next
GetAllColErrs = myBuilder.ToString
End Function
Here is the XSD file:
<?xml version="1.0" standalone="yes" ?>
<xs:schema id="FundsDataset"
xmlns:mstns="http://www.tempuri.org/FundsDataSet.xsd"
xmlns:xs="http://www.w3.org/2001/XMLSchema"
xmlns:msdata="urn:schemas-microsoft-com:xml-msdata"
attributeFormDefault="qualified" elementFormDefault="qualified">
<xs:element name="FundsDataset" msdata:IsDataSet="true">
<xs:complexType>
<xs:choice maxOccurs="unbounded">
<xs:element name="Funds">
<xs:complexType>
<xs:sequence>
<xs:element name="_x0031_0YearReturn"
type="xs:double" minOccurs="0" />
<xs:element name="_x0031_0YearRisk"
type="xs:double" minOccurs="0" />
<xs:element name="_x0031_0Years" type="xs:double"
minOccurs="0" />
<xs:element name="_x0031_0YearStars"
type="xs:unsignedByte" minOccurs="0" />
<xs:element name="_x0031_0YearTaxEff"
type="xs:double" minOccurs="0" />
<xs:element name="_x0031_2b-1Fee" type="xs:double"
minOccurs="0" />
<xs:element name="_x0033_YearReturn"
type="xs:double" minOccurs="0" />
<xs:element name="_x0033_YearRisk"
type="xs:double" minOccurs="0" />
<xs:element name="_x0033_Years" type="xs:double"
minOccurs="0" />
<xs:element name="_x0033_YearStars"
type="xs:unsignedByte" minOccurs="0" />
<xs:element name="_x0033_YearTaxEff"
type="xs:double" minOccurs="0" />
<xs:element name="_x0035_yearReturn"
type="xs:double" minOccurs="0" />
<xs:element name="_x0035_yearRisk"
type="xs:double" minOccurs="0" />
<xs:element name="_x0035_Years" type="xs:double"
minOccurs="0" />
<xs:element name="_x0035_YearStars"
type="xs:unsignedByte" minOccurs="0" />
<xs:element name="_x0035_YearTaxEff"
type="xs:double" minOccurs="0" />
<xs:element name="AllReturn" type="xs:double"
minOccurs="0" />
<xs:element name="AllRisk" type="xs:double"
minOccurs="0" />
<xs:element name="AllStars" type="xs:unsignedByte"
minOccurs="0" />
<xs:element name="BearDecile" type="xs:double"
minOccurs="0" />
<xs:element name="BestAvgReturn" type="xs:double"
minOccurs="0" />
<xs:element name="BestAvgRisk" type="xs:double"
minOccurs="0" />
<xs:element name="BestBear" type="xs:double"
minOccurs="0" />
<xs:element name="BestCapExp" type="xs:double"
minOccurs="0" />
<xs:element name="BestMean" type="xs:double"
minOccurs="0" />
<xs:element name="BestReturn" type="xs:double"
minOccurs="0" />
<xs:element name="BestReward" type="xs:double"
minOccurs="0" />
<xs:element name="BestRisk" type="xs:double"
minOccurs="0" />
<xs:element name="BestSharpe" type="xs:double"
minOccurs="0" />
<xs:element name="BestStars" type="xs:double"
minOccurs="0" />
<xs:element name="BestSTD" type="xs:double"
minOccurs="0" />
<xs:element name="BestTax" type="xs:double"
minOccurs="0" />
<xs:element name="BestTaxEff" type="xs:double"
minOccurs="0" />
<xs:element name="Brokers" type="xs:string"
minOccurs="0" />
<xs:element name="CapGainsExp" type="xs:double"
minOccurs="0" />
<xs:element name="Category" type="xs:string"
minOccurs="0" />
<xs:element name="CurrentPrice" type="xs:double"
minOccurs="0" />
<xs:element name="DeferredLoad" type="xs:double"
minOccurs="0" />
<xs:element name="ErrorDesc" type="xs:string"
minOccurs="0" />
<xs:element name="ExpenseRatio" type="xs:double"
minOccurs="0" />
<xs:element name="Fund" type="xs:string"
minOccurs="0" />
<xs:element name="GeneralAdditional"
type="xs:double" minOccurs="0" />
<xs:element name="GeneralInitial" type="xs:double"
minOccurs="0" />
<xs:element name="Inception" type="xs:dateTime"
minOccurs="0" />
<xs:element name="InitialLoad" type="xs:double"
minOccurs="0" />
<xs:element name="IRAAdditional" type="xs:double"
minOccurs="0" />
<xs:element name="IRAInitial" type="xs:double"
minOccurs="0" />
<xs:element name="ManagerName" type="xs:string"
minOccurs="0" />
<xs:element name="Mean" type="xs:double"
minOccurs="0" />
<xs:element name="MgmtFee" type="xs:double"
minOccurs="0" />
<xs:element name="MgrDate" type="xs:dateTime"
minOccurs="0" />
<xs:element name="NetAssets" type="xs:double"
minOccurs="0" />
<xs:element name="Redemption" type="xs:double"
minOccurs="0" />
<xs:element name="RejectDate" type="xs:dateTime"
minOccurs="0" />
<xs:element name="RejectReason" type="xs:string"
minOccurs="0" />
<xs:element name="Sharpe" type="xs:double"
minOccurs="0" />
<xs:element name="SmallestFund" type="xs:double"
minOccurs="0" />
<xs:element name="STD" type="xs:double"
minOccurs="0" />
<xs:element name="TempRating" type="xs:string"
minOccurs="0" />
<xs:element name="Ticker" type="xs:string" />
<xs:element name="TotalFees" type="xs:double"
minOccurs="0" />
<xs:element name="Updated" type="xs:dateTime"
minOccurs="0" />
<xs:element name="UpdateError" type="xs:boolean"
minOccurs="0" />
<xs:element name="Year" type="xs:double"
minOccurs="0" />
<xs:element name="YTD" type="xs:double"
minOccurs="0" />
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:choice>
</xs:complexType>
<xs:unique name="Constraint1" msdatarimaryKey="true">
<xs:selector xpath=".//mstns:Funds" />
<xs:field xpath="mstns:Ticker" />
</xs:unique>
</xs:element>
</xs:schema>
Does anyone have any idea how to diagnose the cause of this problem?
Thanks,
Mark
below. All I do is loop through the records in the table and update
them without making any changes. Out of 600 records, about 40 of them
throw Concurrency violation errors in the update, and my GetAllColErrs
function provides no output. In comparing the rows that throw errors
with those that do not, I could find no pattern.
It is obviously a bogus error, as the database is an Access 2003 MDB
file on my PC and there is no concurrent access taking place. After
doing much research as to possible causes, I changed all decimal
columns in the database and XSD file (also provided below) to doubles.
No difference.
Dim FundsDS As DataSets.FundsDataset
Dim FundRow As DataSets.FundsDataset.FundsRow
Dim myCommand As OleDbDataAdapter
FundsDS = New DataSets.FundsDataset
myConnection = New
OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" &
strFileName & ";Persist Security Info=False")
myConnection.Open()
Try
myCommand = New OleDbDataAdapter("SELECT * FROM Funds ORDER BY
TICKER", myConnection)
myCommand.FillSchema(FundsDS, SchemaType.Source, "Funds")
myCommand.Fill(FundsDS, "Funds")
Dim myBuilder As OleDbCommandBuilder = New
OleDbCommandBuilder(myCommand)
myBuilder.QuotePrefix = "["
myBuilder.QuoteSuffix = "]"
OpenDB = True
Catch e As StrongTypingException
ErrorHandler(e.Source, e.Message)
Catch e As Exception
ErrorHandler(e.Source, e.Message)
End Try
For Each FundRow In FundsDS.Funds
'Code to do something useful would go here
Try
myCommand.Update(FundsDS.Tables(0))
FundRow.AcceptChanges()
Catch e As DBConcurrencyException
ErrorHandler(e.Source, e.Message & GetAllColErrs(FundRow))
FundRow.RejectChanges()
Catch e As OleDbException
ErrorHandler(e.Source, e.Message)
FundRow.RejectChanges()
Catch e As Exception
ErrorHandler(e.Source, e.Message)
FundRow.RejectChanges()
End Try
Next
Private Function GetAllColErrs(ByVal myRow As DataRow) As String
' Declare an array variable for DataColumn objects.
Dim colArr() As DataColumn
Dim myRows() As DataRow
Dim myCol As DataColumn
Dim myTable As DataTable
Dim myBuilder As New StringBuilder
myBuilder.Append(" Column(s):")
Dim intLoop As Integer
For Each myTable In FundsDS.Tables
If myTable.HasErrors Then
myRows = myTable.GetErrors
For Each myCol In myRow.GetColumnsInError
If intLoop > 0 Then
myBuilder.Append(vbCrLf)
End If
myBuilder.Append(myCol.ColumnName & " " &
myRows(intLoop).GetColumnError(myCol))
Next
End If
Next
GetAllColErrs = myBuilder.ToString
End Function
Here is the XSD file:
<?xml version="1.0" standalone="yes" ?>
<xs:schema id="FundsDataset"
xmlns:mstns="http://www.tempuri.org/FundsDataSet.xsd"
xmlns:xs="http://www.w3.org/2001/XMLSchema"
xmlns:msdata="urn:schemas-microsoft-com:xml-msdata"
attributeFormDefault="qualified" elementFormDefault="qualified">
<xs:element name="FundsDataset" msdata:IsDataSet="true">
<xs:complexType>
<xs:choice maxOccurs="unbounded">
<xs:element name="Funds">
<xs:complexType>
<xs:sequence>
<xs:element name="_x0031_0YearReturn"
type="xs:double" minOccurs="0" />
<xs:element name="_x0031_0YearRisk"
type="xs:double" minOccurs="0" />
<xs:element name="_x0031_0Years" type="xs:double"
minOccurs="0" />
<xs:element name="_x0031_0YearStars"
type="xs:unsignedByte" minOccurs="0" />
<xs:element name="_x0031_0YearTaxEff"
type="xs:double" minOccurs="0" />
<xs:element name="_x0031_2b-1Fee" type="xs:double"
minOccurs="0" />
<xs:element name="_x0033_YearReturn"
type="xs:double" minOccurs="0" />
<xs:element name="_x0033_YearRisk"
type="xs:double" minOccurs="0" />
<xs:element name="_x0033_Years" type="xs:double"
minOccurs="0" />
<xs:element name="_x0033_YearStars"
type="xs:unsignedByte" minOccurs="0" />
<xs:element name="_x0033_YearTaxEff"
type="xs:double" minOccurs="0" />
<xs:element name="_x0035_yearReturn"
type="xs:double" minOccurs="0" />
<xs:element name="_x0035_yearRisk"
type="xs:double" minOccurs="0" />
<xs:element name="_x0035_Years" type="xs:double"
minOccurs="0" />
<xs:element name="_x0035_YearStars"
type="xs:unsignedByte" minOccurs="0" />
<xs:element name="_x0035_YearTaxEff"
type="xs:double" minOccurs="0" />
<xs:element name="AllReturn" type="xs:double"
minOccurs="0" />
<xs:element name="AllRisk" type="xs:double"
minOccurs="0" />
<xs:element name="AllStars" type="xs:unsignedByte"
minOccurs="0" />
<xs:element name="BearDecile" type="xs:double"
minOccurs="0" />
<xs:element name="BestAvgReturn" type="xs:double"
minOccurs="0" />
<xs:element name="BestAvgRisk" type="xs:double"
minOccurs="0" />
<xs:element name="BestBear" type="xs:double"
minOccurs="0" />
<xs:element name="BestCapExp" type="xs:double"
minOccurs="0" />
<xs:element name="BestMean" type="xs:double"
minOccurs="0" />
<xs:element name="BestReturn" type="xs:double"
minOccurs="0" />
<xs:element name="BestReward" type="xs:double"
minOccurs="0" />
<xs:element name="BestRisk" type="xs:double"
minOccurs="0" />
<xs:element name="BestSharpe" type="xs:double"
minOccurs="0" />
<xs:element name="BestStars" type="xs:double"
minOccurs="0" />
<xs:element name="BestSTD" type="xs:double"
minOccurs="0" />
<xs:element name="BestTax" type="xs:double"
minOccurs="0" />
<xs:element name="BestTaxEff" type="xs:double"
minOccurs="0" />
<xs:element name="Brokers" type="xs:string"
minOccurs="0" />
<xs:element name="CapGainsExp" type="xs:double"
minOccurs="0" />
<xs:element name="Category" type="xs:string"
minOccurs="0" />
<xs:element name="CurrentPrice" type="xs:double"
minOccurs="0" />
<xs:element name="DeferredLoad" type="xs:double"
minOccurs="0" />
<xs:element name="ErrorDesc" type="xs:string"
minOccurs="0" />
<xs:element name="ExpenseRatio" type="xs:double"
minOccurs="0" />
<xs:element name="Fund" type="xs:string"
minOccurs="0" />
<xs:element name="GeneralAdditional"
type="xs:double" minOccurs="0" />
<xs:element name="GeneralInitial" type="xs:double"
minOccurs="0" />
<xs:element name="Inception" type="xs:dateTime"
minOccurs="0" />
<xs:element name="InitialLoad" type="xs:double"
minOccurs="0" />
<xs:element name="IRAAdditional" type="xs:double"
minOccurs="0" />
<xs:element name="IRAInitial" type="xs:double"
minOccurs="0" />
<xs:element name="ManagerName" type="xs:string"
minOccurs="0" />
<xs:element name="Mean" type="xs:double"
minOccurs="0" />
<xs:element name="MgmtFee" type="xs:double"
minOccurs="0" />
<xs:element name="MgrDate" type="xs:dateTime"
minOccurs="0" />
<xs:element name="NetAssets" type="xs:double"
minOccurs="0" />
<xs:element name="Redemption" type="xs:double"
minOccurs="0" />
<xs:element name="RejectDate" type="xs:dateTime"
minOccurs="0" />
<xs:element name="RejectReason" type="xs:string"
minOccurs="0" />
<xs:element name="Sharpe" type="xs:double"
minOccurs="0" />
<xs:element name="SmallestFund" type="xs:double"
minOccurs="0" />
<xs:element name="STD" type="xs:double"
minOccurs="0" />
<xs:element name="TempRating" type="xs:string"
minOccurs="0" />
<xs:element name="Ticker" type="xs:string" />
<xs:element name="TotalFees" type="xs:double"
minOccurs="0" />
<xs:element name="Updated" type="xs:dateTime"
minOccurs="0" />
<xs:element name="UpdateError" type="xs:boolean"
minOccurs="0" />
<xs:element name="Year" type="xs:double"
minOccurs="0" />
<xs:element name="YTD" type="xs:double"
minOccurs="0" />
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:choice>
</xs:complexType>
<xs:unique name="Constraint1" msdatarimaryKey="true">
<xs:selector xpath=".//mstns:Funds" />
<xs:field xpath="mstns:Ticker" />
</xs:unique>
</xs:element>
</xs:schema>
Does anyone have any idea how to diagnose the cause of this problem?
Thanks,
Mark