Windows Server 2008 Image thumbnails not showing

20 December, 2010 1 comment

I noticed the other day that on one of my servers image thumbnails were not showing.

This is easy to fix, do the following:

  1. Click Start  and Right-Click on “Computer” and choose “Properties”, (or if like me you like your “Computer” icon on your desktop then just Right-Click on the computer icon on your desktop).
  2. Under “Tasks” on the left hand list of options click “Advanced System Settings”
  3. On the “Advanced” tab, in the “Performance” group, click “Settings”
  4. On the “Visual Effects” tab find and tick the following option “Show thumbnails instead of icons”
  5. Click Ok
  6. Click Ok

You should now be able to browse your images as thumbnails again.

Sigh! Thanks for turning that off by default Microsoft!

Categories: OS

SSIS Date conversion error going from Oracle to SQL Server

19 December, 2010 1 comment

Hi,

The other day I had the task to move a large amount of data from Oracle to SQL Server.
I had chosen to import the data via SSIS, doing a direct copy from one table in oracle to one table in SQL Server.

Everything was fine until I one of my tables crashed, with a data conversion error.

The issue is that the lowest date that SQL Server will accept is “1-Jan-1753”. There was some bad data in Oracle dated year 1049, consequently SQL server did no know how to handle it. How was I going to handle it?

The solution is to use a transformation script. In your data flow task, add a transformation script between your source and destination. When you drop in on the form it pops up a dialogue, leave it default for transform.

On the inputs column choose the date column in question (for the example lets assume its called CreatedDate).
Make sure you change its “UsageType” in the grid from “Read” to “Read-Write”.

Go to the script tab and click “Design Script” enter something like the following code:
Note: This is in vb .net. I think 2008 R2 allows c#, but you should get the idea:

        Try
            Dim dt As DateTime = Row.CreatedDate()
            Dim dtMin As DateTime = System.DateTime.Parse("1753-01-01 00:00:00")
            Dim dtMax As DateTime = System.DateTime.Parse("9999-12-31 23:59:59")
            If (Row.CreatedDate_IsNull = False) Then
                If (dt < dtMin Or dt > dtMax) Then
                    If (dt < dtMin) Then
                        Row.CreatedDate() = dtMin
                    Else
                        Row.CreatedDate() = dtMax
                    End If
                End If
            End If
        Catch ex As Exception
            Row.CreatedDate_IsNull = True
        End Try

This code will find any row that has a date that falls outside the bounds of what SQL server will accept and set it to the Max or Min date values.

Finally some general tips that I learned in attempting to move large amounts of data from Oracle to SQL.

1. Don’t use a linked server connection it is really slow.
2. The Microsoft OLEDB connector for Oracle is pretty fast.
3. When setting up the OLEDB Destination via “Table or View” make sure you choose the “Fast Load” option!! Why you would want it to run slow is beyond me but the “Table or View – fast load” is about 10 to 15 times faster.

Cheers

Try
Dim dt As DateTime = Row.CreatedDate()
Dim dtMin As DateTime = System.DateTime.Parse(“1753-01-01 00:00:00”)
Dim dtMax As DateTime = System.DateTime.Parse(“9999-12-31 23:59:59”)
If (Row.CreatedDate_IsNull = False) Then
If (dt < dtMin Or dt > dtMax) Then
If (dt < dtMin) Then
Row.CreatedDate() = dtMin
Else
Row.CreatedDate() = dtMax
End If
End If
End If
Catch ex As Exception
Row.CreatedDate_IsNull = True
End Try
Categories: SQL Server

How to Create a linked server connection from SQL Server to Filemaker Pro 6.0

15 November, 2010 1 comment

Ok,

This one may be a bit obscure but I had to do this for data conversion from a legacy system the other day and the FileMaker documentation was pretty light on, but I eventually got it to work.

The problem is that you want to extract data from a FileMaker Pro 6.0 database by creating a linked server connection from SQL Server.

Here are the steps with one Caveat. I was only able to make this work on a 32-bit machine. I had a 64-bit machine, and I could run the 32-bit odbc datasource tool and set-up and test the connection but I could not get my 64-bit version of Sql Management studio to find the 32-bit System DSN I had created, so I jumped over to a 32-bit virtual machine with SQL 2008 on it and everything worked more easily.

1. Install FileMaker Pro

Ensure that you have FileMaker pro installed on the box that you want to create the linked server connection on. This installs the 32-bit filemaker pro driver to allow you to create an ODBC data source.

2. Create on ODBC Datasource System DSN

  • Go start :: administrative tools :: Data Source (ODBC)
  • Switch to the System DSN tab
  • Click Add
  • Choose “FileMaker Pro”
  • Click Finish
  • On the General Tab give the connection a generic name, (can be anything), i used FMPro
  • Tick “Use Remote Connection” and add the loop back IP address, 127.0.0.1
  • Click OK.

3. Create a linked server connection

  • Launch SQL Server Management Studio
  • Expand to “Server Objects” :: “Linked Servers”
  • Right Click “New Linked Server”
  • In the provider choose “Microsoft OLE DB Provider for ODBC Drivers”
  • In the following fields, enter “FMPRO”
    • Linked Server
    • Product Name
    • Data Source
  • Click OK.

4. Load FileMaker Database

