Syndication

I hope that you have had a good Halloween weekend like myself! My daughter did her first “trick or treat run” :-)

I’ve stumbled on some pieces of really good, have to have freeware:

1. Process Quick Link version 2 – This little util gives you an “i”-icon next to the processname in Taskmanager.

Clicking the “i” will give you a brief webpage describing the process and giving a suggestion if it is recommended to terminate it or not.

Vey handy when “stuff” is happening on you computer and you don’t know why!

image Click the “i” for Information!

2. Magic Disc – Lets you mount about 18 different diskimage formats(like ISO, NRG etc). It is freeware and works on all version of Windows(even x64). You can have any number of virtual drives you like and it integrates with explorer.

3. Sysinternals tools(now MS) – I don’t think anyone using their computer as a developer has missed the tools from Sysinternals? They’re great! So great that Microsoft bought them! There are tools for watching the network, processes, filesystem and more – highly recommended!

4. ImgBurn – A very good and free CD/DVD/ISO burner. Integrates nicely into explorer and runs fine on x64 as well as on x86!

That’s all folks!

// Lazze

Posted by Lars Siden
Filed under: , ,

This will be a brief introduction to the SQL Dependency object. I will demonstrate how to register a SQL Query for notification when the result of the query has changed. The main purpose of the dependency object is to ensure that cached data is up to date.

What you will need

  1. SQL Server 2005 or 2008
  2. Visual studio 2005/2008 - the downloadable example is made in VS2008. If you have VS2005 you can open the .csproj file instead of the .sln file.
  3. A database with a simple table
  4. SQL Management studio(express works fine)

The user connecting to the database needs to have the following SQL privileges:

GRANT SUBSCRIBE QUERY NOTIFICATIONS TO <database_principal>
GRANT CREATE QUEUE TO <database_principal>
GRANT CREATE SERVICE TO <database_principal>
GRANT CREATE PROCEDURE TO <database_principal>

If you connect as database owner(dbo) all is already set for you.

You may have to enable the service broker in SQL Server:

alter database <dbname> SET ENABLE_BROKER

To verify that the broker is running you can check properties in the databaseserver using SQL Management studio or run the following query

select is_broker_enabled from sys.databases where name = '<dbname>'

Make sure that you get "1" for the database you intend to use.

What's the magic?

It is really simple. You register the SQLCommand with a SQLDependency object and then SQL Sever will monitor that query and notify you when the result of the query changes. You will however only be notified once, so after you've been "pinged" you will have to register the query again. This is becuase keeping track of queries uses SQL Server resources so forcing you to register every time you want a callback ensures optimal usage of resoures.

Here are the key code lines for making a SQL Query with a callback dependency:

select id,name from dbo.DemoTbl // Our SQL Query to monitor
SqlDependency.Start(connstr);     
// Create and bind the SqlDependency object to the command object.           
SqlDependency dependency =new SqlDependency(command);           
dependency.OnChange += new OnChangeEventHandler(dependency_OnChange);
   

Here is a guide for writing queries that works with query-notification.    

Simple winforms example app

This is a very simple example that shows the basics that you need to get started. You'll need a simple database with a table with two columns. Use the following script to create a table that works with the example:

CREATE TABLE [dbo].[Demotbl](
    [ID] [int] IDENTITY(1,1) NOT NULL,
    [Name] [nvarchar](50) NOT NULL,
CONSTRAINT [PK_Demotbl] PRIMARY KEY CLUSTERED
(
    [ID] ASC
)WITH (PAD_INDEX  = OFF, STATISTICS_NORECOMPUTE  = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS  = ON, ALLOW_PAGE_LOCKS  = ON) ON [PRIMARY]
) ON [PRIMARY]

 

The example selects all lines from the demoTbl and displays them in a DataGridView. After starting the program, press the "Register Query" button to start the action. When the DataGrid comes back(probably empty) - start SQL Management Studio and open your table, insert or update some rows and see them magically appear in the DataGridView.

Download the example!

 Don't forget to edit the connectionstring in the example!

This example on demonstrates the simplest use for Query Notification. In real life you probably put the caching and dependency mechanism in the "middleware" so that all clients can use them.

