Archiv für die Kategorie ‘.NET’

Get the password of user IWAM_

Samstag, 17. Januar 2009

After trying some things in the IIS settings I wanted to change back to use the IWAM_* account. But for this I needed the password. I’ve searched and found some informations and tips to get the password that was used for the IUSR_* or IWAM_* accounts.

Auswahl der zu benutzenden Framework-Version

Mittwoch, 12. November 2008

Um eine .net-Applikation mit einer bestimmten Framework-Version auszuführen, kann diese im App.Conifg-File angegeben werden. Mit folgendem Beispiel wird die Anwendung mit dem Framework 1.1 ausgeführt, wenn man den Kommentar um das andere supportedRuntime-Tag setzt, wird das Framework 2.0 verwenden.

< ?xml version="1.0" encoding="utf-8">
<configuration>
   <startup>
      <supportedruntime version="v1.1.4322"/>
<!--      <supportedRuntime version="v2.0.50727"/>-->
   </startup>
</configuration>

Die Datei muss dabei dem Dateinamen der Anwendung mit angehängtem .config entsprechen, z.B. für die Anwendung “MyApp.exe” heisst die Datei “MyApp.exe.config”.

Slippery When Wet #2: SCOPE_IDENTITY and SqlDataReader

Samstag, 25. Oktober 2008

I proudly present to you the second in a infinite number of posts of “Slippery When Wet.” In these posts I show you a little bastard I stubled on.

Imagine you have a database table with a cloumn id of the data type integer that has set the IDENTITY. You use a stored procedure to insert a new entry into this table. Inside this stored procedure you use the SCOPE_IDENTITY() function to get the identifier created for this row. With RETURN SCOPE_IDENTITY() you give the identity to the caller.

You call this stored procedure from a SqlComand with ExecuteReader() that returns you an SqlDataReader object.

From this SqlDataReader you read now the identifier with GetInt32().

Wrong !

This will give you an InvalidCastException. SCOPE_IDENTITY()’s return type is numeric, although your identifier column is an integer. SqlDataReader’s GetXY functions do not convert the data and throw the exception when the data is not already of the right type.

The first solution

You can read the value with GetDecimal() and cast the value to an int:

int identifier = (int)reader.GetDecimal(0);

The second solution

You cast the identifier inside the stored procedure und return it already as an integer:

SELECT CAST(SCOPE_IDENTITY() AS int)

Whatever solution you choose, take care that you use always the same inside your application.

Exception after sending data async from a thread

Samstag, 24. Mai 2008

If you have a situation like this:

void MyThreadFunc()
{
// do some work

socket.BeginSend(buffer, 0, buffer.Length, 0, new AsyncCallback(MyCallback), s);
}

void MyCallback(IAsyncResult ar)
{
Socket s = (Socket) ar.AsyncState;
s.EndSend(ar);
}

And you send a big buffer over a slow connection it can happen that calling EndSend() will throw a SocketException ‘The I/O operation has been aborted because of either a thread exit or an application request’.

This happens because the Thread that started the sending is no more available when the sending ends. The only solution I know is to make sure the thread is still available or to use syncronous sending if possible.

Benutzen der NAnt-Properties

Mittwoch, 21. November 2007

Der Zugriff auf die NAnt-Properties ist meiner Meinung nach etwas unglücklich gewählt, da zwei verschiedene Varianten je nach Kontext benutzt werden müssen.

Folgendes Beispiel zeigt sehr schön die beiden Varianten, wie NAnt-Properties im jeweiligen Zusammenhang angewendet werden müssen:

<delete file="${Directory}${File}.new"
if="${file::exists(Directory + '' + File + '.new')}" />

Dieser Befehl löscht die Datei, falls sie vorhanden ist. Für den Dateinamen muss die Syntax mit dem ${} benutz werden, die so genannte ‘property expansion’.

Für die Bedingung wird dann die Methode für den Zugriff auf das Property innerhalb einer Expression benutzt. Dabei wird auf ${} verzichtet.

Exception “No web service found at:” with /js or /jsdebug

Freitag, 09. März 2007

With “ASP.NET 2.0 AJAX Extensions 1.0″ (I love this name with two version numbers inside…) you can request a JavaScript Proxy for a web service with appending /js or /jsdebug to the web service path, like “http://my-server/my-service.asmx/js”.

