Saturday, September 30, 2006

Enterprise Application Data Block Version 2.0

Since I really missed the convenience of version 1.0 of the enterprise application data block and wanted to reduce redundant code while making calls to the database I came up with a helper class much like SqlHelper class in the data block one.

Usage :


DBHelper dhp = new DBHelper();
DBParameter[] para = { new DBParameter("param_name", DbType.String, param_Value) };

return dhp.Query(@"Sql_query", para);


You will need to add the following classes to your project

using System;
using System.Data;
using System.Configuration;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using Microsoft.Practices.EnterpriseLibrary.Data;
using Microsoft.Practices.EnterpriseLibrary.Data.Sql;
using System.Data.Common;

///
/// Summary description for DBHelper
///

public class DBHelper
{

Database burstdb;


public DBHelper()
{
//
// TODO: Add constructor logic here
//

burstdb = DatabaseFactory.CreateDatabase();
}

public DataTable Query(string sqlText, DBParameter[] param)
{
DbCommand command = burstdb.GetSqlStringCommand(sqlText);
for (int i = 0; i < param.Length; i++)
{
burstdb.AddInParameter(command, param[i].Name,param[i].Type,param[i].DBValue);
}
burstdb.ExecuteDataSet(command);
DataSet ds = new DataSet();
burstdb.LoadDataSet(command, ds, "ds");
return ds.Tables[0];
}

public DataTable QuerySP(string spName, DBParameter[] param)
{
DbCommand command = burstdb.GetStoredProcCommand(spName);
for (int i = 0; i < param.Length; i++)
{
burstdb.AddInParameter(command, param[i].Name, param[i].Type, param[i].DBValue);
}
burstdb.ExecuteDataSet(command);
DataSet ds = new DataSet();
burstdb.LoadDataSet(command, ds, "ds");
return ds.Tables[0];
}

public void nonQuery(string sqlText, DBParameter[] param)
{
DbCommand command = burstdb.GetSqlStringCommand(sqlText);
for (int i = 0; i < param.Length; i++)
{
burstdb.AddInParameter(command, param[i].Name, param[i].Type, param[i].DBValue);
}
burstdb.ExecuteNonQuery(command);
}

public void nonQuerySP(string spName, DBParameter[] param)
{
DbCommand command = burstdb.GetStoredProcCommand(spName);
for (int i = 0; i < param.Length; i++)
{
burstdb.AddInParameter(command, param[i].Name, param[i].Type, param[i].DBValue);
}
burstdb.ExecuteNonQuery(command);
}


}




using System;
using System.Data;
using System.Configuration;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;

///
/// Summary description for DBParameter
///

public class DBParameter
{
string _name;
DbType _dbtype;
object _value;

public string Name
{
get { return _name; }
set { _name = value; }
}

public DbType Type
{
get { return _dbtype;}
set {_dbtype = value;}
}

public object DBValue
{
get { return _value; }
set { _value = value; }
}

public DBParameter(string name, DbType type,object value)
{
Name = name;
Type = type;
DBValue = value;
}


}

Wednesday, September 27, 2006

Install SVN on Win XP

Subversion (SVN)

From Eugene Lazutkin's blog

It looks like Subversion is the most reasonable choice for source control:

* It is free open source project available on virtually all platforms.
* It was designed as replacement for aging CVS, which is the most dominant source control system for distributed open source projects.
* It is well supported. After CVS it is the most mature and stable source control system.
* It is possible to find hosts, which offer SVN hosting for free or commercially.
* It looks like a preferred choice for new projects.
* It is easy to host internally.

A must read is free electronic book available in HTML and PDF formats here: http://svnbook.org/. Links to documentation, examples, tools, and clients can be found here: http://subversion.tigris.org/project_links.html.

Subversion provides access to repository using either Apache (via http or https) or its own proprietary svn protocol. The latter method supports secure SSH variation: svn+ssh protocol. Apache integration includes WebDAV support and (optional and not recommended) FrontPage support.

While there are many Subversion clients around, two are the most popular choices for Windows platform:

* RapidSVN (developed by Subversion developers)
* TortoiseSVN

I tried both of them and TortoiseSVN feels better for me. The caveat is it is integrated with Windows Explorer => pollutes right-click menu. RapidSVN is stand-alone program.

Let's install Subversion with TortoiseSVN. Below are step by step instructions inspired by Miguel Jimenez's excellent post on this subject: http://blogs.clearscreen.com/migs/archive/2005/01/21/824.aspx. Our goal is to run Subversion as a Windows service. In this case it may be placed on remote server and be available to all group members.

1. Download the latest Subversion binary.
2. Download the latest TortoiseSVN client software.
3. Download the latest SrvAny utility (it's a part of free Resource Kit, e.g. Windows Server 2003 Resource Kit Tools). Alternatively you can use my version extracted from the latest Resource Kit.
4. Install Subversion (run .msi file).
5. Install TortoiseSVN (run the installer). It will require to reboot.
6. Create a folder for your repository (e.g., C:\Repository). Create svn subfolder in it to keep SVN data separate from Trac data later on (e.g., C:\Repository\svn). Create one more subfolder in svn to host actual database (e.g., C:\Repository\svn\repo). Actual names and actual layout are up to you.
7. Right-click on repo subfolder (see example above) and select TortoiseSVN/Create Repository here....
1. It will ask you for type of repository.
2. Select FSFS — everybody recommends this new type. Ignore BDB.
3. Now you can run svnserve (it is in bin directory of Subversion) to test your installation: svnserve -d -r C:\Repository\svn\repo. It uses TCP port 3690.
4. Try to connect to it using TortoiseSVN or RapidSVN and make sure it works. Use connection string like that: svn://yourserver/.
8. Install SrvAny by copying it to a folder of your choice.
9. Install new service for svnserve (I've included a .doc file with manual for SrvAny and InstSrv).
1. Run InstSrv with following arguments: InstSrv svnserve SrvAny.exe. You can use any name instead of svnserve here. Sometimes fully qualified name is required for SrvAny.exe.
2. Run regedit and navigate to this key: HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\svnserve.
3. Create subkey Parameters.
1. Add Application string value with exact fully qualified path to svnserve, e.g., C:\Program Files\Subversion\bin\svnserve.exe.
2. Add AppParameters string value with following data: -d -r C:\Repository\svn\repo. If you used different repository folder, change the value accordingly.
4. Run the service using the standard Windows Services panel.
10. If you don't want to keep your repository wide open, it is time to modify security settings.
1. In subdirectory C:\Repository\svn\repo\conf create passwd file with following information:
[users]
user1 = password1
user2 = password2
2. Obviously you should use real user names and real passwords.
3. In the same directory create (or modify) file svnserve.conf:
[general]
anon-access = none
auth-access = write
password-db = passwd
realm = Subversion Repository
4. You can specify different file name for password-db and select different realm name. Realm is used to inform user about purpose of authentication.
5. Now use any SVN client to test connection to your new Subversion service.

If you want to serve several repositories, you should create several services for that. Obviously you should specify different ports for different repositories.