Deleting all data from a Database

Posted by Monty on December 25th, 2009

SELECT 'ALTER TABLE ' +  OBJECT_NAME(f.parent_object_id) + ' DROP CONSTRAINT [' + f.name + ']'
FROM sys.foreign_keys AS f
INNER JOIN sys.foreign_key_columns AS fc
ON f.OBJECT_ID = fc.constraint_object_id
UNION ALL
SELECT 'TRUNCATE TABLE ' + name FROM dbo.sysobjects WHERE (type = 'u') and name != 'sysdiagrams'
UNION ALL
SELECT 'ALTER TABLE ' +  OBJECT_NAME(f.parent_object_id) + ' ADD CONSTRAINT '  + f.name + ' FOREIGN KEY (' + COL_NAME(fc.parent_object_id, fc.parent_column_id) + ') REFERENCES ' + OBJECT_NAME (f.referenced_object_id) + '(' + COL_NAME(fc.referenced_object_id, fc.referenced_column_id) + ')' FROM sys.foreign_keys AS f INNER JOIN sys.foreign_key_columns AS fc ON f.OBJECT_ID = fc.constraint_object_id

Deeploading with NetTiers

Posted by Monty on December 22nd, 2009

Once you get your head around the DeepLoading and Inclusive/Exclusive Lists in NetTiers, its not too hard, but it isnt straightforward to start off with. Take this VERY simplified class, as an example:


class Product
{
public TList<Product> ChildrenProducts {get;set;}
public Product ParentProduct {get;set;}
}

If you want to deepload the ChildrenProducts collection, you think youd run the following:


DataRepository.ProductProvider.DeepLoad(product,true,DeepLoadType.IncludeChildren, new []{typeof(Product)});

But that will load the ParentProduct product, and not your ChildrenProducts collection, even though its just a list of Product.

What you want to do is:


DataRepository.ProductProvider.DeepLoad(product,true,DeepLoadType.IncludeChildren, new []{typeof(TList<Product>)});

Using NAnt 0.85 with .net 4.0

Posted by Monty on December 19th, 2009

Im guessing because the .net 4.0 framework is still in the beta stages, that’s why NAnt (and TeamCity) arnt supporting it, but from what I can tell, mstcthe method to build it hasnt changed since .net 2.0′s msbuild way of compiling a solution.  Basically, all you need to do is call msbuild from the command line, give it the path of the solution, and off it goes to build it. You can specify additional information such as the build target etc, but its not essential.

Whereas normally, within NAnt, you would run the following:


<solution configuration="release" solutionfile="test.sln" />

This aparently dosent work with the .net 4.0 framework, it seems to not detect it. From what I can tell, the quickest way around this is to do the following:


<exec program="c:\Windows\Microsoft.NET\Framework64\v4.0.21006\MSBuild.exe" basedir="C:\SVN\CycleMania\"  verbose="true" >
 <arg value="C:\SVN\CycleMania\CycleMania.sln" />
 </exec>

Obviously, change the path in the program attribute to suit where Windows is located, and change the Framework64 to simply Framework if you are not running on a 64bit platform. One quirk that I fonud is that you have to have the BaseDir as where the solution is based, otherwise it throws errors about it cannot build properly.

And that should be it! If you are still struggling to compile on the .net 4.0 framework from within Nant, give me a shout.

CycleMania’s Continuous Integration

Posted by Monty on December 18th, 2009

Its now public knowledge that I have been working on getting a decent CI integration for the CycleMania project working on a publicly accessable server.

For the record, we are using the following tech for the CI integration. Yes, I WILL write a very detailed how-to on how I set things up, but as I am on my lunchbreak here at work, heres a very quick overview of what we are using:

  • TeamCity 5.0 Professional, a free download from JetBrains (Limit of 20 Projects and 20 Users)
  • .Net framework 4.0 Beta 2 (obviously)
  • Nant 0.85, not as a proper build script, but purely as a glorified as a batch script
  • APPCMD command to control IIS7′s App recycling (From inside Nant)
  • .Net 4.0′s MSBuild

