Thursday, June 27, 2013

Visual Studio settings needed for a fault contract to work in WCF Services

Having lost a day to this, I have to write this solution up

In order for the service side exception to pass over to the client side in WCF, two settings in the debugging section of the Visual Studio IDE have to be turned off

1) Just My Code
2) The Exception Assistant

Grrr

Monday, May 13, 2013

The equivalent to InvokeRequired in WPF


In WPF, this was moved out of the Control/UIElement hierarchy, and into the dispatcher.
The equivalent is Dispatcher.CheckAccess and Dispatcher.Invoke.
You should be able to do:
if (someControl.Dispatcher.CheckAccess())
      UpdateUI();
else
    someControl.Dispatcher.Invoke(new Action(UpdateUI));

Friday, March 1, 2013

Windows 8 - Cant see network shares in dialogs for programs running elevated

I had an issue with Visual Studio not seeing projects that were on network shares, and programs not seeing network shares in dialog boxes. The common factor was the programs were running at UAC elevated level

If that happens to you, as it did to me, set the following registry entry

In HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Policies\System, add a DWORD called EnableLinkedConnections and set it to 1 (True)



Tuesday, November 6, 2012

oledbconnection pooling

Or when is a file close not actually a file close?

Had a snippet of code that first opened a file for shared access, then opened it as exclusive once it started a processing run

If the open routine found the file already open, it closed it, disposed the connection object, and set it to null
You would have thought that would have freed the file from use
No luck. The resulting error was less than clear: Couldn't use ; file already in use.

It was still open hiding in the connection pool

Here's the final solution


         If Not DatabaseConnection Is Nothing Then
            If DatabaseConnection .State = ConnectionState.Open Then
                Try
                    DatabaseConnection .Close()
                    DatabaseConnection .Dispose()
                    DatabaseConnection = Nothing
                    System.Threading.Thread.Sleep(TIME_TO_WAIT_STALL)
                    OleDbConnection.ReleaseObjectPool()  <-- Important line!!!!
                Catch ex As Exception

                End Try
            End If
        End If

Friday, April 20, 2012

COM DLLs in Microsoft Access 2010

When developing a COM add in for Access 2010 (and other MS Office products I suspect), when using regasm to register the DLL, throw both the TLB and the CODEBASE flags

Otherwise Access gets lost, and you get automation errors on referencing the COM objects the DLL supports

Friday, December 16, 2011

Parsing file paths

Since I can't seem to remember these functions that work on a full path with filename:

System.IO.Path.GetFileName - extracts the filename part with extensions and loses the leading path
System.IO.Path.GetDirectoryName - extracts the leading path and loses the filename with extension
System.IO.Path.GetExtension - extracts just the extension from the path

Tuesday, December 13, 2011

Handling autonumber/key fields in a dataset

Problem: If you want to use a dataset and dataadapter exclusively for managing the updates to a table, and the table was designed with an autonumber field as as the primary key, you have to fill in the primary key after the record is inserted.

Solution: The insert statement of the data adapter can't contain the primary key column. You let the underlying data provider fill in the key value. I have taken two solution routes, but they do the same thing. After inserting the row, I updated the row in the mainline code with the new key value in the datagridview and the datatable. My second, more elegant solution, was to attach a row updated event handler to the data adapter. I then fill in the primary key value in the data row. The datagridview picked up the update automatically.


 Private Sub Add_Autonumber(s As Object, e As System.Data.OleDb.OleDbRowUpdatedEventArgs) Handles TViewAdapter.RowUpdated
        If e.StatementType = StatementType.Insert Then
            Dim NewID As Integer
            Dim idCMD As New OleDbCommand("SELECT @@IDENTITY", e.Command.Connection)
            NewID = idCMD.ExecuteScalar
            e.Row("ID") = NewID
        End If
    End Sub

SELECT @@IDENTITY is specific to the oledbconnection for Access databases. SQL has a similar statement. You must do this on the connection that generated the autonumber, hence the command references the rowupdated argument's connection that was passed in