How do I … identify dataset constraint type that has failed when I get exception: System.Data.ConstraintException: Failed to enable constraints. One or more …

How do I … identify dataset constraint type that has failed when I get exception:

This is a nice trick

System.Data.ConstraintException: Failed to enable constraints. One or more rows contain values violating non-null, unique, or foreign-key constraints.

Write a test that Fills the requried table. I use a helper class for datasets, but you could change this to put the tableadapter in here.
Then loop through the columns and remove the constraints
Also remove the primary key constraint
Prove that the Fill now works. Then stop turning the constraints off one-by-one until you find the type of constraint.


<TestMethod()> _

Public Sub FillTest()

Dim dsValue As New <datasetname>
Dim target As New <dataset>Helper(dsValue)
For Each col As DataColumn In dsValue.<tablename>.Columns
If col.Ordinal < 10 Then   'Use to reduce possible columns down
col.MaxLength = -1       'Rem in or out to reduce possible constraints. And next line
col.AllowDBNull = True
End If
Next

dsValue.<tablename>.PrimaryKey = Nothing
Dim aList = dsValue.<tablename>.Constraints

Stop
target.Fill

End Sub

 

Optional helper methods

    Private Sub SetAllowDBNULLTrue(dt As DataTable, Optional MinOrdinal As Integer = 0, Optional MaxOrdinal As Nullable(Of Integer) = Nothing)

        If Not MaxOrdinal.HasValue Then MaxOrdinal = dt.Columns.Count

        For Each col As DataColumn In dt.Columns
            If col.Ordinal > MinOrdinal AndAlso col.Ordinal < MaxOrdinal Then   'Use to reduce possible columns down
                If col.AllowDBNull = False Then
                    Debug.Print("Changing column to allow null " + col.ColumnName)
                    col.AllowDBNull = True
                End If
            End If
        Next

    End Sub

    Private Sub SetMaxLengthToMinus1(dt As DataTable, Optional MinOrdinal As Integer = 0, Optional MaxOrdinal As Nullable(Of Integer) = Nothing)

        If Not MaxOrdinal.HasValue Then MaxOrdinal = dt.Columns.Count

        For Each col As DataColumn In dt.Columns
            If col.Ordinal > MinOrdinal AndAlso col.Ordinal < MaxOrdinal Then   'Use to reduce possible columns down
                If col.MaxLength <> -1 Then
                    Debug.Print("Changing column MaxLength to -1 for " + col.ColumnName)
                    col.MaxLength = -1       'Rem in or out to reduce possible constraints. And next line
                End If
            End If
        Next

    End Sub

 

LocalReport set-up and publish

How do I … keep reports in a sub-directory

May be set in code or in ReportViewer control

Dim report as New LocalReport()
report.ReportPath = “Reports\ReportName.rdlc”

How do I … fix Local reports that work in Visual Studio not when published

The errors you may get include:

  • An error occurred during local report processing copy
    The report definition for report ‘..\some_path_to_report\<reportname>.rdlc’ has not been specified
    Could not find file ‘C:\inetpub\wwwroot\some_path_to_report\tse.rdlc’.

When reports are added their default Build Action is Embedded Resource.
To fix this change to Content and choose a copy policy, probably Copy if Newer

How do I … use a report in a referenced project

Add the report as a “Linked” file ( Add existing item > Add as Link )(probably) at the same directory level as in the referenced project
Then on these linked files choose the necesary options as above

TFS Build: Referenced assembly ‘…dll’ targets a different processor than the application

 

For both the application and the referenced library check that the following match

Project > Properties > Compile > Advanced Compile Options > Target CPU ( possibly also the Target Framework )

If difficult to find use the Build explorer > View Log > Next Warning to work out the application project

TFS Build: Could not resolve this reference. Could not locate the assembly ”. Check to make sure the assembly exists on disk.

A TFS Build fails probably after a new reference has been added. Possibly a .exe reference

ERROR
TFS Build: Could not resolve this reference. Could not locate the assembly ‘<name>’. Check to make sure the assembly exists on disk. If this reference is required by your code, you may get compilation errors

