Error: The multi-part identifier could not be bound. when using a function and alias

You cannot pass parameters to functions across a JOIN.

http://stackoverflow.com/questions/4123413/the-multi-part-identifier-columnname-could-not-be-bound

Use APPLY:

SELECT ROW_NUMBER() OVER(ORDER BY x.Year DESC, x.Month) AS ID,
x.*,
fr.*
FROM (
SELECT Client,
Month(TimeStamp) As Month,
Year(TimeStamp) As Year,
Day(TimeStamp) As Day,
(dateadd(yy,(Year(TimeStamp)-1900),0)
+ dateadd(mm,Month(TimeStamp)-1,0)
+ Day(TimeStamp)-1) AS XTimeStamp,
Sum(KwTop) As KwTop,
Sum(KwHeap) as KwHeap,
Sum(KwLow) As KwLow
FROM Ori.vEnergyUnion
GROUP BY
Year(TimeStamp), Month(TimeStamp),Day(TimeStamp), Client
) x
OUTER APPLY
(
SELECT *
FROM Finance.fGetRates(x.XTimeStamp) Fr
WHERE fr.ValidFrom = x.XTimeStamp
) fr

Visual Studio unable to copy file because it is being used by another process

 

To try and get around this I closed VS and re-opened it. Still the same problem. In this scenario I then closed it again and on inspection of Task Manager I found that devenv was still running as a process (it was not in Applications). After Killing this extra devenv my computer blue screened. After restarting itself I was able to open my solution and build.

Could not load file or assembly … or one of its dependencies. The module was expected to contain

Possibly the reference is an executable program. Solution is:

  1. Right-click on project not building properly – Project Build Order
  2. Check that the reference is higher in the list
  3. If not then use Dependencies tab to add the required dependency which changes the Build Order

Similar to http://wp.me/p17IS4-dh

 

Entity Framework – Inheritance/Association – including Troubleshooting and comment on verbose SQL

See this video on Model Table Per Type

http://msdn.microsoft.com/en-us/data/cc765425.aspx

  1. Update Model from Database – Add Table
  2. Right-click Entity Add Inheritance
  3. Error 11009: Property ‘<>’ is not mapped
  4. Right-click Entity > Table Mapping > re map missing
  5. Running transformation: A member named ID cannot be defined in class DerivedClass. It is defined in ancestor class ParentClass.
  6. Delete it from DerivedClass

Error 3027: No mapping specified for the following EntitySet/AssociationSet – TableATableB

Error 11008: Association TableATableB is not mapped
EF is not expecting both a Foreign Key relationship and an association, see note at top of: http://msdn.microsoft.com/en-us/library/bb738488.aspx
Delete the association

Existing queries may then break as the Entity type no longer exists. So in my case Products is base type PadMain inherits from this. Used to have PadMains now PadMain EntityName is Products, so query on PadMains needs to change. From/To:

From b In context.PadMains
From b in context.Products1.OfType(Of PadMain)()

However if PadMain has subtypes then the SQL generated is verbose. If table is separated out in SQL then you just want the base table. If a field will appear in multiple related child tables then you will get duplications. In this scenario this is a major disadvantage of Entity Framework. Hopefully it will be fixed in future. For now I have removed my inheritance.

The file or directory is corrupt and non-readable. (possibly in Visual Studio and TFS Build broke)

Problem found

<drive>:\<folder> is not accessible    The file or directory is corrupt and non-readable.The file or directory is corrupt and non-readable. The file or directory \<folder> is corrupt and unreadable.    Please Run the Chkdsk utility.

Was causing build to fail. Some how system had created a badly named file RoqteOpsData where the q should have been a u

Resolution

http://support.microsoft.com/kb/176646

Attempt to repair the damaged file, folder or file system index using Chkdsk. To do so, follow these steps:

  1. Click Start, and then click Run.
  2. In the Open box, type chkdsk /f <drive>:,   where <drive> is the letter of the drive on which the damaged file,   folder or file system index exists.
  3. Click OK.

Click-Once – The application binding data format is invalid

 

Remove files from %userprofile%\AppData\Local\Apps\2.0\

WPF freezes when dragging data source onto a Page or Window

Problem

WPF freezes when dragging data source onto a Page or Window

Possible Solution

Inspect datasource and see if it has a child table underneath it. Does this child expand to show the parent table again. If so then you may be creating an infinite loop when dragging the datasource onto the Page or Window

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.


&lt;TestMethod()&gt; _

Public Sub FillTest()

Dim dsValue As New &lt;datasetname&gt;
Dim target As New &lt;dataset&gt;Helper(dsValue)
For Each col As DataColumn In dsValue.&lt;tablename&gt;.Columns
If col.Ordinal &lt; 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.&lt;tablename&gt;.PrimaryKey = Nothing
Dim aList = dsValue.&lt;tablename&gt;.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: 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: