DCSIMG
November 2008 - Posts - Gilad Lavian's Blog

Gilad Lavian's Blog

In Development

November 2008 - Posts

MS-SQL: Changing single user Database to multi users

The problem:

Changes to the state or options of database "DatabaseName" cannot be made at this time. The database is in single-user mode, and a user is currently connected to it.

 

The solutions:

use master
go

alter database "DatabaseName" set multi_user;

 

If there's users connected to the Database and you don't know who, you can use "sp_who2" to check who's connected.

 

You can kill only user process by there SPID:

kill 15;

First Impression: Oracle g11 Developer Tools

oralogo_small The g11 release of Oracle Developers Tools (ODT) includes powerful features integrated with Visual Studio.

I must say that this is a major change, the features included in this version makes the common developing and database maintenance much easier.

 

Its supports:

  • Visual Studio 2008/2005/2003
  • Oracle database version 9.2 and later


Enhanced integration with Visual Studio 2008 and Visual Studio 2005

 

Integrated

 


An Oracle Database Project to provide source control of Oracle SQL scripts

 

 SourceControl

 

Integration with Microsoft Query Designer

 

QueryDesigner

 

Read more...

Generic EventArgs<T>

A good way for passing data with EventArgs

public class EventArgs<TValue1> : EventArgs
{
    public TValue1 Value1 { get; set; }
    public EventArgs(TValue1 value1)
    {
        Value1 = value1;
    }
}

Should you want to pass 2 values

public class EventArgs<TValue1, TValue2> : EventArgs<TValue1>
{
    public TValue2 Value2 { get; set; }
    public EventArgs(TValue1 value1, TValue2 value2)
        : base(value1)
    {
        Value2 = value2;
    }
}

The same goes to CancelEventArgs

public class CancelEventArgs<TValue1> : CancelEventArgs
{
    public TValue1 Value1 { get; set; }
    public CancelEventArgs(TValue1 value1)
    {
        Value1 = value1;
    }
}

Extension Methods: IDataReader.GetValue<T>

A convenient solution to get value from IDataReader field.

/// <summary>
/// Gets the reader field value.
/// </summary>
/// <typeparam name="TField">The type of the field.</typeparam>
/// <param name="reader">The reader.</param>
/// <param name="fieldName">Name of the field.</param>
/// <returns></returns>
public static TField GetValue<TField>(this IDataReader reader, string fieldName)
{
    //Guard
    if (string.IsNullOrEmpty(fieldName)) throw new ArgumentException("fieldName");
    return (TField)reader.GetValue(reader.GetOrdinal(fieldName));
}

Usage:

IDataReader reeader = _database.ExecuteReader(command);
if (reader.Read())
{
    int productId = reader.GetValue<int>("ProductId");
}