Shortcut to Start and Stop MsSqlServer Service

by Emanuele 6/18/2008 12:13:00 PM
Very frequently I start and stop default istance of Sql Server, to deploy new stuff on the server or on my local machine.
I created two batch files on my desktop to speed up this operation.

First of all we test if the command line script run correctly or not.

Click Start -> Run -> type "cmd" to start command prompt.


Start SqlServer Default Istance

Type "net start mssqlserver" and press Enter.



Stop SqlServer Default Istance

Type "net stop mssqlserver" and press Enter.




If two commands run correctly, we can go on to create the batch files.

p.s. If you use Windows Vista, you must launch the commands with administrator privileges.


Create the shortcuts

Right click on desktop and select New -> Text Document.
Rename the file with "start sqlserver.bat"
Put the command "net start mssqlserver" in the file and save.

Right click on desktop and select New -> Text Document.
Rename the file with "stop sqlserver.bat"
Put the command "net stop mssqlserver" in the file and save.

If you use Windows Vista, right click and select "Run as administrator".

Log4net: use Sql Server to log your application events

by Emanuele 2/23/2008 2:26:00 PM

In the previous article on the Log4net configuration, I explain how to configure Log4net with the file appender.
In this article I explain how to configure Log4net with the Sql Server appender.
It is very similar, but we see in detail the new configuration.

Download

You can download the latest version of Log4net from this location.

Add reference to your solution

In Visual Studio 2005 select Project -> Add Reference.
In the tab Browse, find and select the dll Log4net.dll in your local folder.

Modify web.config

Into web.config file add this code into the section Configuration->Configsections:

<configSections>
    <section name="log4net"
      type="log4net.Config.Log4NetConfigurationSectionHandler, log4net" /> 
</configSections>

<log4net>
  <appender name="ADONetAppender" type="log4net.Appender.ADONetAppender">
    <bufferSize value="100" />
    <connectionType value="System.Data.SqlClient.SqlConnection, System.Data, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" />
    <connectionString value="server=localhost; uid=; pwd=; database=" />
    <commandText value="INSERT INTO Log ([Date],[Thread],[Level],[Logger],[Message],[Exception]) VALUES
       (@log_date, @thread, @log_level, @logger, @message, @exception)" />
    <parameter>
      <parameterName value="@log_date" />
      <dbType value="DateTime" />
      <layout type="log4net.Layout.RawTimeStampLayout" />
    </parameter>
    <parameter>
      <parameterName value="@thread" />
      <dbType value="String" />
      <size value="32" />
      <layout type="log4net.Layout.PatternLayout">
        <conversionPattern value="%t" />
      </layout>
    </parameter>
    <parameter>
      <parameterName value="@log_level" />
      <dbType value="String" />
      <size value="512" />
      <layout type="log4net.Layout.PatternLayout">
        <conversionPattern value="%p" />
      </layout>
    </parameter>
    <parameter>
      <parameterName value="@logger" />
      <dbType value="String" />
      <size value="512" />
      <layout type="log4net.Layout.PatternLayout">
        <conversionPattern value="%c" />
      </layout>
    </parameter>
    <parameter>
      <parameterName value="@message" />
      <dbType value="String" />
      <size value="4000" />
      <layout type="log4net.Layout.PatternLayout">
        <conversionPattern value="%m" />
      </layout>
    </parameter>
    <parameter>
      <parameterName value="@exception" />
      <dbType value="String" />
      <size value="2000" />
      <layout type="log4net.Layout.ExceptionLayout" />
    </parameter>
  </appender>
  <root>
    <level value="DEBUG" />
    <appender-ref ref="ADONetAppender" />
  </root>
</log4net>

Change the connectionstring parameters to connect to your database.

Create the table

In your database, create the table to use Log4net. 

CREATE TABLE [dbo].[Log](
    [Id] [int] IDENTITY(1,1) NOT NULL,
    [Date] [datetime] NULL,
    [Thread] [varchar](255) NULL,
    [Level] [varchar](50) NULL,
    [Logger] [varchar](255) NULL,
    [Message] [varchar](4000) NULL,
    [Exception] [varchar](2000) NULL
) ON [PRIMARY]

Edit the Global.asax file

In the event "Application_Start" of the file Global.asax add this line:

log4net.Config.XmlConfigurator.Configure();

Begin to log

In every page you want to log something, add the static variable like below:
private static readonly ILog log = LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType);

This class has 5 levels of severity to log the operations:

log.Debug("log something at this level")
log.Info("log something at this level")
log.Warn("log something at this level");
log.Error("log something at this level");
log.Fatal("log something at this level");

You find the official documentation at this link.

If you want to log on the file system, read the previous article on Log4net.

Launch a DTS from Asp.net page

by Emanuele 11/7/2007 2:52:00 PM

Introduction

Data Trasformation Services (DTS) is a tool and set of programmable objects that lets you extract, trasform and consolidate data from various source into various destinations.

How to

Launch a DTS from Asp.net page is much useful, when you must import some data from disparate sources.
First, add reference Microsoft.SqlServer.ManagedDTS to project.
Place into the class the follow using:

using Microsoft.SqlServer.Dts.Runtime;

Now, into the page load event place this code:

string
pkgLocation;
Package pkgImport;
Application appImport;
DTSExecResult pkgResults;

pkgLocation = @"c:\temp\DtsTest.dtsx";
appImport = new Application();
pkgImport = appImport.LoadPackage(pkgLocation, null);
pkgResults = pkgImport.Execute();

if (pkgResults == DTSExecResult.Success)
{
    TxtEsito.text = "DTS Eseguito con successo.";
}

Also we can

Also, we can see the state of job using the follow state enumeration http://msdn2.microsoft.com/en-us/library/microsoft.sqlserver.dts.runtime.dtsexecresult.aspx



Powered by BlogEngine.NET 1.3.1.0
Theme by Emanuele Bartolesi

About the author

Name of author Emanuele Bartolesi
I'm a senior developer and project manager.

Contact me Contact me

Calendar

<<  December 2008  >>
MoTuWeThFrSaSu
24252627282930
1234567
891011121314
15161718192021
22232425262728
2930311234

View posts in large calendar

Disclaimer

The opinions expressed herein are my own personal opinions and do not represent my employer's view in anyway.

© Copyright 2008

Sign in

Download Day 2008