All this running ontop of Windows 2008 R2 Web Edition, and SQL Server 2008 Express.

Things I have learned is:

  • TeamCity 5.0 isnt geared up for .net 4.0 YET, which is fair enough, they said support will be included in 5.1
  • TeamCity also seems to be simply geared for building projects and running unit tests, less so for copying files over to another directory with specific paths etc.
  • Nant’s contrib project is crap. Fair enough last time it was updated was 3 years ago, but it dosent work.
  • You cannot simply recycle an app pool to kill a user instance of SQL Server 2008, to update the .mdf file.
  • You really shouldnt run a site from the same directory as SVN, if you plan to update it (re above)
  • Nant is all good and well, but also dosent support .net 4.0.

I promise I will expand on most of these points when I have time!

Javascript – Encoding

Posted by Monty on December 15th, 2009

The escape() method does not encode the + character which is interpreted as a space on the server side as well as generated by forms with spaces in their fields. Due to this shortcoming and the fact that this function fails to handle non-ASCII characters correctly, you should avoid use of escape() whenever possible. The best alternative is usually encodeURIComponent().

escape() will not encode: @*/+

Use of the encodeURI() method is a bit more specialized than escape() in that it encodes for URIs [REF] as opposed to the querystring, which is part of a URL. Use this method when you need to encode a string to be used for any resource that uses URIs and needs certain characters to remain un-encoded. Note that this method does not encode the ' character, as it is a valid character within URIs.

encodeURI() will not encode: ~!@#$&*()=:/,;?+'

Lastly, the encodeURIComponent() method should be used in most cases when encoding a single component of a URI. This method will encode certain chars that would normally be recognized as special chars for URIs so that many components may be included. Note that this method does not encode the ' character, as it is a valid character within URIs.

encodeURIComponent() will not encode: ~!*()'

Shamelessly stolen from xkr.us – This can very well bite you on the ass.

Disable Warning As Error on WEBSITE project

Posted by Monty on December 8th, 2009

Well after spending half an hour looking on the net on how to disable WarningAsError on a WEBSITE project, everyone kept saying the same thing – edit the project settings – WELL A WEBSITE PROJECT DOSENT HAVE PROJECT SETTINGS!

Anyway, here is the solution, you need to edit your web.config :

<system.codedom>
 <compilers>
 <compiler language="c#;cs;csharp" extension=".cs" type="Microsoft.CSharp.CSharpCodeProvider,System, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" warningLevel="3" compilerOptions="/d:DEBUG;TRACE">
 </compiler>
 </compilers>
</system.codedom>

Should turn into the following:

<system.codedom>
 <compilers>
 <compiler language="c#;cs;csharp" extension=".cs" type="Microsoft.CSharp.CSharpCodeProvider,System, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" warningLevel="3" compilerOptions="/d:DEBUG;TRACE">
 <providerOption name="WarnAsError" value="false"/>
 </compiler>
 </compilers>
</system.codedom>

The line you want in question is:

<providerOption name="WarnAsError" value="false"/>

And this baby will make it work! Enjoy!

Output all properties for any object

Posted by Monty on July 22nd, 2009

private void outputValues(object inputObject)
{
List<PropertyInfo> propertyInfos = new List<PropertyInfo>(inputObject.GetType().GetProperties());

foreach (PropertyInfo info in propertyInfos)
{
try
{
object obj = info.GetValue(inputObject, null);
if (obj == null)
{
continue;
}
Console.WriteLine("[{0}]:{1}", info.Name, obj.ToString());

}
catch (Exception)
{
continue;
}

}

}

Replace the Console.WriteLine with whatever you want, log4net,  Debug, trace, etc, and it works!

Clearing FK’s and tables from database

