Archive for September, 2008

h1

Timeout SQL problem when calling procedure

September 17, 2008

What happens  if you make some difficult stored procedure (SP) and call it by ADO for example in connected mode?? All code is just pseudo….

  • We have this code: 

    Command cmd = new  SqlCommand(“LongCall”,con)    ;
    cmd.CommandType = CmdType.StroredProcedure;
    cmd.ExecuteNonQuery();

 

  • We have this procedure
    CREATE  PROCEDURE  LongCall AS
      …….Inside of LongCall SP can be cascade calling of selects    
          SELECT * FROM ( SELECT * ……( SELECT *)  ) basically  something with huge complexity

What happened??  ExecuteNonQuery closes connection. Implicitly after 30 seconds.  So what you have to do?  
 

  • You can set TimeOut
    cmd.TimeOut = 100; //sets timeout to 100 seconds
     
  • You can disable Timeout
    cmd.Timeout = 0;  //calling of cmd.ExecuteNonQuery finish however LongCall ends.
     
  • You should call asynchronous ExecuteNonQuery
    IAsyncResult result = cmd.BeginExecuteReader(CommandBehavior.CloseConnection)
    while(!result.IsCompleted)
    {
      ….
    }
    cmd.EndExecuteReader();

     

  • Take a thing on your Stored Procedure LongCall. Can you degrease complexity??
    What about make a cache!! Use temporary  tables as much as you can.  Replace Views by selects etc…

http://www.csharphelp.com/archives4/archive640.html

h1

Gacutil

September 16, 2008

In this Article I want to just describe, where you can find your gacutil and how to write out your asseblies into the file.

I don’t know why, buut there are two gacutils:

  • C:\WINDOWS\Microsoft.NET\Framework\v1.1.4322\gacutil.exe
  • C:\WINDOWS\system32\dllcache\gacutil.exe

You can write out your GAC by gacutil.exe /L >> aaa.txt

Assemblies in the GAC you can find in hidden folder

  • C:\WINDOWS\assembly
h1

How to play sound in .NET

September 8, 2008

using System.Runtime.InteropServices;

namespace NotterdamDLX.DLX

{

/// <summary>
/// Summary description for Sound.
/// </summary>

   public class Sound

   {

[DllImport("winmm.dll")]

// play asynchronously

       public static extern long PlaySound(String lpszName, long hModule, long dwFlags);

// use file name

public static int SND_ASYNC    = 0×0001;   
       // purge non-static events

       public static int SND_FILENAME = 0×00020000;  

       public static int SND_PURGE    = 0×0040;    

 
       public Sound()      {}

      
      
public static void PlaySound(string fName)

       {

          PlaySound(fName, 0,SND_ASYNC |  SND_FILENAME );

       }

  }

}

h1

Easy serialization in c#

September 3, 2008

 

Following code works for general types without types which implememnts IDictionary. I’am serializing List<T> in my examples, but you can serialize all  types which contains [Serializable] attribute + implicit public constructor + public class of type.

 


Serialization

public static void Serialize<T>(T entity)
{
  
XmlSerializer xmlSerializer = new XmlSerializer(typeof(T));
  
using (FileStream fstream = new FileStream(@”blabla.xml”, FileMode.Create, FileAccess.Write, FileShare.None))
  
{
        
xmlSerializer.Serialize(fstream, entity);
  
}
}

 

 

Deserialization

public static T Deserialize<T>()
{
  
XmlSerializer xmlSerializer = new XmlSerializer(typeof(T));
  
T result;
  
using (FileStream fstream = new FileStream(@”blabla.xml”, FileMode.Open, FileAccess.Read, FileShare.None))
  
{
      
result = (T)xmlSerializer.Deserialize(fstream);
  
}
  
return result;
}

 

Calling code

Serialize<List<Aaa>>(list);

List<Aaa> list2 = Deserialize<List<Aaa>>();

 

h1

Zlepšovatel

September 2, 2008
h1

Security settings for this service require Windows Authentication but it is not enabled for the IIS application that hosts this service.

September 1, 2008

I obtained this error when i tested my WCF Service.

Security settings for this service require Windows Authentication but it is not enabled for the IIS application that hosts this service.

Solution

IIS->select virtual directory with services -> Properties -> Directory Security tab-> Edit… -> Check Integrated windows authentication. Uncheck Anonymous access.

Then open command line and execute iisreset

h1

Application path to user profile

September 1, 2008

Sometimes we need to place data in dependence on user profile. That’s meansthat user1 will work on computer1. His settings will be stored to application Data folder and stored to GP during logout. When he logs to computer2 than GP loads stored data from serevr.  Code for getting path to ApplicationData folder is here:

Code

 

private static String GetCacheFileName()
{
 
String path = Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData) + “\\AppName\\”;
  
if (!Directory.Exists(path))
       
Directory.CreateDirectory(path);
  
return path + “contact_cache.xml”;
}

 

 Result

Path to hidden folder C:\Documents and Settings\userName.DOMAIN\Application Data\AppName\contact_cache.xml