The linked server connection only works via the local client, so for the linked server to work you have to have your Filemaker Pro database loaded and remotely accessible.

  • Launch FileMaker Pro
  • Open your database, this can be a FM database on a remote server over TCP/IP, connect up as you normally would to access the file.
  • Choose File :: Sharing
  • Set to Multiple and enable Local and remote connections.

Note: During my linked server sessions, I have sometimes lost the connection or get connection errors. I just close filemaker, and repeat the above steps and it all comes good again.

5. How to query FileMaker

What is the name of the FileMaker Table? select * from what?

Turns out the name of the filemaker database is the table name, so assume your db is called “fmdatabase” you would write the following (Note: I generally use “OpenQuery” statements to run my linked server queries):

select * from openQuery(FMPRO, 'Select * from fmdatabase')

but what if your filemaker database has a space in the name? like “fm database”

well the trick here is documented away deep in the FileMaker help file use `

this is the punctuation on the tilde (~) key.

so your query becomes

select * from openQuery(FMPRO, 'Select * from `fm database`')

Now that should all be clear.

Hope it helped.


Categories: General Apps

StringUtil class – Space Before a Capital Letter

17 September, 2010 Leave a comment

Hi,

I often use enumerations in code that I want to display as text on the screen. For example the state of an object recorded in an enum like

public enum StageType
{
PreRelease = 0,
Proposed = 1,
Open = 2,
Closed = 3
}

So if I get the matching value out of the database and I want to render a textual representation of the enum to the UI I migth do:

lblStatus.Text = ((StageType) iStage).ToString(); // where iStage is an int value representing the enum.

So this is great appart from the first item PreRelease will be shown without a space.

Step in my amazing class which will parse the string and add a space before a capital so “PreRelease” becomes “Pre Release”
This way I can use any Camel case enum string and have it render to the UI nicely.


public static class StringUtil
{

///
/// Returns a string with a space after a capital
///
///
///
public static string SpaceOnCapital(string word)
{
StringBuilder sb = new StringBuilder();

foreach (char c in word)
{
if (sb.Length == 0)
{
sb.Append(c);
}
else
{
// not the first character
// ch
if (IsCapital(c))
{
sb.AppendFormat(” {0}”, c);
}
else
{
sb.Append(c);
}
}
}

return sb.ToString();

}

public static bool IsCapital(char c)
{
int ascii = (int)c;
return (ascii >= 65 && ascii <= 90);
}
}

Cheers

Categories: c#

Create Visual Studio Project with the correct directory structure

10 September, 2010 Leave a comment

This ones just for me.

I have been using TFS and when I read the best practice documentation for how to setup your projects I have ended up having a preference for how i like my directory structure.

Assume you have a project  call BudgetForecast, I would  end up with a folder structure like

c:\Dev\BudgetingProject\Main\Source\BudgetForecast\Source\

Under the BudgetForecast directory would be the BudgetForecast.sln and in the Source subdirectory would be the Project file.

So how to get Visual studio to do that.

  1. Create a new solution
  2. Set the location to c:\Dev\BudgetingProject\Main\Source\
  3. Set the Name to “Source” (this also sets the solution name)
  4. Set the SolutionName to “BudgetForecast”
  5. make sure the “Create Directory for Solution”  is picked
  6. click OK

Your soltuion is now created but your project is called source, so just rename to project to BudgetForecas, save that and your done.

I wrote this as I can never remember whether Name or solution Name needs to be changed to source and invariably I get it wrong

Cheers

Categories: Visual Studio

jQuery – enable / disable (readonly) and how to reference .Net Server side Controls

8 September, 2010 Leave a comment

Ok, I am just starting to play around with jQuery and these are a couple of tips that I have found useful.

1. How to access .net server side controls
The code to get the value from a html input control <input id=”name”> might be as follow:
var name = $(‘#name’).val();

For a server side control like <asp:TextBox ID=”txtName” runAt=”sever” /> you can reference it as follows:
var name = $(‘#<%=txtName.ClientID%>’).val();

I have a user control for date selection called the DateSelector, and it has a control inside it called txtDate which stores the selected date.
If I want to get the value from within a user control like this I can do:

var dte = $(‘#<%=dteDateSelector.ClientID%>_txtDate’).val();

2. Disable a control
In this case I want to disable a text box from the txtName example above:
$(‘#<%=txtName.ClientID%>’).attr(“disabled”, true);
to clear it
$(‘#<%=txtName.ClientID%>’).removeAttr(“disabled”)

A problem with disabling controls in this way is that their values cannot be read in javascript, so another way is to use the “ReadOnly” attribute
$(‘#<%=txtName.ClientID%>’).attr(“readonly”, true);
to clear it
$(‘#<%=txtName.ClientID%>’).removeAttr(“readonly”)

Cheers

Categories: ASP .Net, jQuery

Generic List.Sort

30 August, 2010 Leave a comment

I often want to use a list to sort and every time I have to go searching on how to use the IComparer interface.

Assume I have a Person object with the “DisplayName” property that I wish to sort by.

I created the following class:

public class PersonDisplayNameAscendingComparer : IComparer
{

#region IComparer Members

public int Compare(Person x, Person y)
{
return x.DisplayName.CompareTo(y.DisplayName);
}

#endregion
}

And then assuming you have a List called people, you can sort like this;

PersonDisplayNameAscendingComparer personComparer = new PersonDisplayNameAscendingComparer();
people.Sort(personComparer);

Job done.

Categories: c#