A post to keep track of interesting bits of information regarding .NET development. Latest notes on backing up SQL Server 2005 databases from .NET code and creating / managing compressed filed from .NET code.
Backing up a SQL Server 2005 Database in C#: Use the Smo interface as demonstrated here: http://www.geekpedia.com/tutorial180_Backup-and-restore-SQL-databases.html. However if you need to do this on an x64 server then you need to download the x64 DLL: http://www.microsoft.com/downloads/details.aspx?familyid=D09C1D60-A13C-4479-9B91-9E8B9D835CDC&displaylang=en (see general IT article for extracting without installing).
Creating and Managing Compressed Files in C#: This open source library certainly does the trick: http://www.icsharpcode.net/OpenSource/SharpZipLib/Default.aspx
Using Session State in HttpHandlers e.g. WebHandlers is ASHX files. Remember to implement IReadOnlySessionState.
<% @ webhandler language="C#" class="DownloadHandler" %>using System;
using System.Web;
using System.Web.SessionState;
public class MyHandler : IHttpHandler, IReadOnlySessionState
{
public bool IsReusable { get { return true; } }
public void ProcessRequest(HttpContext Context)
{
Context.Response.Write(Context.Session["fred"]);
}
}
Thanks to Scott Hanselman
Dynamic Proxy Classes in C#.NET: I recently came to use a dynamic proxy class in .net having previously used them in Java and found to my surprise that they are quite complex to implement in .net. Follows is a solution for .net however I ended up using an open source solution, Castle.DynamicProxy.
Data Formatting ASP.NET 2.0 Gridview: I recently had a problem formatting data in a Gridview and found (thanks to this article: http://weblogs.asp.net/rajbk/archive/2005/10/31/429090.aspx) that because formatting occurs after the HTML encode function (which is on by default) the formatting has no effect. Setting HtmlEncoding to 'false' solves the problem.
Error "Cannot use a leading .. to exit above the top directory.": This may happen when re-writing URL's in which case for the solution see this thread: DNN Forum Post and this blog: ToDotNet Blog Post
Error " Validation of viewstate MAC failed. If this application is hosted by a Web Farm or cluster, ensure that configuration specifies the same validationKey and validation algorithm. AutoGenerate cannot be used in a cluster. ": If you are sure that the error is not caused by the points mentioned then check this DotNetSlackers Blog Post and this ASP.NET Forums Post
Exception has been thrown by the target of an invocation. at System.RuntimeMethodHandle._InvokeMethodFast(...) Error received when adding a new user to an asp.net membership application. This is due to using "encryption' and not having an available machine key. You can create a machine key here: Machine Key Creator