SOLUTION
In Team Explorer > Builds > Build Explorer > Select broken build and double-click to work out which project did not build
Visual Studio > Projects > Project Dependencies > Select project that is not building > Add the required dependency > Confirm that the Build Order tab now shows this project higher than the project failing to build

Still did not work. Removed and added the reference again and it then worked.
The change in Source Control for the file was that the version no was in the broken version. not in the fixed version. Before here:

After here:

 

Visual Studio Macros “Cannot load the recording macro…”

Error
“Cannot load the recording macro project ” for the following reason:
‘C:\Users\<username>\Documents\Visual Studio 2010\Projects\VSMacros80\MyMacros\MyMacros.vsmacros’ is an invalid or inaccessible macro project file
Would you like to recreate it?”
Yes or No

Solved Answer No.
The problem may well be that you are not using C, maybe using D or another drive.

If looking in the wrong place then set the macro recording project to the other project then unload the current project. If necessary move any new created macro project to where you want it then open it. Repeat for samples.

Windows Forms DataBinding displays ‘System.Data.DataRowView’ in text boxes and other controls

ERROR

Windows Forms DataBinding displays ‘System.Data.DataRowView’ in text boxes and other controls

SOLVED

Was a ComboBox databinding pointing at a field no longer in the dataset.

Problem: Dataset with code behind repeatedly needs Run Custom Tool to compile

Maybe source code control put the vb code in the wrong place. The .vb code should be underneath the dataset in show all files, not alongside it.
Backup the current .vb code, then copy it to clipboard and delete it. Then go into the dataset and right-click > view code > then paste the code in there. The newly created .vb code file will now be behind and everything should work from now on.

Problem: Dataset does not generate Insert command

SOLVED today by:

Changing the select statement to SELECT * FROM then pull the fields in again.

Some SQL Server 2005 services are not listed in SQL Server Configuration Manager – Also Red Cross shown in IIS – Server 2003

PROBLEM

  1. Some SQL Server 2005 services are not listed in SQL Server Configuration Manager
  2. Red Cross shown in IIS – Server 2003

SOLVED QUICK

BITS – Background Intelligent Transfer Service may not be registered and may have a startup type of Manual and be Stopped.

regsvr32.exe qmgr.dll
regsvr32.exe qmgrprxy.dll

Then reboot.

SOLVED DETAIL

by external support company. Asked them how they did it. Answer copied here:

It looks like a windows update was responsible for the failure, Steve correctly spotted the fundamental issue which was that the default web site was stopped in IIS.  By attempting to start IIS, this registered an event in the windows logs and I could diagnose the issue from there.

The earlier versions of SQL reporting prior to 2008 relied on IIS to operate and the failure of IIS to start resulted in the missing items in SQL.

Windows update installed a hot fix which altered a file responsible for BITS (the service that enables Windows Update to function), the update applied an updated version of a file for IIS and the file failed to register when it was installed.  IIS was effectively looking for a file which wasn’t present and stopped itself.

By re-registering the file and rebooting, IIS was able to recognise the updated file and the default web site started successfully.  As the default website hosts information referred to by SQL, this caused SQL reporting to re-appear.

An odd one, but then Microsoft updates are probably responsible for a lot of strange behaviour!

Incidentally, while I was on the server, I spotted a string of Windows Desktop Search errors in the log – Windows Desktop Search was given as an update by Microsoft and it is my personal view that the product is poorly designed and disables perfectly good search facilities included within Windows, it looks like it has been clogging your event log with errors for some time now and with both of these things in mind,  I have disabled the Windows Desktop Search.

Anyway, glad SQL & IIS are now working, please let me know if you have any further issues.

SSRS Data Cache in Development

After some effort I found that data in SSRS Development environment was being cached in a files called <ReportName>.rdl.data
So you may be expecting data to change and finding that it is not. To get around this you can do one of the following:

The following error may be due to this cache of data
[rsInvalidExpressionDataType] The Value expression used in textrun ‘InvoiceTitle.Paragraphs[0].TextRuns[0]’ returned a data type that is not valid.

Good luck!