Site Search:
Sign in | Join | Help
4Penny.net

VB.NET

Notes, Tricks and Tips on VB.NET

June 2008 - Posts

  • Subsonic VB Setup

    Web.config 

    <configuration>
     <configSections>
      
               <section name="SubSonicService" type="SubSonic.SubSonicSection, SubSonic" requirePermission="false"/>
      
     </configSections>

    <SubSonicService defaultProvider="OnlineNotes">
        <providers>
          <clear/>
          <add name="OnlineNotes" type="SubSonic.SqlDataProvider, SubSonic" connectionStringName="OnlineNotes" generatedNamespace="OnlineNotes"   includeTableList="^_" includeProcedureList="^FP"/>
        </providers>
    </SubSonicService>

     

    VisualStudio > Tools > External Tools > Add
     Name is Subsonic DAL and browse for the exe file
      C:\Program Files\SubSonic\SubSonic 2.0.3\SubCommander\sonic.exe
     
     Arguments: generate/out App_Code\Generated/lang vb

     Initial Directory: Project Directory
     
     x Use Output Window                            x Prompt for arguments

  • RUN my Windows Service without installing and starting it

    I am often asked the question "Can't I just RUN my Windows Service without installing and starting it?".

    My answer usually is "No, you can't but..."

    There is a "but": you can create your Windows service as a hybrid application, so it will run as a console application also.

    Why would you want to do that?
    • It makes debugging from within Visual Studio a breeze
    • Sometimes you want to show some debugging information in a production environment by using Console.WriteLine()
    • You don't always want to install your service to see if it runs in a particular environment
    Turning a .NET Windows service into a hybrid application is actually very simple. In your Main() method you add the following:
    static class Program
    {
      static void Main(params string[] parameters)
      {
        if (parameters.Length > 0 && parameters[0].ToLower() == "/console")
          new MyService().RunConsole(parameters);
        else
          ServiceBase.Run(new ServiceBase[] { new MyService() });
       }
    }
    Then, in your service class, add a RunConsole() method:
       public void RunConsole(string[] args)
       {
          OnStart(args);

          Console.WriteLine("Service running... Press any key to stop");
         
          Console.Read();
       
          OnStop();
       }
    That's all there is to it. To run your service as a console app, just specify "/console" as the first paramter when running the .EXE.