zaterdag 9 oktober 2021

In Lightroom Classic, select photos without a flag

The other day I was judging pictures in Lightroom. As usual, most of them were not as good as expected and could be thrown away. Problem: I had only flagged the ones to keep (using 'P'). 

If I had used 'X' for the ones to reject, it would have been easy to actually delete them. 'Ctrl+Backspace' removes all rejected photos. But what to do now? 

 Then I saw the solution: ordering. 
  1. In the toolbar below, select ordering on 'Choice' - this is based on the flag you assigned. 
  2. Then scroll to the first non-flagged picture. 
  3. Shift-select until the end. 
  4. Delete.

dinsdag 13 december 2016

How to express an expected call on a Moq mock in the memberdata for an XUnit Theory.

In XUnit you can use the [Theory] attribute to run the same test against a set of different parameters. Moq allows you to specify expectations on which methods of a mocked interface are called, with the Verify method. Recently, I wanted to combine these two techniques to be able to convey the expectation along with the other test parameters to the XUnit Theory. It took me a little thought to get this right. The trick is in casting the expected call (usually an Action<T>) to an Expression<Action<T>>. That is done in the gist below.

dinsdag 11 oktober 2016

Simply check logged messages in .NET Core and Moq

The Microsoft.Extensions.Logging framework in ASP.NET Core is very useful for logging, but it can be somewhat verbose to check logged messages in your unit tests. Because the methods you use for logging (LogInformation, LogWarning etc.) are all extension methods, you cannot verify calls on them. You can verify calls to the Log method. But it took me some time to find out what the exact check should be. So I wrapped that knowledge into a utility method VerifyLog, in this Gist: Happy logging!

woensdag 20 juli 2016

ASP.NET Core Middleware pipeline 'Status code cannot be set, response has already started.'

ASP.NET Core has this beautiful concept of a pipeline of Middleware. See the introduction if you're not familiar with it.

In this tutorial you see you can always expect a 'next' to be available to invoke. But what if you have only one piece of middleware, or you are at the end of the pipeline? What is 'next' then?

The magic is in ApplicationBuilder, in the Build method:

1:      public RequestDelegate Build()  
2:      {  
3:        RequestDelegate app = context =>  
4:        {  
5:          context.Response.StatusCode = 404;  
6:          return Task.FromResult(0);  
7:        };  
8:        foreach (var component in _components.Reverse())  
9:        {  
10:          app = component(app);  
11:        }  
12:        return app;  
13:  }  

As you can see, a default RequestDelegate is appended to the end of the pipeline. It sets the StatusCode to 404 (meaning 'not found').

Now, where does the error in the title come from? It happens when you write to the httpContext.Response, and call next.Invoke(context). If none of the middleware components short-circuits the pipeline, eventually the 404 RequestDelegate above will be called. And that is where the problem starts: because you already started a response (leading to Response.HasStarted = true), you are not allowed to set the StatusCode anymore.

And what is the solution?