Posted by Monty on July 14th, 2009
SELECT 'ALTER TABLE ' +  OBJECT_NAME(f.parent_object_id) + ' DROP CONSTRAINT [' + f.name + ']' FROM sys.foreign_keys AS f INNER JOIN sys.foreign_key_columns AS fc ON f.OBJECT_ID = fc.constraint_object_id
union all
SELECT 'DROP TABLE '+ name FROM dbo.sysobjects WHERE (type = 'u') and name != 'sysdiagrams'

Curiosity

Posted by Monty on June 28th, 2009

Iv recently come across this rather … strange custom in the US navy, where an aircraft would land at the wrong aircraft carrier during a war – either because it got disoriented, or because it ran out of fuel (or, the pilot is a moron), with some hilarious affects:

(Click for larger images)

^ is rather … worrying, im not sure what other ships will think if they see the Russian hammer and sickle on the tail?

The sheer amount of effort and work that went on this plane is just hilarious – “Must be airforce”, I wonder what would happened when this pilot got back to his own ship ?

Politics and expenses

Posted by Monty on June 18th, 2009

I don’t normally write about politics, because its usually such a controversial topic, and I tend to piss people off easily enough anyway, but the whole current expenses row really gets my goat.

They are elected by the public, to serve the public, but unfortunately, they do not see it this way. They see them selves as the elite, they see them selves above us “dirty commoners”, they are better than us. They believe there is one law for them, and another law for us. The whole expenses row has proved this to be correct.

Take the last Home Secretary, someone who was in charge of Anti terror legislation. She admitted to smoking cannabis in the 80′s, and warns people that they shouldn’t smoke cannabis because it will lead to mental health issues, this the day after she was appointed  as the head of the govt review of the UK Drugs strategy.

Smoking cannabis is a CRIME in the UK, so our (former) beloved Home Secretary is a *CRIMINAL*. She has committed a  CRIMINAL OFFENCE (And no, the Misuse of Drugs Act has no statute of limitations)

One of the anti terror strategies was to link, basically everything to terrorism. They have linked photographers to terrorists, something that would be done under the Home Secretary. Another thing that they have linked to terrorism was the fact that drugs will fund terrorists. So, Jacqui Smith has supported terrorism, and should be arrested under her very own Anti Terrorism Act, and held for 42 days without -food-charge.

She has stated :

“If you can’t live by the rules that we live by, the standards and the values that we live by, we should exclude you from this country and, what’s more, now we will make public those people that we have excluded”

Well, CLEARLY, by smoking a Class B drug, you have committed an offence under the Misuse of Drugs Act,  which the penalties lie from 3 months to 5 years in prison – why has she not been prosecuted, or arrested for this offence? I say prosecute her, throw her in jail, then deport her. Good luck finding a country to take the old hag though.

Then there’s the whole fiasco with the ID cards, no one wants them, it WILL NOT PREVENT TERRORIST ACTS (Madrid bombings – they had ID cards then) – and the govt make ridiculous claims such as “Its a SECURE form of identity” – Oh really? Like the countless MOD laptops “forgotten” on trains or left in pub car parks, details for 25 MILLION child benefit claimants’, 3 million learner driver’s details also “misplaced”, on top of that, 45,000 peoples names, dates of birth, and national insurance numbers of people claiming benefits in York, which also has been “misappropriated”.

And lately, the whole expenses row’s – our beloved Jacqui Spliff was caught watching pornography, not once, but twice, and tried to claim it on our expenses, which come out of my and your taxes. That’s great, does that mean I too can watch pornography, and it come out of tax payer expenses? No? That’s not fair!

And lets not forget the DNA debacle – 17 senior judges across Europe have ruled that keeping DNA after not being charged is ILLEGAL, and HAS TO STOP, and the -Nazi Government-British Government has agreed to keep DNA and fingerprints for 6 years.

Do you really trust this government, who have, repeatedly, over and over again, shown disregard for the law, and everyone’s rights, and only look out for themselves, and try to screw everyone over?


Copyright © 2007-2010 Muntedhar Alhakim. All rights reserved.