image

This is a more likely real life scenario.

Ok, this was a short "heads up" - have fun!

// Lazze

What is Mono? (and can you have it in Stereo?)

 Mono is an open source port of Microsoft's .Net Framework. The founder of the project is Novell. Mono is primarily made to run under Linux but it will also work for Macintosh and Unix. The first part of the port targeted .NET core functionality and ASP.NET support. Mono is also supported on a number of embedded devices. In October 2008 Mono reached version 2 and many wished for features wasfinally implemented. All links and external resources will be listed in the end of the article.

Major changes for Mono release 2

  • ADO.NET 2.0 API for accessing databases.
  • ASP.NET 2.0 API for developing Web-based applications.
  • Windows.Forms 2.0 API to create desktop applications.
  • System.XML 2.0: An API to manipulate XML documents.
  • System.Core: Provides support for the Language Integrated Query (LINQ).
  • System.Xml.Linq: Provides a LINQ provider for XML.
  • System.Drawing 2.0 API: A portable graphics rendering API.
  • Full support for C# v3.0
  • Debugger for managed code
 

What can't you do in Mono?

Generally speaking all hard wired windows stuff is off limit.

  • All P/Invoke calls will fail. Some of them can be rewritten to use standard Linux API calls.
  • Third party extensions
  • Database support isn't 100%. More on this later.
 

What Mono gives you that is not in .NET Framework

( You can have it in stereo)

In addition to supporting the .NET Core functionality Mono also have libraries extending .Net, such as:
  • classes for Gtk+
  • Zip files
  • LDAP
  • OpenGL
  • Cairo
  • POSIX
  • and more

Tools

Reaching version 2 many of the tools for developing for Mono has matured.

  • Mono Migration Analyzer (MoMA). Will assist you in finding code that won't work on Mono.
  • Gendarme -  a IL code inspector tool that will analyze the code on a deeper level than just compiling. It uses the Cecil library
  • Mono Develop a GNOME base visual IDE for developing Mono applications
  • Eclipse - is a Java based IDE that can be used to develop Mono projects using IKVM(Java VM for .NET)

Database support

ADO .NET is more or less fully implemented in Mono release 2.  But just as on the windows platform it relies on the underlying database client software. Here is a short list of the most common databases and their support in Mono.

  1. MySQL - preferred database using Mono. The client is provided by "MySQL AB" and is licensed under the GPL license.
  2. SQL Server 2000(sp3) / SQL Server 2005 -works well. Most standard SQL queries and functions will work as expected. If you want to use integrated windows authentication the computer must be in the same domain as the database server.
  3. Oracle - more or less the same status as for SQL Server.
ASP.NET

ASP.NET is almost completely implemented in Mono release 2.  You can run ASP.NET in several different ways under Mono:

  • mod_mono for Apache - this is the most common and best way to run deployed ASP.NET applications using Mono.
  • FastCGI - a fast interprocess implementation of ASP.NET. Also a good way to run deployed ASP.NET applications. The following web servers are documented using FastCGI, Abyss Web Server,Cherokee HTTP Server ,Lighttpd and Nginx .
  • XSP - small web server written in C#. Mainly for testing during development.
The ASP.NET support is both for web forms and for web services.

Mono's ASP.NET does not implement the following features:

  • Precompiled web sites
  • WebParts APIs

WinForms

Mono do support WinForms but the support isn't so mature as for the other parts. However the support for WinForms is getting better day by day. There are a number of projects using WinForms mono and some good tutorials helping to convert from Visual Studio to Mono developer.

Resources

Want to test mono? No time to set it all up? Then the pre-prepared VM-Ware image is perfect for you. Just download the image and the VM-Ware player and off you go!

Here is the link for the VM-Ware image + other Mono downloads

Links

·    Mono projects homepage

·    Mono SQL Client

·    Mono Oracle Client

·    Mono MySQL Client

·    Gendarme  

·    Mono ASP.NET 

·    Mono ASP.NET Edit(work in progress)

·    Mono Developer

·    Mono Migration Analyzer(MoMa)

 

Posted by Lars Siden
Filed under: , , ,