ixnay2infinity

Wednesday, February 11, 2009

TIP: create SQL server datetime using international date format (ISO 8061)

SELECT
CAST(
CAST(datepart(year, getdate()) AS varchar) + '-' +
RIGHT('0' + CAST(datepart(month, getdate()) AS varchar), 2) + '-' +
RIGHT('0' + CAST(10 AS varchar), 2) +
'T00:00:00'
AS datetime)

Note that SQL Server 2005 does *NOT* accept all ISO 8061 date/time formats. This one works well, and the advantage of using an international date/time format is that the date string is not ambiguous.

The above SQL creates a string consisting of at least 2 digits for day and month, and ends up looking like this for example: '2009-02-10T00:00:00'

SQL accepts that format and can CAST it to datetime.

Thursday, February 05, 2009

IE8 RC1 causes system instability when Roxio DLA is installed

Recommend you do NOT install IE8 RC1 together with Roxio DLA. I had DLA installed, on Win XP SP2 with IE 6, and installed IE 8 RC1 only to get regular system freezes (reset required). Uninstalling IE8 did *NOT* solve it either. The problems seemed to get worse. E.g. opening My Computer would show a white window only and stop responding.

Windows reported a problem closing DLACTRL.EXE I think it was, when shutting down. So I took a punt and uninstalled Roxio DLA. Problem was solved.

Labels:

Friday, January 23, 2009

".. specified file is not a registry script .."

".. specified file is not a registry script .."

If you get such an error when trying to import a .REG file in Windows XP, one thing you might want to check is that your text editor saved the file with Windows new-lines (i.e. CRLF). If you edit in Textpad for example it seems to save with Unix new-lines (LF) and the registry editor will not accept the .REG file as a valid format for importing.

Sunday, April 20, 2008

Using LINQ to SQL with MS Access databases

As you probably know the LINQ to SQL functionality in .NET 3.5 is only supported with SQL Server databases, as the SQL commands generated by the DataContext are targetted at SQL Server.

However the DataContext does not enfore it's connection to be a SQL server connection, and you can in fact pass an OleDbConnection object. I personally find Access very capable for some projects - so obviously it makes sense to be able to use LINQ to SQL with Access databases. Searching on this topic returns very little info, especially since most articles refer to "data access layer".

Anyway - if you have classes decorated with the [Column] attributes etc corresponding to your tables, you CAN in fact query the Access database with LINQ queries. I'm not saying *all* LINQ queries will work - I am still to test how many. But many types should, since the Access SQL syntax flavour is not that different from SQL server's.

However what I really wanted was to be able to use the SubmitChanges() feature to push object data back to the database. Unfortunately the SQL generated by the create & update functions are NOT compatible with Access.

The INSERT gives an error of a "missing semicolon" (due to a second query to retrieve the identity value), and the UPDATE gives an error saying "row not found or changed" (the reason still eludes me, after seeing the query it generates).

The solution is to create a class that inherits from DataContext, and implement Update & Insert methods that it will call instead. If you use a customisable data-layer generator, this class can be automated. Basically you need to execute custom INSERT & UPDATE queries. If you follow this format you could save yourself a lot of time and banging-head-against-desk:




Now you should be able to create/update rows the usual LINQ way:

-------------
Customer newCust = new Customer() { Name = "n", Description = "d" };
db.Customers.InsertOnSubmit(newCust);

try
{
db.SubmitChanges();
}
catch (Exception err)
{
MessageBox.Show(err.Message);
}

MessageBox.Show(newCust.ID.ToString());
-------------



Here is the full code for the DataContext-inherited class:

[System.Data.Linq.Mapping.Provider(typeof(System.Data.Linq.SqlClient.Sql2000Provider))]
[System.Data.Linq.Mapping.DatabaseAttribute()]
public partial class Db : System.Data.Linq.DataContext
{
void UpdateCustomer(Customer c)
{
this.ExecuteCommand("UPDATE [Customers] SET [Name]=@p1, [Description]=@p2, [Version]=@p3 WHERE [ID]=@p0", c.ID, c.Name);
}

void InsertCustomer(Customer c)
{
IDbCommand cmd;

string query = "INSERT INTO [Customers] ([Name], [Description], [Version]) VALUES (@p0, @p1, @p2)";

cmd = this.Connection.CreateCommand();
cmd.Transaction = this.Transaction;
cmd.CommandText = query;
cmd.Parameters.Add(new OleDbParameter("p0", c.Name));
cmd.Parameters.Add(new OleDbParameter("p1", c.Description));
cmd.Parameters.Add(new OleDbParameter("p2", c.Version));
cmd.ExecuteNonQuery();

cmd = this.Connection.CreateCommand();
cmd.Transaction = this.Transaction;
cmd.CommandText = "SELECT @@IDENTITY";
c.ID = Convert.ToInt32(cmd.ExecuteScalar());
}


private static System.Data.Linq.Mapping.MappingSource mappingSource = new AttributeMappingSource();


public Db() :
base(global::LinqExp1.Properties.Settings.Default.cnwin_mainConnectionString, mappingSource)
{
OnCreated();
}

public Db(string connection) :
base(connection, mappingSource)
{
OnCreated();
}

public Db(System.Data.IDbConnection connection) :
base(connection, mappingSource)
{
OnCreated();
}

public Db(string connection, System.Data.Linq.Mapping.MappingSource mappingSource) :
base(connection, mappingSource)
{
OnCreated();
}

public Db(System.Data.IDbConnection connection, System.Data.Linq.Mapping.MappingSource mappingSource) :
base(connection, mappingSource)
{
OnCreated();
}


void OnCreated()
{ }


public System.Data.Linq.Table Customers
{
get
{
return this.GetTable();
}
}
}

Monday, July 31, 2006

Sandcastle BAT script configuration utility

UPDATE: Now supports wild cards (i.e. multiple assemblies/xml-comments files).

I've whipped together a little windows app to configure and create the BAT script that I posted yesterday which calls the various steps to get Sandcastle-generated MSDN-style documentation:

http://www.ixnay2infinity.com/misc/SandcastleCreateBat.zip

NB: The app includes the BAT script - you do not need to download it separately.

1) Unzip all files, and open SandCastleCreateBat.exe.
2) Specify file paths
3) Click Create BAT to output BAT script + sandcastle.config to the same directory as as the CHM path.

Screenshot:


For detailed information visit: http://www.codeproject.com/useritems/SandcastleCreateBat.asp


Feedback would be appreciated.

Improved SandCastle BAT script

(Update: I've made a windows app to configure the paths and save the BAT script - click here)

Yesterday I posted my initial BAT script to automate the 11 steps to create a CHM using Microsoft's SandCastle CTP. Well there were a couple of limitations, so here is the updated BAT script: http://www.ixnay2infinity.com/ScrollingGrid/SandCastle-BAT-compile-updated20060731.zip


Contents of readme.txt:

Description: BAT file to create CHM file containing MSND-style class documentation for your assemblies using Microsoft Sandcastle CTP (July 29 2006)
Author: Ashley van Gerven (http://ixnay2infinity.blogspot.com)


Instructions:
1) Extract this zip file to a working directory (ANYWHERE!)
2) Modify line 3 to point to your assembly
3) Modify line 4 to point to your comments XML file
4) Modify line 18 and change "ScrollingGrid.chm" to the your CHM filename. You can also set the full destination path to the resulting CHM file.
5) Run the BAT script, and you should end up with your CHM file in the working directory or where you specified


NB - Requirements:
1) You installed Sandcastle to the default path: C:\Program Files\Sandcastle
2) You installed HTML Help 1.4 SDK to the default path: C:\Program Files\HTML Help Workshop
3) You have .NET framework 2.0 installed


Note:
This BAT has several improvements over my initial BAT script of yesterday which had the C:\test_sc path hard-coded and required replacing this string to the current path of the BAT. This is no longer required.

Note 2:
If you don't want the ouput folder (containing all the HTML files, Help project etc) to be deleted after compiling the CHM just prepend "REM" to the second-last "@rd..." line.

Sunday, July 30, 2006

Batch file for Microsoft SandCastle CTP .NET documentation compiler

NB: I've since updated the BAT script - available here.

OK the SandCastle CTP is out, but it doesn't have a UI or command line interface. The 11-step instructions at http://blogs.msdn.com/sandcastle/archive/2006/07/29/682398.aspx would be quite a mission to repeat manually each time you need to update your CHM.

I'm probably not the only one to compile a batch file with all the commands. However it certainly wasn't as simple as expected. So I'm sure this batch script will save a lot of time and headaches until the next release of SC.

Steps (or skip to below to download ZIP file):
1) create C:\test_sc\working & C:\test_sc\output
2) Copy C:\Program Files\Sandcastle\Presentation\Configuration\sandcastle.config to C:\test_sc\working and edit this file. Replace "..\..\" with "C:\Program Files\Sandcastle\", "..\cpref_reflection" with "C:\Program Files\Sandcastle\Examples\cpref_reflection", "Output\html" with "..\output\html.
3) Save this batch script and modify lines 2 & 3 to point to your assembly & XML file:


cd "C:\test_sc\working"
copy "C:\test_sc\assembly here\ScrollingGrid.xml" "C:\test_sc\working\comments.xml"
MRefBuilder "C:\test_sc\assembly here\ScrollingGrid.dll" /out:reflection.org
XslTransform "C:\Program Files\Sandcastle\ProductionTransforms\AddOverloads.xsl" reflection.org XslTransform "C:\Program Files\Sandcastle\ProductionTransforms\AddGuidFilenames.xsl" /out:reflection.xml
XslTransform "C:\Program Files\Sandcastle\ProductionTransforms\ReflectionToManifest.xsl" reflection.xml /out:manifest.xml
cd "C:\test_sc\output"
if not exist html mkdir html
if not exist art mkdir art
if not exist scripts mkdir scripts
if not exist styles mkdir styles
copy "C:\Program Files\Sandcastle\Presentation\art\*" art
copy "C:\Program Files\Sandcastle\Presentation\scripts\*" scripts
copy "C:\Program Files\Sandcastle\Presentation\styles\*" styles
cd "C:\test_sc\working"
BuildAssembler /config:sandcastle.config manifest.xml
XslTransform "C:\Program Files\Sandcastle\ProductionTransforms\ReflectionToChmContents.xsl" reflection.xml /arg:html="C:\test_sc\output\html" /out:"C:\test_sc\output\Test.hhc"
copy "C:\Program Files\Sandcastle\Presentation\Chm\test.hhp" "C:\test_sc\output\help_proj.hhp"
"C:\Program Files\HTML Help Workshop\hhc.exe" "C:\test_sc\output\help_proj.hhp"
@PAUSE
Or you can extract this zip file to "C:\test_sc":

http://www.ixnay2infinity.com/ScrollingGrid/SandCastle_BAT_compile.zip, then modify lines 2 & 3 to point to your assembly & XML file, and run it.

It will output various files to "output" and "working" directory, and finally you should have "Test.chm" in the "output" directory. The default page for the CHM is blank.. just click a node on the left.

NB: two assumptions in this script:
1) you installed sandcastle to default path
2) html help install path is: C:\Program Files\HTML Help Workshop

Hope this is useful.
Ash

Friday, March 03, 2006

Picasa vs. MS Library vs ACDSee

Before I decide whether to upgrade to latest version of ACDSee I decided to try it out, as well two other photo managers, and ended up doing a bit of a comparison on impressive (+) and disappointing (-) features of each app. This is not a comprehensive list - so any other comments are welcome.

AFAIK Microsoft Digital Image 2006 Suite is pretty new. I only looked at the Library app, but they've done a pretty awesome job IMO. I couldn't actually find much fault with it... whereas the other two there had quite a few annoyances. But in the end by offering a similar feature set PLUS being free, Picasa must be giving the competition a hard time.

Are there any other impressive photo managers out there that might put any of these to shame? (I know there are a few avid photographers around here!)


Google Picasa 2.2.0 (free)
http://picasa.google.com/
+ easily assign labels
+ password protect
+ create timeline
+ adding new 'watched folder' processes images very fast
+ batch rotate, brightness etc.
+ batch resize (export to album)
+ built in editor
- all folders added at same level (no hierarchy)
- can only star images (no 5 star rating)
- can't hide/drag the navigator that appears when zoomed in on image
- move mouse stops slideshow
- entire collection is shown in the main window (grouped by folder). Even hiding a folder still displays it (just seems to move it to the end).
- no medium size preview display


Microsoft Digital Image 2006 Library (US$34.95)
http://www.microsoft.com/products/imaging/ProductDetails.aspx?pid=002
+ easy to add new watch folders
+ 5 star rating, 6 (customisable) flags
+ includes images in subfolders in thumbnail view
+ can group by different options (e.g. rating, year, filesize etc)
+ easy rename & edit caption (tile view)
- processing images for a newly 'watched folder' seems to take 3-4 times as long as Picasa


ACD Systems ACDSee 8 (US$49.99)
http://www.acdsystems.com/products/acdsee/index
+ can select multiple folders to combine images displayed in preview area
+ rate images from 1-5
+ assign to hierarchical categories
+ very advanced search facility (but can't save your search criteria)
+ favorites - add's shortcut to image or folder in favorites pane
+ no need to import folders - uses existing directory structure
+ highly customisable
- no way to expand all subfolders in Folders pane
- adding to favorites cannot add to a subfolder within favorites
- doesn't show images in subfolders unless expand and select them
- can only apply basic filters to listing view
- can't save a search (which should be a critical feature considering the filter function is so basic)
- no easy rename of images / description
- crashed once during a slide show