General rule of thumb: if you write to the Response in middleware X, end the pipeline (don't call next).

If you think about it this makes sense: X apparently knows the right response, so the request can be considered handled. Of course, the previous middleware components still get called on the way back through the pipeline. They also should not try to set the StatusCode.

Should you set the StatusCode yourself?


Not when the response is OK, because that is the default value of StatusCode. If your middleware decides that another response is appropriate, it should:
  • first set the StatusCode to an appropriate value (for example 201, Created)
  • then write to the Response
  • end the pipeline (don't call next)

woensdag 23 december 2015

Advanced pattern matching in SQL Server

This week I had the privilege of extracting times from a varchar column. This had to be done in T-SQL, which as you probably know does not support regular expressions. So I could only use PATINDEX, which is a lousy replacement for real regexes. Nevertheless, I found a solution that you may find useful.

The code is below, I will start with an explanation of the idea.

The problem at hand:

  1. A varchar column that contains a start time and end time, separated by a dash or a space.
  2. Times can be at the start, the middle or the end.
  3. The text may contain no time, just a start time, just an end time or both.
  4. Time can be denoted with three or four digits, with or without a leading zero for times before 10am.
  5. Time can be denoted with or without a dot as separator between hours and minutes.
  6. The dash may be surrounded by spaces, either before, after or both.
This is a lot of variation, that leads to many patterns to check. This could be done in a very ugly case statement. I don't like ugly statements so I came up with a Common Table Expression (CTE) holding all the possible patterns. This CTE contains the patterns from longest to shortest, so the first match that is found is always the most specific. Beside the pattern, the CTE contains a decription (just for human readability) and two numbers (startLenght and endLength) that help in finding the actual time piece from the start of the pattern. (PATINDEX just returns the position where the pattern is found. Nothing like multiple matching groups that you like so much about regex...)

Then I join the patterns CTE with the table that contains the text to be searched, and perform a PATINDEX for every combination. That results in zero, one or more matches per text. If there are more than one, the most specific will have row number 1. So then I filter on ROW_NUMBER() = 1.

From there is it a matter of smart substringing and converting.

I resolved the variations following from problems steps 5 and 6 by applying the REPLACE function for each of the variations. This could also have been solved by adding separate patterns. If you decide to do that, you will probably also need an extra index number for the position of the end-time in the pattern.

The CTE 'UnitTests' is what the name suggests: a list of test notes to retrieve the times from, including the correct answers.

The environment

SQL Server 11.0 SP2, aka SQL Server 2012

The code

 DECLARE @ThreeDigitTimePattern nvarchar(20) = '[0-9][0-5][0-9]';  
 DECLARE @FourDigitTimePattern nvarchar(20) = '[0-2]' + @ThreeDigitTimePattern;   
   
 WITH   
 StartEndTimePatterns AS  
 (  
     -- Patterns in order of matching length. This makes sure that the longest match is the first match.  
     SELECT patternID, startLength, endLength, pattern, [description]  
     FROM  
     (  
         VALUES   
          (1, 4, 4, '%[^0-9,-]' + @FourDigitTimePattern + '[- ]' + @FourDigitTimePattern + '[^0-9]%', 'FourDigitTime/FourDigitTime/MiddleOfSentence: blabla 1135-1345 blabla')  
   
         , (2, 3, 4, '%[^0-9,-]' + @ThreeDigitTimePattern + '[- ]' + @FourDigitTimePattern + '[^0-9]%', 'ThreeDigitTime/FourDigitTime/MiddleOfSentence: blabla 735-1145 blabla')  
   
         , (3, 4, 3, '%[^0-9,-]' + @FourDigitTimePattern + '[- ]' + @ThreeDigitTimePattern + '[^0-9]%', 'FourDigitTime/ThreeDigitTime/MiddleOfSentence: blabla 735-945 blabla')  
   
         , (4, 3, 3, '%[^0-9,-]' + @ThreeDigitTimePattern + '[- ]' + @ThreeDigitTimePattern + '[^0-9]%', 'ThreeDigitTime/ThreeDigitTime/MiddleOfSentence: blabla 735-945 blabla')  
   
         , (5, 4, 0, '%[^0-9,-]' + @FourDigitTimePattern + '[^0-9]%', 'FourDigitTime/null/MiddleOfSentence: blabla 1135 blabla')  
   
         , (6, 3, 0, '%[^0-9,-]' + @ThreeDigitTimePattern + '[^0-9]%', 'ThreeDigitTime/null/MiddleOfSentence: blabla 735 blabla')  
   
         , (7, 0, 3, '%-' + @ThreeDigitTimePattern + '[^0-9]%', 'null/ThreeDigitTime/MiddleOfSentence: blabla -735 blabla')  
   
         , (8, 0, 4, '%-' + @FourDigitTimePattern + '[^0-9]%', 'null/ThreeDigitTime/MiddleOfSentence: blabla -735 blabla')  
     ) as T(patternID, startLength, endLength, pattern, [description])  
 )  
 , UnitTests AS   
 (  
     -- A list of examples for unittesting.  
     -- First step: remove '.', and extra spaces around the dash.  
     SELECT testID, [description], '__' + Replace(Replace(Replace(NoteText, '.', ''), '- ', '-'), ' -', '-') + '__' as NormalizedNoteText, CAST(startTime_ref as time) as startTime_ref, CAST(endTime_ref as time) as endTime_ref  
     FROM  
     (  
         VALUES (1, 'ThreeDigitTime/ThreeDigitTime/WholeSentence', '735-945', '7:35', '9:45')  
         , (2, 'ThreeDigitTime/FourDigitTime/WholeSentence', '735-1145', '7:35', '11:45')  
         , (3, 'FourDigitTime/FourDigitTime/WholeSentence', '1135-1345', '11:35', '13:45')  
         , (4, 'ThreeDigitTime/ThreeDigitTime/StartOfSentence', '735-945 blabla', '7:35', '9:45')  
         , (5, 'ThreeDigitTime/FourDigitTime/StartOfSentence', '735-1145 blabla', '7:35', '11:45')  
         , (6, 'FourDigitTime/FourDigitTime/StartOfSentence', '1135-1345 blabla', '11:35', '13:45')  
         , (7, 'ThreeDigitTime/ThreeDigitTime/MiddleOfSentence', 'blabla 735-945 blabla', '7:35', '9:45')  
         , (8, 'ThreeDigitTime/FourDigitTime/MiddleOfSentence', 'blabla 735-1145 blabla', '7:35', '11:45')  
         , (9, 'FourDigitTime/FourDigitTime/MiddleOfSentence', 'blabla 1135-1345 blabla', '11:35', '13:45')  
         , (10, 'ThreeDigitTime/ThreeDigitTime/EndOfSentence', 'blabla 735-945', '7:35', '9:45')  
         , (11, 'ThreeDigitTime/FourDigitTime/EndOfSentence', 'blabla 735-1145', '7:35', '11:45')  
         , (12, 'FourDigitTime/FourDigitTime/EndOfSentence', 'blabla 1135-1345', '11:35', '13:45')  
         , (13, 'ThreeDigitTime/null/WholeSentence', '735', '7:35', null)  
         , (14, 'FourDigitTime/null/WholeSentence', '1135', '11:35', null)  
         , (15, 'ThreeDigitTime/null/StartOfSentence', '735 blabla', '7:35', null)  
         , (16, 'FourDigitTime/null/StartOfSentence', '1135 blabla', '11:35', null)  
         , (17, 'ThreeDigitTime/null/MiddleOfSentence', 'blabla 735 blabla', '7:35', null)  
         , (18, 'FourDigitTime/null/MiddleOfSentence', 'blabla 1135 blabla', '11:35', null)  
         , (17, 'ThreeDigitTime/null/EndOfSentence', 'blabla 735', '7:35', null)  
         , (18, 'FourDigitTime/null/EndOfSentence', 'blabla 1135', '11:35', null)  
         , (19, 'TooLongNumber/null/WholeSentence', '73545', null, null)  
         , (20, 'TooLongNumber/null/StartOfSentence', '73545 blabla', null, null)  
         , (21, 'TooLongNumber/null/MiddleOfSentence', 'blabla 73545 blabla', null, null)  
         , (22, 'TooLongNumber/null/EndOfSentence', 'blabla 73545', null, null)  
         , (23, 'LeadingZero/ThreeDigitTime/StartOfSentence', '0852-912 blabla', '08:52', '9:12')  
         , (24, 'LeadingZero/ThreeDigitTime/MiddleOfSentence', 'blabla 0852-912 blabla', '08:52', '9:12')  
         , (25, 'LeadingZero/ThreeDigitTime/EndOfSentence', 'blabla 0852-912', '08:52', '9:12')  
         , (26, 'Point/ThreeDigitTime/StartOfSentence', '8.52-912 blabla', '8:52', '9:12')  
         , (27, 'Point/Point/StartOfSentence', '8.52-10.12 blabla', '8:52', '10:12')  
         , (28, 'null/ThreeDigitTime/StartOfSentence', '-912 blabla', null, '9:12')  
         , (29, 'null/ThreeDigitTime/MiddleOfSentence', 'blabla -912 blabla', null, '9:12')  
         , (30, 'null/ThreeDigitTime/EndOfSentence', 'blabla -912', null, '9:12')  
         , (31, 'null/FourDigitTime/StartOfSentence', '-1012 blabla', null, '10:12')  
         , (32, 'null/FourDigitTime/MiddleOfSentence', 'blabla -1012 blabla', null, '10:12')  
         , (33, 'null/FourDigitTime/EndOfSentence', 'blabla -1012', null, '10:12')  
         , (34, 'ThreeDigitTimeWithSpace/FourDigitTime/MiddleOfSentence', 'blabla 735 -1145 blabla', '7:35', '11:45')  
         , (35, 'PointAndLeadingZero/ThreeDigitTime/StartOfSentence', '08.52-912 blabla', '8:52', '9:12')  
         , (36, 'PointAndLeadingZero/Point/StartOfSentence', '08.52-10.12 blabla', '8:52', '10:12')  
         , (37, 'Point/ThreeDigitTime/MiddleOfSentence', 'blabla 08.52-912 blabla', '8:52', '9:12')  
         , (38, 'Point/Point/MiddleOfSentence', 'blabla 08.52-10.12 blabla', '8:52', '10:12')  
         , (39, 'ThreeDigitTime/LeadingZero/StartOfSentence', '852-0912 blabla', '08:52', '9:12')  
         , (40, 'ThreeDigitTime/LeadingZero/MiddleOfSentence', 'blabla 852-0912 blabla', '08:52', '9:12')  
         , (41, 'ThreeDigitTime/LeadingZero/EndOfSentence', 'blabla 852-0912', '08:52', '9:12')  
         , (50, 'PracticeTest', 'pkno 09.20-10.00 ASA 2', '9:20', '10:00')  
         , (51, 'PracticeTest', 'PVAT 08.09-9.08/2', '8:09', '9:08')  
         , (52, 'PracticeTest', 'PVVO 08.14-8.52/1', '8:14', '8:52')  
         , (53, 'PracticeTest', 'ppch 0847-0915', '8:47', '9:15')  
         , (54, 'PracticeTest', 'pver 856-0945', '8:56', '9:45')  
         , (55, 'PracticeTest', 'PNCH 0900-0945', '9:00', '9:45')  
         , (56, 'PracticeTest', 'PKCH ASA 2 9.53-10.10%0D%0A', '9:53', '10:10')  
         , (57, 'PracticeTest', 'pgyn -1609 +', null, '16:09')  
   
     ) as T(testID, [description], NoteText, startTime_ref, endTime_ref)  
 )  
   
 , StartEndTimeIndices as   
 (  
     -- Second step: find the position where the pattern is found  
     select t.testID, t.[description] as TestDescription, NormalizedNoteText, p.patternID, p.startLength, p.endLength, PATINDEX(p.pattern, NormalizedNoteText) as patternFoundAt, startTime_ref, endTime_ref  
     from UnitTests t, StartEndTimePatterns p  
 )  
 , StartEndTimeOrderedIndices as  
 (  
     -- Third step: filter the rows where any pattern matched, add a row_number  
     select testID, TestDescription, NormalizedNoteText, patternID, startLength, endLength, patternFoundAt, startTime_ref, endTime_ref  
     , ROW_NUMBER() OVER (PARTITION BY testID ORDER BY testID, patternID asc, patternFoundAt asc) as rownumber  
     from StartEndTimeIndices  
     where patternFoundAt > 0  
 )  
 , StartEndTimeStrings as  
 (  
     -- Fourth step: use only the first matches (those are the longest); extract the start- and endTime based on their lengths  
     select testID, patternID, patternFoundAt, NormalizedNoteText,   
         startLength, IIF(startLength > 0, SUBSTRING(NormalizedNoteText, patternFoundAt + 1, startLength), null) as startTime, startTime_ref,   
         endLength, IIF(endLength > 0, SUBSTRING(NormalizedNoteText, patternFoundAt + 1 + CAST(startLength as BIT) + startLength, endLength), null) as endTime, endTime_ref  
         from StartEndTimeOrderedIndices  
     where rownumber = 1  
 )  
 , StartEndTimeIntegers as  
 (  
     -- Fifth step: cast the start- end endTime to integers if possible; makes for easy calculation of the time in the next step.  
     select testID, patternID, patternFoundAt, NormalizedNoteText,   
         startLength, IIF(ISNUMERIC(startTime) = 1, CAST(startTime as INT), null) as startTime, startTime_ref,   
         endLength, IIF(ISNUMERIC(endTime) = 1, CAST(endTime as INT), null) as endTime, endTime_ref  
         from StartEndTimeStrings  
 )  
 , StartEndTimes as  
 (  
     -- Sixth step: calculate time values from the integers.  
     select testID, patternID, patternFoundAt, NormalizedNoteText, startLength, endLength  
     , IIF(startTime is not null AND startTime/100 < 24 AND startTime % 100 < 60, TIMEFROMPARTS(startTime / 100, startTime % 100, 0, 0, 0), null) as startTime, startTime_ref  
     , IIF(endTime is not null AND endTime/100 < 24 AND endTime % 100 < 60, TIMEFROMPARTS(endTime / 100, endTime % 100, 0, 0, 0), null) as endTime, endTime_ref  
     from StartEndTimeIntegers  
 )  
 -- Check whether the computed times are equal to the reference times from the unittests.  
 -- Ideally, this yields no results :-)  
 select * from StartEndTimes  
 where   
 (  
     (startTime is null and startTime_ref is not null)  
 or    (startTime is not null and startTime_ref is null)  
 or    (startTime != startTime_ref)  
 or    (endTime is null and endTime_ref is not null)  
 or    (endTime is not null and endTime_ref is null)  
 or    (endTime != endTime_ref))  
   

dinsdag 5 juni 2012

Typical Open Source Java experience

Today I decided to give Jaspersoft a go. Read about it, seems to be good, all new ‘Jaspersoft Studio’ waiting to be tested. Installation is a breeze (that is not so typical, that’s excellent).

So I started it. Nice splash screen. And a welcome screen. With a cheat sheet for setting up your first data connection. There comes the familiar part. It first tells me where to find the repository with data connections and how to create a new one. And then – we’re still in the very first cheat sheet, should be a simple start:

“Set the correct JDBC driver name. You will have to add the jar(s) of the driver in order to be able to connect to your database. When done, press Test to test your connection.” Besides that you have to figure out the correct JDBC URL, which is not even mentioned in the cheat sheet.

What????? What is the correct JDBC driver name for my SQL Server 2008R2 database? What jar(s) do I need, and where should I add them?

OK, I’m a programmer (albeit not in Java) so I will probably figure it out. Especially since I had to do the same for Talend Open Studio for Data Integration a while ago. So I also know that in order to make the jtds SQL Server driver work with Windows Integrated Security, I should (and did) install the Studio in a path without spaces (so the default ‘Program Files’ is not good).

But hey, was it too difficult to put some frequently used drivers (SQL Server is hardly exotic, is it?) in the installer and be able to construct the right driver name with some clever dropdowns? That’s what I’m used to in Visual Studio, even in the (also free) express editions.

So, tip to all the major open source providers to flatten the learning curve: If you need a connection to a database to do anything useful, pre-configure the most used ones (Oracle, SQL Server, MySQL – should cover many cases already), so the first time user only needs to fill in the servername, databasename, username and password. When he has played around a little, he will be much more forgiving if he has to configure a JDBC driver for his more exotic databases.

[… trying out further …]

Allright, established a data connection to my database, works. Created a new report (based on ‘Coffee’), specified a query on a simple table: works. Preview the report: ClassDefNotFound, apparently on some class having to do with Groovy.

Selected Java as the language for the report, instead of Groovy. Preview the report: NullPointerException. How am I supposed to make this work, if I get two exceptions out of the box? I have not even programmed a statement of Java myself. I’m disappointed. Yet, I’ll give iReport a try to see if that is more mature.

[… trying out iReport …]

OK, works. I still had to add the jtds driver and specify the right JDBC URL, but by now I know what to do. This time, the report still didn’t work, but iReport is indeed more mature and robust. It stated: report has no pages.

Aha, could it be that the table that I query is empty? Check, yes it is. Could that be the cause of the nullpointerreference in JasperSoft Studio? Fill the table, start JSS – no error anymore!

OK. First thing to do with new code: Create unittests for the regular and the edge cases. A report with no data is an edge case. Should have been tested.

To end positively: Two report designers, both free and I managed to squeeze out simple reports on my own table in one day. Not bad after all – for free products.

donderdag 6 oktober 2011

IUpdatable, what is it supposed to do?

I’m setting up an OData service by means of WCF Data Services. The DataContext publishes a list of BloodPressureMeasurements. These are queried from a more generic model in a lower tier, which in turn is persisted somewhere. So in essence I work with a model specific for the service, hence we call it the ServiceModel.

To publish the BPM’s, the DataContext contains a

public IQueryable<BloodPressureMeasurement> BloodPressureMeasurements

and in the get method I take care of the mapping from the generic model to the ServiceModel. That was the relatively easy part.

Now I want to enable adding new BPM’s. For the service to accept that, the DataContext has to implement IUpdatable. I have found several examples using either Entity Framework or LINQ to SQL. In both cases, most of the actual ‘IUpdatable-work’ is offloaded to the underlying techniques. And neither the official documentation nor the examples explain why IUpdatable is even there, and what the implementation should accomplish.

I’ve started implementing it nevertheless, and that made me discover exactly that: what should it do? In essence, when the data has to be updatable, WCF Data  Services needs a place to collect all the changes, whereafter it can ask to save all those changes (or discard them). So the IUpdatable implementation should provide some sort of delta-collection. If you get that, it becomes more clear what each of the methods should do.

And while experimenting with IUpdatable and writing this blog, I finally found a very valuable resource on the Astoria Team Blog (now WCF Data Service Team Blog, why didn’t I look there earlier?) Read, it’s a good explanation.

I chose a very simple solution: two List<BloodPressureMeasurement> variables, one for additions, one for deletions (editing is not permitted in our case). Since BPM objects are small POCO’s, I can send the objects themselves around. If you instead want to move around references to the objects, you have to implement ResetResource and ResolveResource.

Furthermore, there are no master-detail collections to be taken care of, so I could also leave out SetReference, Add- & RemoveReferenceToCollection.

After implementing I discovered one more thing that might be handy to know: If you implement a ChangeInterceptor on your service, I will be called in this sequence:

  1. all the methods on IUpdatable (as implemented by the context) for assembling the delta
  2. your ChangeInterceptor
  3. IUpdatable.SaveChanges

Happy Data Servicing!

donderdag 1 september 2011

Rijtje records genereren in SQL Server?

Hier is een recursieve oplossing. Geinspireerd op de code van deze site: http://mhimu.wordpress.com/2009/05/07/sql-dynamic-date-range-number-range-in-oracle-sql-server-and-db2400/. Daar doet de schrijver het met dateranges.

NB: Recursie kent een grens. In SQL Server default 100 stappen, met OPTION (MAXRECURSION n) kun je een andere waarde kiezen. De Books Online over MAXRECURSION:

MAXRECURSION number

Specifies the maximum number of recursions allowed for this query. number is a non-negative integer between 0 and 32767. When 0 is specified, no limit is applied. If this option is not specified, the default limit for the server is 100.

When the specified or default number for MAXRECURSION limit is reached during query execution, the query is ended and an error is returned.

Because of this error, all effects of the statement are rolled back. If the statement is a SELECT statement, partial results or no results may be returned. Any partial results returned may not include all rows on recursion levels beyond the specified maximum recursion level.

For more information, see WITH common_table_expression (Transact-SQL).

In dit voorbeeld maak ik er een tabelletje met users mee, maar je kunt zelf vast ook andere opties verzinnen.

WITH IntRange (i) AS
(
SELECT 1 as i
UNION ALL
SELECT (1 + i) as i FROM IntRange WHERE i < 150
)
SELECT i from IntRange
OPTION (MAXRECURSION 150)
GO

WITH IntRange (i) AS
(
SELECT 1 as i
UNION ALL
SELECT (1 + i) as i FROM IntRange WHERE i < 150
)
SELECT i as ID, 'user_' + CONVERT(varchar(3), i) as Username, 'password_' + CONVERT(varchar(3), i) as Pwd
INTO #users
from IntRange
OPTION (MAXRECURSION 150)
GO

SELECT * FROM #users
GO

donderdag 24 maart 2011

VS2010 Settings not updating

Nitty gritty detail, could drive you mad.

In Visual Studio 2010 I have a C# Windows application. I changed the connectionstring for the database in the app.config file. Later, I opened the Properties | Settings. VS noticed that the app.config had changed and suggested to change the settings accordingly. Yes, VS, I would like that, thank you. 

But then (as it turned out much later), it does NOT change the default setting in the Settings.Designer.cs, in the

[global::System.Configuration.DefaultSettingValueAttribute(....)]

When you simply run the application, it will read app.config (or actually the values that were copied to <applicationname>.exe.config). But when you - a I did - use it's classes from a Test project, it will only use the default setting.

Solution: open the editor in the Properties | Settings designer, test your connection (if you want to), and then save the setting. Now VS sees that you altered it, and adjusts the .cs file accordingly.

donderdag 24 februari 2011

Talend SSO, NTLM to SQL Server 2008

Fresh laptop, let's re-install the Talend Open Studio for some testing. I usually work with SQL Server through Integrated Authentication (automatically logging on with your Windows account). Not so easy with Talend though. I finally got it to work by:

- downloading jTDS 1.2.5 from http://sourceforge.net/projects/jtds/files/jtds/

- extracting it, navigate to subfolder x86\SSO

- copy ntlmauth.dll to Windows\System32 (could be anywhere in your PATH if I understood several posts well)

- restart TOS

- leave username and password in the DbConnection settings empty

- in ServerName just the name of my computer (no instance name appended)

And then, ole, it worked!

dinsdag 22 februari 2011

Can you express order in UML?

Today a collegue asked me if he could express order in a class diagram. Well, you can't.

Situation: class QuestionList, composition of multiple Question items. Actually, each question in the QuestionList is of a specific subtype of Question. How to express that the Question items should be in a specific order?

The Association in the class diagram offers the attribute 'ordered' in the source or target role. This leads to the first set of classes in the diagram below. However, you cannot infer from it that in the QuestionList, an Object of type FirstQuestion should be first, and an object of type SecondQuestion second. Or even that you should have one of each.

Next option is to use Objects instead of Classes. As in the second diagram. It shows that MyQuestionList consists of one object of type FirstQuestion and one of type SecondQuestion, but still no order.

Classes and Objects

The problem is that the order in which questions are to be asked is a dynamic feature, not a static one. And since a Class Diagram is for static constructions, you cannot express order very well. So we go on to a more dynamic diagram: Collaboration. In this diagram you could use the role binding to state which type of question fulfills which role. And then read 'role' as 'being the first question' and so on. See the diagram below. It still isn't machine processable, but at least you have modelled it.

I'm open to better solutions.

Collaboration

donderdag 17 februari 2011

Oops, Visual Studio 2010 installed SQL Server Express

Fresh machine! Fresh Win7 pro!

I already loaded SQL Server 2008 R2.
Next is Visual Studio 2010. Full install or custom install? Well, what the h*, let's do a full install.

Oops, I did not anticipate that the full install of an IDE includes an RDBMS. My mistake I guess.

So I ended up with two SQL Server instances, one for 2008 R2, one for Express. Fresh machine becomes mess machine. In just 2 hours.

Problem is: When you re-run VS setup, it offers to add/remove features, but SQL Server Express is NOT one of those features. The uninstall team at MS clearly did not count on an RDBMS being included either. On to Add/Remove Programs (which, on a side-note, in Dutch is called 'Software', which is still an English noun...). No such entry as 'Microsoft SQL Server Express'. Hmmm.

But hey, I found out: In Add/Remove Programs find the entry 'Microsoft SQL Server 2008'. Select it. Choose 'Uninstall/Change'. It opens a window, choose 'Remove'. After some more steps you will be presented the choice which instance you would like to remove. Choose SQL Server Express. In the selectionlist for individual features do not select the Shared Features (you'll want to keep them for your 2008 R2 instance). Next, next, finish.

Win7 may complain about the uninstall not being compatible or something like that. Ignore it. It has uninstalled properly, as you can check by not seeing the SQL Server Express services in Run | services.msc any more.

dinsdag 4 januari 2011

VMWare upgrade requires expert SQL Server knowledge

Today our System Administrator wanted to upgrade the VMWare server (aka vCenter Server) to version 4.1, thereby reusing the existing management database. Our SA is no database expert, and he shouldn't need to be. VMWare thinks otherwise.

To set the scene: the new version is 4.1, which requires a new server because the server OS has to be 64bit. The existing management database is called 'VMware' and located on a SQL Server 2005 instance. On a previous install the SA was instructed to create a 'VMware' user, and create several tables under that account. And therefore automatically in the 'VMware' schema (which in SQL Server is not exactly the same as a user). So in the VMWare database about 1/3 of the objects lives in the dbo schema, and the rest in the VMware schema. While running the upgrade that leads to the following error:

"
Setup found that multiple schemas exist in the database. Please the remove extra schemas before continuing."

Apparently, VMWare knows that such a thing may have happened before, and have written an instruction to solve it. It's here. Unfortunately, it is not enough to make it work. It took us two hours, so I write it down here to save you that time. And forget about the 8 steps on the aforementioned page.

  1. Make a backup from the original VMware database, before even starting the upgrade process.
  2. Start SQL Server Management Studio, and open a new Query Window.
  3. Execute: USE VMware;
  4. Execute: SELECT schema_id from sys.schemas where name = 'VMware';
  5. Execute: SELECT 'ALTER SCHEMA dbo TRANSFER ' + sys.objects.name from sys.objects where sys.objects.type in ('U', 'V', 'P') and sys.objects.schema_id = ;
  6. Copy the result of step 5 from the result window to the query window, and execute this list of statements. You now have moved everything from the VMware schema to the dbo schema.
  7. I suppose you still want to use the VMware user to perform the upgrade, so you have to make sure that when you do, the upgrade scripts doesn't create new objects in the associated VMware schema again. It appears that SQL Server Management Studio lets you set the default schema for user VMware in the properties window. You can change it, but it won't remember the change... So, back to scripting:
  8. Execute: DROP SCHEMA VMware;
  9. Execute: DROP USER VMware;
  10. Execute: CREATE USER VMware WITH DEFAULT_SCHEMA = dbo;
  11. Finally, we came across another error in the upgrade log: "Error while upgrading: ERROR [42000] [Microsoft][SQL Native Client][SQL Server]CREATE INDEX failed because the following SET options have incorrect settings: 'ARITHABORT'. Verify that SET options are correct for use with indexed views and/or indexes on computed columns and/or query notifications and/or xml data type methods." Well, if you know that, VMware, include a statement in the upgradescript to make sure the setting is correct. But hey, we'll do it ourselves:
  12. Execute: SET ARITHABORT ON;
  13. Make another backup of the VMware database, prior to starting the upgrade.
  14. OK, by now the vCenter Server setup worked through the database upgrade script (using the VMware login for access to the database). I hope it does for you as well.

woensdag 27 oktober 2010

TDM, a history of Impact

Today I came across the acronym 'TDM'. I've worked in the field of healthcare IT for quite some time now, and I was sure I had heard it before. Just could not find the right drawer in my head.

From the context and some other drawer in my head I derived that it had to do with an integration platform and message brokering. Enter Google. Now this is old stuff, so I had to look a bit further. The answer:

TDM is an acronym for Transaction Distribution Broker, and it is a communication broker created by CAI - Century Analysis Inc. I think it was then already bundled with the (then BAZIS, now iSoft) ZIS (Hospital Information System, but then the Dutch acronym). In 1998 it was transformed to Impact, which again was bundled with iSoft ZIS to make it communicate with the outside world.

By now, CAI does not exist anymore. It was acquired by New Era of Networks Inc. (NEON) in 1999. NEON was acquired by Sybase in 2001. Sybase now offers the product under the name "e-Biz Impact".

Thanks to Ric Cross for providing the meaning of TDM. He knows a lot more about it (I quote):

Transaction Distribution Management - There was no binary by that name in the product suite ... just a marketing name to provide some clue as to the products purpose. A "Distributed Computing Environment" (DCE) based "POSIX compliant" message broker.

At the time the term was "Message Oriented Middleware" TDM had several pieces that worked together, the Broker Server Manager (BSM) the Store and Forward Manager (SFM) and message client/servers, we called them Adaptive Interface Modules (AIMs). The concept "Common Services" was the prevalent and primary underpinning of the functionality of the suite. The TDM client GUI was in my biased opinion one of the better parsers of the day. You used the GUI to craft "Production Objects", basically, under the covers C++ class structures for the proprietary "Object Definition Language" (ODL). The ""Production Object" consisted of an inbound definition and the outbound definition. The Outbound Rules were where the transformation of data took place, rules would consist of rule components, with qualifiers and filters (pre and post), built in function calls, etc.

The GUI layout was good. What was clever was the ability load sample data to test the parse and step through the outbound rules.

Typically a developer took the the Production Objects and referenced them to a SFM. The SFM was defined with AIMs for either Inbound or Outbound and presto you were moving messages. You could embed Production Objects within the AIM, make a ODL function call to it to determine data values, set dynamic links, as an example, which SFM or any number of manipulations, use it to call another AIM to retrieve additional data etc, all in all some fairly sophisticated processing could be developed.

woensdag 20 oktober 2010

HP Envy's scroll feature won't resume

New laptop, HP Envy 14, cool piece of gear. Little problem: after resuming from hibernate it won't scroll anymore. Only after a restart of Windows, scrolling came back.

First guess was right: upgraded the Synaptics driver to version 15.0.17.4. Now it works!

woensdag 21 juli 2010

Evernote cookie

I'm on a new laptop at a client's site. Firefox works as a charm, thanks to Firefox Sync. Now I also need Evernote, since I don't have OneNote here. (Two OneNotes is not practical anyway, as the name of the tool implies...)

But the webclipper of Evernote doesn't work. Installation is fine, try to clip, it keeps asking for my password.

After some more minor annoyances about the clipper and the Windows client, I looked around and came across SpringPad. A subject for another blog. However, the bookmarklet for SpringPad did not work either, same symptom. In SpringPad you can link your Google account and then log in with that, also in the clipper bookmarklet. So I tried that. And Google was the first to be so clever to tell me that I should enable cookies.

It turns out that you need to have third-party cookies enabled, at least until you shutdown the browser.

Would that have been the cure for the Evernote clipper as well? Click... o, yeah!

So: If you want to use the Evernote clipper, enable 'cookies from other websites'.

By the way: if you think about it, it's logical. You're on myrecipe.com, want to clip it, and for that you need a cookie from Evernote.com, which is in this case 'another website'.

dinsdag 11 mei 2010

VirtualBox networking for second domain

My laptop is configured to be part of the Furore domain, where I work. However, I frequently work at a customers' location. With my current customer, your machine has to be on the domain, say 'ABC', otherwise al kinds of services are unavailable.

Since my laptop cannot be configured for two domains, I set up a virtual Windows XP with VirtualBox. For the network I used the default NAT setting connected to my physical ethernet connection. Worked fine, for a while.

Today a network monitoring tool apparently saw a local IP address on the network, the one from the VirtualBox Host. Therefore they automatically shut down my network connection. Problem...

This can be prevented by using the Bridged setting (according to the documentation). So I tried. Didn't work. I suppose because the Hosts' MAC address is unknown to the domain controller, and therefore does not get an IP address from the DHCP server. I could try to contact the servicedesk to register this MAC address. But instead I will ask for a separate laptop from ABC. I'm done with administering things I cannot fully control myself.

maandag 22 februari 2010

Outlook Express can compact messages...

Interesting message I get the past few days after each startup. Funny thing is that I do not even use Outlook Express, I only use Outlook. So there is exactly 1 message in there, the default welcome message. Makes sense to compact that ;-)

However, I found the solution, accidentally on an Outlook forum. The crucial part:

It is related to desktop search - right-click the magnifying glass icon in the toolbar menu and choose Windows Desktop Search Options from the menu. If Microsoft Outlook Express is listed under 'Included Locations' then left-click on it and click on the 'Modify' button'. You should see an Indexed Locations popup where you can 'uncheck' the Microsoft Outlook Express: Main Identity entry and you will no longer receive the message.


Edit: Next startup the message reappeared! So I just gave in and pressed OK. It will probably be silent for some time now. In short:

Resistance is futile. We are Microsoft

zaterdag 28 november 2009

Windows 7 needs memory on VirtualBox

Today finally time to install Windows 7 on a virtual machine. Only it ended fairly quickly with a "failed to start" message. Without any clue as to what might be wrong. Searching on the internet did not reveal the answer directly, but someone had made a description of his own installation, mentioning the amount of memory allocated. That rang a bell. VirtualBox's default is 192 MB. That's not enough. I raised it to 1024 MB and now Windows is installing happily.

woensdag 11 november 2009

Outlook knows what's good for you

Well, sure it does. But if I want to receive an Access database file (.mdb), I do not want to be held back by it. Luckily, Microsoft provided a solution. You just have to edit the registry and reboot your machine. Apparently this cannot be done easier...

For the solution, see the Microsoft Knowledgebase, article 829982.