When I deployed my application I’ve got the InvalidOperationException “No web service found at:”. When I called the web service without /js or /jsdebug the web service worked (at least the generated forms in the Browser where shown).

I’ve spent a lot of time ’til I recognized the File my-service.asmx was not included in the deploy package. So without the /js appended the my-service.asmx file was not needed, the code from the compiled dll was executed directly, but when I added /js it needed the file.

Conclusion:
Don’t forget to add the .asmx files in the deployment of your ASP.NET AJAX Project!

Verhalten des System.Timers.Timer bei neusetzen des Intervalles

Dienstag, 31. Oktober 2006

Nur als kleine Gedächnisstütze für mich:

Wenn man beim System.Timers.Timer das Interval neu setzt, wird dieses nach dem nächsten Auslösen des Timers verwendet:

Kurzer Bespielcode:

using System;
public class MyClass
{
  private static System.Timers.Timer timer = new System.Timers.Timer();

  public static void Main()
  {
    timer.Elapsed += new System.Timers.ElapsedEventHandler(OnTimer);
    timer.Interval = 3000;
    timer.Start();

    System.Threading.Thread.Sleep(7000);
    timer.Interval = 2000;

    Console.ReadLine();
  }

  protected static void OnTimer(object sender, System.Timers.ElapsedEventArgs e)
  {
    Console.WriteLine(DateTime.Now.ToString());
  }
}

Ambiguous match found nach Publishen der ASP.NET Webseite

Mittwoch, 27. September 2006

Beim Entwickeln einer Web-Anwendung bin ich über eine Eigenart von ASP.NET 2.0 gestolpert. Beim Testen auf dem lokalen Rechner lief alles wie gewünscht. Nach dem Publishen der Webseite erhielt ich dann aber den Fehler:

Ambiguous match found

Als Fehlerzeile war die erste Zeile mit der

@Page

-Direktive angegeben.

Nach einigem Suchen im Internet fand ich bei Peter Johnson den Blog-Eintrag Ambiguous match found, der mich auf das Problem aufmerksam machte:

Innerhalb meiner Seite hatte ich ein hiddenField mit der ID

MyIdentifier

und eine

protected

Member-Variable mit dem Namen

myIdentifier

. Diese beiden Variablen lebten während dem Entwickeln in friedlicher Koexistenz, nach dem Publizieren der Webseite vertrugen sie sich aber nicht mehr. Leider liefert das Visual Studio weder während des Entwickelns noch beim Publizieren irgendwelche Warnungen oder Fehler. Nachdem ich

myIdentifier

in

theIdentifier

umbenannt hatte lief dann alles reibunglos.

Fehlendes ImageUrl bei asp:image erzeugt unerwünschtem Seitenaufruf

Dienstag, 26. September 2006

Stundenlang habe ich gesucht, bis ich den Fehler gefunden habe:

Unter bestimmten Umständen wurde meine Seite bei einem Postback erneut aufgerufen, aber mit

IsPostBack == false

. Bis ich dann herausgefunden habe, dass es am

asp:image

Tag liegt. Wenn das Attribut

ImageUrl

nicht angegeben wird, wird das Tag image mit einem leeren

src

Attribut erzeugt, was den Browser dazu veranlasst, als Bild die Seite laden zu wollen. Dies erzeugte den nicht gewünschten Seitenaufruf. Nachdem ich ein leeres Bild als Standardbild angegeben habe, passiert dieser unerwünschte Seitenaufruf nicht mehr.

ScottGu’s Blog : “Atlas” 1.0 Naming and Roadmap

Dienstag, 12. September 2006

Wie Scott Guthrie in seinem Blog schreibt, erhält Atlas mit der Version 1.0, die Ende Jahr erscheinen soll, einen ofiziellen Namen (bzw. drei):

  • Die Client-seitige Javascript Bibliothek wird zu Microsoft AJAX Library
  • Die Server-seitige Bibliothek (UpdatePanel) wird zu ASP.NET 2.0 Ajax Extensions
  • Das jetztige Atlas Control Toolkit wird zu ASP.NET Ajax Control Toolkit

Mit der Version 1.0 wird es auch ofiziellen Support für die Bibliotheken geben.