Archive for the ‘DotNET’ Category

Make a .NET web service accept GET requests

The usual way to call web service is by using POST requests. But sometimes GET requests are required. To make .NET web services accept their parameters from GET requests, add a ScriptMethod attribute to your web service routine. First add some libraries: C# Using System.Web.Services; Using System.Web.Services.Protocols; Using System.Web.Script.Services; Visual Basic Imports System.Web.Services Imports System.Web.Services.Protocols [...]

More »

Compute hash of a file

Computing the hash value of a file is quite strait forward. I use the routine below. It opens the file, specifies the hash-algorithm to use and returns the hash of the file. If you rather use MD5 hashes, just change hashAlgorithm into MD5CryptoServiceProvider. Public Function ComputeFileHash(ByVal fileName As String) As String   Dim hashAlgorithm As [...]

More »

Am I running as a 32 or 64-bit application?

Here’s an easy way to determine if a .NET application is running as either 32 or 64-bit  application. VB Protected Sub Page_Load(ByVal sender As Object, ByVal e As EventArgs)   If IntPtr.Size = 8 Then     Response.Write("64-bit")   ElseIf IntPtr.Size = 4 Then     Response.Write("32-bit")   End If End Sub C# protected void [...]

More »

Error message 401.2.: Unauthorized: Logon failed due to server configuration. (IIS7)

After installing Windows 7 my ASP.NET application displayed an Access is deniederror. The complete error message was: Error message 401.2.: Unauthorized: Logon failed due to server configuration.  Verify that you have permission to view this directory or page based on the credentials you supplied and the authentication methods enabled on the Web server.  Contact the Web [...]

More »

To comment or not to comment, that’s the question

Even though I’m a great advocate of commenting code, there are those thank think commenting is not always a good thing. As stated in the linked article, we must differentiate between API documentation and normal, inline comments. API documentation, imho, is just as necessary as the code it is trying to describe. I do use [...]

More »

HttpContext.Current.Request.UserHostAddress returns ::1

One would expect HttpContext.Current.Request.UserHostAddress to return the IP address of the client computer. On my developement machine this would be 127.0.0.1. The application I’m working on acts on this IP address, so it is fital to get the correct address. Since I’ve moved to Windows Server 2008 x64 on my laptop, I got ::1 as a [...]

More »

MultipleActiveResultSets (MARS), SQL server 2000 and LINQ

Using the MultipleActiveResultSets setting in a connection string allows one to have multiple datareaders open on the same connection, at the same time. This setting was introduced with SQL server 2005. Setting it with SQL server 2000 does not have any effect, or so I thought.

More »

Could not load file or assembly ‘Name’ or one of its dependencies. An attempt was made to load a program with an incorrect format.

On a 64-bit Windows installation this is caused by the fact that assemblies are compiled for x86 processors only. To change the compile settings do the following: Open the project properties Open the Compile tab Open the Advanced Compile Options… window Change the Target CPU from x86 to AnyCPU Recompile Happy programming!

More »

Connect PowerShell to MySQL

Using the MySQL.NET connector, it’s possible to connect to a MySQL database using PowerShell. /* replace path with your local /path/to/mysql/connector/MySQL.Data.dll */ [void][system.reflection.Assembly]::LoadFrom(\"d:\\tools\\mysql-connector\\bin\\MySQL.Data.dll\") $myconnection = New-Object MySql.Data.MySqlClient.MySqlConnection $myconnection.ConnectionString = \"server=localhost;user id=test;password=test;database=test;pooling=false\" $myconnection.Open() $mycommand = New-Object MySql.Data.MySqlClient.MySqlCommand $mycommand.Connection = $myconnection $mycommand.CommandText = "SHOW TABLES" $myreader = $mycommand.ExecuteReader() while($myreader.Read()){ $myreader.GetString(0) } This example will display all tables [...]

More »

return confirm() doesn’t work as expected inside UpdatePanel

When using a GridView with a ButtonField for deleting records, setting a return confirm(‘Are you sure?’) on the onclick event doesn’t prevent the event from firing to the server.My first try was with this code: <asp:buttonfield ButtonType="Image" ImageUrl="/images/b_drop.png" CommandName="DeleteRow" />

More »

UnidenCommander

I recently got hold of a Uniden UBC785XLT radio scanner. This device has a RS-232 port by which it can be controlled and programmed. As a programmer, what could be more fun than trying to write a little app to do just that. So here’s UnidenCommander (UC). It’s a remote control application for Uniden Bearcat [...]

More »

Brain Beckman has 2 new videos up

One of my Microsoft heroes, Brain Beckman, has 2 great new videos up on channel9 It’s a two part video called The Zen of Stateless State – The State Monad. View the videos after the click…||The Zen of Stateless State – The State Monad – Part 1|| ||The Zen of Stateless State – The State [...]

More »

How to connect to MICROSOFT##SSEE

Microsoft products such as Windows Server Update Services (WSUS) 3.0 and Windows Sharepoint Services (WSS) 3.0 ship with SQL Server 2005 Embedded Edition, also called Windows Internal Database.The Windows Internal Database is an embedded data service that can only be used by a handful of Windows Services. It is designed in such a way that [...]

More »

Method error 12030 when using CascadingDropDown

I followed the example about using CascadingDropDowns linked to a databse as described on http://www.asp.net/AJAX/AjaxControlToolkit/Samples/Walkthrough/CCDWithDB.aspx Unfortunatly, the code contains a little bug, resulting a Method error 12030 or Method error 12031 being displayed in the dropdownlist, instead of the expected data. Because the webservice is being called from (java)script, using ASP.NET AJAX, the enclosing class [...]

More »

C# IsNumeric alternative (c#)

Snipplet to compensate for the lack of an IsNumeric function in c# public bool IsNumeric(string s) { try { Int32.Parse(s); } catch { return false; } return true; } Alternatively you can use the following: Double.Tryparse(string s)

More »