Posts filed under ‘Visual Studio’

SQL Server 2008 ”Katmai" & SQL Server 2005

After removing SQL Server 2005 (SQL Server 2005 management tools cause the SQL 2008 install to bork) and installing SQL Server 2008 – it all went a little pear shaped………..

SQL Server 2008 worked ok but none of the database libs existed – so projects against file-based SQL 2005 databases could no-longer connect. Not good.  VS 2008 couldn’t connect to SQL 2008 and I couldn’t create a SQL 2008 file based database with Visual Studio.  As a last ditch attempt I attempted to use the OLEDB DB drivers – again without luck.

After a few hours of trying to get to the bottom of the problem and to get things working – I decided to install SQL Server 2005 express again side-by-side with SQL 2008.  The install worked ok – and I could open the SQLExpress instance with the SQL 2008 management tools.  Cool – so back to the projects and try again with the file-based SQL database…

Some progress but I started getting a weird error ”filename.MDF’ cannot be opened because it is version 639. This server supports version 612 and earlier. A downgrade path is not supported.’.

Hummm.  It appears an update has been installed and the database version had changed.

Windows Update didn’t find anything – so it looked like it was gonna be grim…

Finally I attached the database in question to SQL 2008 and then exported, via the management console, the database to the SQL Express 2005 instance installed.  Then it was a simple process of detaching the database from the SQL 2005 instance and copying the DB files to the project.

5 mins later – the application was running again.

Whew!

It’s a little odd that the native SQL Database drivers weren’t compatible with either SQL 2005 databases and that VS 2008 couldn’t create or connect with SQL 2005 databases.  With the amount of advice we’re given about side-by-side assemblies and SOA contracts that both VS 2008 & SQL 2008 found it all such a stuggle.

Advertisements

Wednesday 28th November, 2007 at 11:07 pm 1 comment

Visual Studio 2008 RTM’d

Visual Studio 2008 has RTM’d – if you’re a lucky MSDN subscriber (alas I’m not ūüė¶ ) you can download it from the subscriber site.  Luckily you can download a 90 day trial of VS 2008 Team Server (basically VS 2008 with a few extra bells and whistles) from here.

Initial impressions are that it’s stable and pretty functional.  I’m in the middle of a WPF application for a client and the rtm is holding up better than the Beta 2 did.

I’m a little disappointed with the visual designer for WPF – it doesn’t really help much in terms of productivity.  The xaml editing is responsive and in a limited way helpful – but could do with a little more oomph added to the intellisense.  The intellisense is  lacking a bit with binding statements (in bold) such as:

<ListBox Grid.Row="1" Name="lstContacts" 
  IsSynchronizedWithCurrentItem="True" 
  ItemsSource="{Binding Source={StaticResource contactsViewSource}}" />
 
Technorati Tags: ,,

Monday 26th November, 2007 at 1:37 pm 1 comment

WPF: Dynamic Filtering Data – the simple approach

You often find yourself wanting to quickly filter data based on a criteria defined by a user in an application.¬† A classic example is filtering what’s shown in a listbox by what a user has typed into a textbox.

There are many approaches to solving the problem but a quick and simple approach is: (first the xaml):

<Window x:Class="Window1"  
  xmlns=http://schemas.microsoft.com/winfx/2006/xaml/presentation  
  xmlns:x=http://schemas.microsoft.com/winfx/2006/xaml  
  xmlns:local="clr-namespace:contactManager"  
  xmlns:system="clr-namespace:System;assembly=mscorlib" 
  Title="Window1" Height="598" Width="1015">
  <Window.Resources>
     <local:contacts x:Key="myContacts" />    
     <CollectionViewSource x:Key="contactsViewSource"
         Source="{StaticResource myContacts}" Filter="CollectionViewSource_Filter" />

  </Window.Resources>
  <Grid Name="Grid1">
    <Grid.RowDefinitions>
      <RowDefinition Height="60*" />
      <RowDefinition Height="423*" />
    </Grid.RowDefinitions>
    <TextBox Margin="62,26,16,0" Name="txtSearch" Height="23" VerticalAlignment="Top"
     AcceptsReturn="True" FontStyle="Italic" KeyUp="txtSearch_KeyUp" />
    <Label Margin="12,12,66,0" Name="Label1" Height="28" VerticalAlignment="Top">Search</Label>

    <ListBox Grid.Row="1" Name="lstContacts" IsSynchronizedWithCurrentItem="True" 
      ItemsSource="{Binding Source={StaticResource contactsViewSource}}" />
  </Grid>

</Window>

The local resource contacts is a class that is defined in the application.¬† The namespace is imported into the XAML with xmlns:local=”clr-namespace:contactManager“‘.¬† The class itself is referenced in XAML by <local:contacts x:Key=”myContacts” />‘.

The class itself inherits from an observableCollection – although the approach would work with any datasource that can be bound to the listbox. After contacts has been imported – we setup a collectionViewSource – rather than using the default viewSource provided by WPF.

The code behind to connect the filter text with the filter applied to the listbox is:

Partial Public Class Window1  
  Private Function findString(ByVal haystack As String, ByVal needle As String, _       
                                 Optional ByVal comparison As StringComparison _          
                                    = StringComparison.CurrentCultureIgnoreCase) As Integer
    ' We are using string.indexOf rather than string.contains as string.contains     
    ' doesn't allow us to specify CurrentCultureIgnoreCase         
    Return haystack.IndexOf(needle, 0, comparison) 

  End Function 

Private Sub CollectionViewSource_Filter(ByVal sender As System.Object, _                                   
                                    ByVal e As System.Windows.Data.FilterEventArgs) 
   ' Cast the listbox item to the type used   
  Dim thisContact As contact = CType(e.Item, contact) 

  If (thisContact IsNot Nothing) Then  ' Handle an empty item 

    If String.IsNullOrEmpty(txtSearch.Text) Then           
      ' Make sure we have some text that we wish to filter

      e.Accepted = True         
      ' If we don't then we want all items to appear in the listbox

    Else                  
      ' findString returns the index of the needle (search text) in       
      ' the haystack (text to be searched)             
      ' IndexOf returns -1 if the needle isn't found in the haystack 

      If (findString(thisContact.firstName, txtSearch.Text) > -1) _                 
               Or (findString(thisContact.lastName, txtSearch.Text) > -1) Then 

        ' The needle exists in the haystack - so accept this entry                 
        e.Accepted = True 

      Else                        
        ' This item doesn't contain the needle we are looking for

        e.Accepted = False

      End If 

    End If

  Else            
    ' thisContact IS nothing - so don't bother displaying it 

    e.Accepted = False 

  End If 

End Sub 

Private Sub txtSearch_KeyUp(ByVal sender As System.Object, _                    
                                ByVal e As System.Windows.Input.KeyEventArgs)          
' This event will be raised whenever the keyUp event occurs on the     
' textbox that we are using to filter         
' Do a simple refresh on the listbox 

    CType(Me.FindResource("contactsViewSource"), CollectionViewSource).View.Refresh() 

  End Sub 

End Class 

  And that's it - a listbox containing items is filtered based on the text typed by the user in a search box.

Technorati Tags: ,,

Sunday 25th November, 2007 at 7:58 pm 2 comments

DataBinding ObservableCollection with WPF

Watch out for the code you place in your sub New() of the ObservableCollection – it can cause the WPF designer problems as the designer will attempt to execute the constructor during design time.¬† If you’re trying to populate the collection from a file based database then the connection string, in some situations, VS 2008 will look in the wrong place for the database.¬† It appears that using the |Data Directory| prefix for the database causes VS 2008 (RTM) to look in the working directory of VS – rather than the project directory.

Symptoms of this kind of problem are VS reporting:

“Could not create an instance of type ‘abc’. …Window1.xaml 8 3” and your XAML reference will be squiggily underlined.
A solution to this problem is wraping the constructor of the object implementing the ObservableCollection in a try/catch and swallowing the error (suggested only during the development cycle) or by detecting if you’re in designtime.

A simple way to detect if you’re in designtime with WPF is:

If DesignerProperties.GetIsInDesignMode(Application.Current.MainWindow) Then
  Add(New contact("DesignTime", "Detected"))
Else
  Try
    oContactsTA.Fill(oContacts)
    For Each thisRow In oContacts
      Add(New contact(thisRow))
    Next
  Catch ex As Exception
    Add(New contact("DesignTime", "NotDetected"))
  End Try
End If

Saturday 24th November, 2007 at 3:51 pm 3 comments

VS.PHP 2.3RC1 is out

For those Visual Studio and PHP developers out there Р2.3RC1 for VS.PHP is out from JCXSoftware. 

Initial testing has gone well and it’s looking like a good release so far.¬† Found a few problems with formatting when editing Smarty¬†templates – but it’s just an annoyance than a problem.

Thursday 24th May, 2007 at 2:59 pm Leave a comment

BlackBytes Components

Anybody know the fate of BlackBytes?¬† They have some great .NET components on their site but don’t appear to be operating anymore – I’ve sent a number of emails and tried to contact them on their forums but they appear to have becomes ghostware.

One of the problems with automated systems – as can be found when you download and request trial keys – is that the system responds – giving the appearence of activity…

It’ll be a shame if they have folded – their DNS API is the only one available.

Wednesday 23rd May, 2007 at 9:26 am Leave a comment

Develop both with PHP and .NET?

If you’re a seasoned¬†developer and work in both ¬†.NET and also PHP – then you’ll be interested in VS.PHP¬†from JCX Software.¬† They have 2 main products:

  • A Visual Studio Add-in for developing PHP
  • A stand-alone VS 2005 PHP Editor (using the VS 2005 redistributable wrapping their Add-in

If you’re used to the VS 2005 interface – you’ll find it a real boon with a familiar environment to work in.¬† It even understands and supports the development of Smarty templates.¬†

I’ve found it to be very performant and much less of a resource-hog than the Zend IDE – which, after running for long periods of time, tends to lock up and become unstable.

¬†It’s well priced (at 99 USD) – they’re not trying to gouge you like some development tools that charge high annual tie-in ‘subscription’ fees for development tools.

The current version of VS.PHP is 2.1 with a beta for 2.3 openly available.

Sunday 20th May, 2007 at 2:31 pm Leave a comment

Older Posts


Recent Posts