Computer and me

May 2, 2010

ASP.NET MVC 2 client validation with Enterprise Library 5.0 Application Validation Block

Filed under: Uncategorized — er2v @ 10:29 am

Not so long ago I learned about new validation aaproach in MVC 2. It’s realy cool and extensible.

My favorite validation framework is Application Validation Block from Enterprise Library 5.0 from Microsoft’s patterns and practices team. It’s widely adopted and I thought that there is some implementations of validation using this framevork for MVC 2. There were not, and this is realy surprised me.

All I found was this post from Brad Wilson – so this was my start point in implementation of full featured support for Validation Block. As MVC’s 2 approach is realy extensible it was not very hard, but there is a lot of work if you want to do something realy good.

I don’t want to do everething by myself 🙂 so I decided to make it available via CodePlex. Meet – my contribution to the hard work of validation 🙂


April 22, 2010

How to create Microsoft SDKs v6.0A Bootstrapper DotNetFx35SP1

Filed under: Uncategorized — er2v @ 6:01 pm

As I’ve found out there were no files for .Net Framework 3.5 SP1 in the Microsoft SDKs\Windows\v6.0A\Bootstrapper\Packages\DotNetFx35SP1 folder. There were only packages.xml and en folder with product.xml and eula.

Actualy it’s not hard to create it by youself.

  • Clear Microsoft SDKs\Windows\v6.0A\Bootstrapper\Packages\DotNetFx35SP1 folder
  • Just download framework installer, open it whith archiver like rar or 7zip and copy it’s content to the Microsoft SDKs\Windows\v6.0A\Bootstrapper\Packages\DotNetFx35SP1 folder.
  • Download folder with product.xml, package.xml and en folder from here, and put it’s content to Microsoft SDKs\Windows\v6.0A\Bootstrapper\Packages\DotNetFx35SP1

The files product.xml file in download addreses issue that is described in this document in the paragraph.

ClickOnce IIS7 Unable to add ‘dotnetfx35sp1/dotNetFX20/aspnet.msp’ to the Web site.

Filed under: Uncategorized — er2v @ 5:27 pm

Today I decided to publish our internal project with ClickOnce technologie on our IIS 7 web site and I’ve got several problems google helped me to solve. But there was one that I had to solve by myself.

I desided, that .Net framework 3.5 sp1 should be located in same location application does, not to download it from vendors server.
After I pressed publish button some files been published, but the process had stop when it tryed to publish dotnetfx35sp1/dotNetFX20/aspnet.msp file and showed error following error

Failed to copy file ‘C:\Dev\work\ASC-projects\Asc.Inside.Client\bin\Debug\app.publish\dotnetfx35sp1\dotNetFX20\aspnet.msp’ to ‘http://svnsrv/AscProjects/dotnetfx35sp1/dotNetFX20/aspnet.msp’. Unable to add ‘dotnetfx35sp1/dotNetFX20/aspnet.msp’ to the Web site. The server unexpectedly closed the connection.

The reason was in MIME types. There were no MIME type for .msp

So all I did was adding

.msp application/octed-stream
.msu application/octed-stream

in the IIS Manager. There are button to config MIME Types in the features view of server node or website node.

August 8, 2009

Form for Connection String Building

Filed under: Uncategorized — er2v @ 1:24 pm

Few days ago I had t0 create form, that will just let user to define connection string. I was pretty shure that there I’ll find working example in google, but I could not. So I had to write it by myself.

First of all I’ve created class SimpleConnectionStringBuilder, that implements INotifyPropertyChanged, so I could bind it.

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data.SqlClient;
using System.ComponentModel;

namespace Asc.Utils.WinForms {

	public class SimpleConnectionStringBuilder : INotifyPropertyChanged
		private SqlConnectionStringBuilder stringBuilder = new SqlConnectionStringBuilder();

		public SimpleConnectionStringBuilder() { }

		public SimpleConnectionStringBuilder(string ConnectionString) {
			stringBuilder.ConnectionString = ConnectionString;

		public string ConnectionString {
			get { return stringBuilder.ConnectionString; }
			set { stringBuilder.ConnectionString = value; }

		public string ServerName {
			get { return stringBuilder.DataSource; }
			set {
				stringBuilder.DataSource = value;
				PropertyChanged(this, new PropertyChangedEventArgs("ServerName"));

		public string Database {
			get { return stringBuilder.InitialCatalog; }
			set {
				stringBuilder.InitialCatalog = value;
				PropertyChanged(this, new PropertyChangedEventArgs("Database"));

		public string User {
			get { return stringBuilder.UserID; }
			set {
				stringBuilder.UserID = value;
				PropertyChanged(this, new PropertyChangedEventArgs("User"));

		public string Password {
			get { return stringBuilder.Password; }
			set {
				stringBuilder.Password = value;
				PropertyChanged(this, new PropertyChangedEventArgs("Password"));

		public bool IntegratedSecurity {
			get { return stringBuilder.IntegratedSecurity; }
			set {
				stringBuilder.IntegratedSecurity = value;
				PropertyChanged(this, new PropertyChangedEventArgs("IntegratedSecurity"));

		#region INotifyPropertyChanged Members

		public event PropertyChangedEventHandler PropertyChanged;


So then I’ve created form with the following code:

using System;
using System.ComponentModel;
using System.Data;
using System.Data.Sql;
using System.Data.SqlClient;
using System.Windows.Forms;

namespace Asc.Utils.WinForms {

public partial class ConnectionBuilderForm : System.Windows.Forms.Form {

public static string GetConnectionString() {
ConnectionBuilderForm form = new ConnectionBuilderForm();
return ReadString(false, ref form);

public static string GetConnectionString(bool ShowTopMost) {
ConnectionBuilderForm form = new ConnectionBuilderForm();
return ReadString(ShowTopMost, ref form);

public static string ModifyConnectionString(string ConnectionString) {
return ModifyConnectionString(ConnectionString, false );

public static string ModifyConnectionString(string ConnectionString, bool ShowTopMost ) {
ConnectionBuilderForm form = new ConnectionBuilderForm(ConnectionString);
return ReadString(ShowTopMost, ref form);


private static string ReadString(bool ShowTopMost, ref ConnectionBuilderForm form) {
form.TopMost = ShowTopMost;
string connectionString = form.ConnectionString;
form = null;
return connectionString;

public ConnectionBuilderForm() {
simpleConnectionStringBuilderBindingSource.DataSource = ConnectionBuilder;
ConnectionBuilder.PropertyChanged += new PropertyChangedEventHandler(ConnectionBuilder_PropertyChanged);

public ConnectionBuilderForm(string ConnectionString)
: this() {
ConnectionBuilder.ConnectionString = ConnectionString;

public string ConnectionString {
get { return ConnectionBuilder.ConnectionString; }
set { ConnectionBuilder.ConnectionString = value; }

private SimpleConnectionStringBuilder ConnectionBuilder = new SimpleConnectionStringBuilder();

private bool needToReloadDataBases = true;

private void ConnectionBuilder_PropertyChanged(object sender, PropertyChangedEventArgs e) {
needToReloadDataBases = true;

private void ReloadDatabases() {
SqlConnection sqlConx = new SqlConnection(ConnectionBuilder.ConnectionString);

try {
DataTable tblDatabases = tblDatabases = sqlConx.GetSchema("Databases");
foreach (DataRow row in tblDatabases.Rows) {
needToReloadDataBases = false;
cmbBd.DroppedDown = true;

catch {
finally {

private void radioItegratedSequrity_SelectedIndexChanged(object sender, EventArgs e) {
txtPassword.Enabled = !radioButton1.Checked;
txtUser.Enabled = !radioButton1.Checked;

private void btnTest_Click(object sender, EventArgs e) {
SqlConnection sqlConx = new SqlConnection(ConnectionBuilder.ConnectionString);
bool success = true;
Exception exception = null;
try {
catch (Exception exc) {
success = false;
exception = exc;
finally {

if (success) {
MessageBox.Show("Connection successfully tested", "Success");
else {
MessageBox.Show("Connection failed:\n " + exception.Message, "Fail");

private void btnSave_Click(object sender, EventArgs e) {

private void FindNetworkServers() {
var instance = SqlDataSourceEnumerator.Instance;
var table = instance.GetDataSources();
foreach (DataRow row in table.Rows) {
string serverName = row["ServerName"].ToString();
string instanceName = row["InstanceName"].ToString();

string serverFullName = serverName +
(instanceName != string.Empty && instanceName != "\\" ? "\\" + instanceName : "");
if (InvokeRequired) {
Invoke(new Action(() => cmbServer.Items.Add(serverFullName)));
else {

private BackgroundWorker backgroundWorker = new BackgroundWorker();
private bool serversBeenAlreadySearched = false;

private void bgw_RunWorkerCompleted(object sender, RunWorkerCompletedEventArgs e) {
serversBeenAlreadySearched = true;
ajax.Visible = false;
cmbServer.DroppedDown = true;

private void bgw_DoWork(object sender, DoWorkEventArgs e) {
Invoke(new Action(() => ajax.Visible = true));

private void cmbServer_DropDown(object sender, EventArgs e) {
if (!backgroundWorker.IsBusy && !serversBeenAlreadySearched) {
backgroundWorker.DoWork += new DoWorkEventHandler(bgw_DoWork);
backgroundWorker.RunWorkerCompleted += new RunWorkerCompletedEventHandler(bgw_RunWorkerCompleted);

private void cmbBd_DropDown(object sender, EventArgs e) {
if (needToReloadDataBases) {
needToReloadDataBases = false;

private void ConnectionBuilderForm_Load(object sender, EventArgs e) {


And the designer class was

using System.Windows.Forms;
namespace Asc.Utils.WinForms {
	partial class ConnectionBuilderForm {
		/// Required designer variable.
		private System.ComponentModel.IContainer components = null;

		/// Clean up any resources being used.
		/// true if managed resources should be disposed; otherwise, false.
		protected override void Dispose(bool disposing) {
			if (disposing && (components != null)) {

		#region Windows Form Designer generated code

		/// Required method for Designer support - do not modify
		/// the contents of this method with the code editor.
		private void InitializeComponent() {
			this.components = new System.ComponentModel.Container();
			System.ComponentModel.ComponentResourceManager resources = new System.ComponentModel.ComponentResourceManager(typeof(ConnectionBuilderForm));
			this.btnSave = new System.Windows.Forms.Button();
			this.btnTest = new System.Windows.Forms.Button();
			this.cmbBd = new System.Windows.Forms.ComboBox();
			this.simpleConnectionStringBuilderBindingSource = new System.Windows.Forms.BindingSource(this.components);
			this.txtPassword = new System.Windows.Forms.TextBox();
			this.txtUser = new System.Windows.Forms.TextBox();
			this.cmbServer = new System.Windows.Forms.ComboBox();
			this.ajax = new System.Windows.Forms.PictureBox();
			this.labelControl1 = new System.Windows.Forms.Label();
			this.labelControl2 = new System.Windows.Forms.Label();
			this.labelControl3 = new System.Windows.Forms.Label();
			this.labelControl4 = new System.Windows.Forms.Label();
			this.radioButton1 = new System.Windows.Forms.RadioButton();
			this.radioButton2 = new System.Windows.Forms.RadioButton();
			// btnSave
			this.btnSave.Location = new System.Drawing.Point(271, 195);
			this.btnSave.Name = "btnSave";
			this.btnSave.Size = new System.Drawing.Size(90, 30);
			this.btnSave.TabIndex = 10;
			this.btnSave.Text = "Save";
			this.btnSave.Click += new System.EventHandler(this.btnSave_Click);
			// btnTest
			this.btnTest.Location = new System.Drawing.Point(169, 195);
			this.btnTest.Name = "btnTest";
			this.btnTest.Size = new System.Drawing.Size(91, 30);
			this.btnTest.TabIndex = 9;
			this.btnTest.Text = "Test";
			this.btnTest.Click += new System.EventHandler(this.btnTest_Click);
			// cmbBd
			this.cmbBd.DataBindings.Add(new System.Windows.Forms.Binding("Text", this.simpleConnectionStringBuilderBindingSource, "Database", true));
			this.cmbBd.Location = new System.Drawing.Point(115, 164);
			this.cmbBd.Name = "cmbBd";
			this.cmbBd.Size = new System.Drawing.Size(246, 21);
			this.cmbBd.TabIndex = 8;
			this.cmbBd.DropDown += new System.EventHandler(this.cmbBd_DropDown);
			// simpleConnectionStringBuilderBindingSource
			this.simpleConnectionStringBuilderBindingSource.DataSource = typeof(Asc.Utils.WinForms.SimpleConnectionStringBuilder);
			// txtPassword
			this.txtPassword.DataBindings.Add(new System.Windows.Forms.Binding("Text", this.simpleConnectionStringBuilderBindingSource, "Password", true));
			this.txtPassword.Location = new System.Drawing.Point(115, 133);
			this.txtPassword.Name = "txtPassword";
			this.txtPassword.PasswordChar = '*';
			this.txtPassword.Size = new System.Drawing.Size(246, 20);
			this.txtPassword.TabIndex = 7;
			// txtUser
			this.txtUser.DataBindings.Add(new System.Windows.Forms.Binding("Text", this.simpleConnectionStringBuilderBindingSource, "User", true));
			this.txtUser.Location = new System.Drawing.Point(115, 102);
			this.txtUser.Name = "txtUser";
			this.txtUser.Size = new System.Drawing.Size(246, 20);
			this.txtUser.TabIndex = 6;
			// cmbServer
			this.cmbServer.DataBindings.Add(new System.Windows.Forms.Binding("Text", this.simpleConnectionStringBuilderBindingSource, "ServerName", true));
			this.cmbServer.Location = new System.Drawing.Point(115, 8);
			this.cmbServer.Name = "cmbServer";
			this.cmbServer.Size = new System.Drawing.Size(246, 21);
			this.cmbServer.TabIndex = 4;
			this.cmbServer.DropDown += new System.EventHandler(this.cmbServer_DropDown);
			// ajax
			this.ajax.BackColor = System.Drawing.Color.Transparent;
			this.ajax.Image = ((System.Drawing.Image)(resources.GetObject("ajax.Image")));
			this.ajax.Location = new System.Drawing.Point(86, 4);
			this.ajax.Name = "ajax";
			this.ajax.Size = new System.Drawing.Size(26, 26);
			this.ajax.TabIndex = 12;
			this.ajax.TabStop = false;
			this.ajax.Visible = false;
			// labelControl1
			this.labelControl1.AutoSize = true;
			this.labelControl1.Location = new System.Drawing.Point(5, 8);
			this.labelControl1.Name = "labelControl1";
			this.labelControl1.Size = new System.Drawing.Size(70, 13);
			this.labelControl1.TabIndex = 0;
			this.labelControl1.Text = "Server name:";
			// labelControl2
			this.labelControl2.Location = new System.Drawing.Point(5, 102);
			this.labelControl2.Name = "labelControl2";
			this.labelControl2.Size = new System.Drawing.Size(107, 20);
			this.labelControl2.TabIndex = 6;
			this.labelControl2.Text = "User: ";
			// labelControl3
			this.labelControl3.Location = new System.Drawing.Point(5, 133);
			this.labelControl3.Name = "labelControl3";
			this.labelControl3.Size = new System.Drawing.Size(57, 20);
			this.labelControl3.TabIndex = 7;
			this.labelControl3.Text = "Password:";
			// labelControl4
			this.labelControl4.Location = new System.Drawing.Point(5, 164);
			this.labelControl4.Name = "labelControl4";
			this.labelControl4.Size = new System.Drawing.Size(77, 20);
			this.labelControl4.TabIndex = 8;
			this.labelControl4.Text = "Database:";
			// radioButton1
			this.radioButton1.AutoSize = true;
			this.radioButton1.DataBindings.Add(new System.Windows.Forms.Binding("Checked", this.simpleConnectionStringBuilderBindingSource, "IntegratedSecurity", true));
			this.radioButton1.Location = new System.Drawing.Point(15, 45);
			this.radioButton1.Name = "radioButton1";
			this.radioButton1.Size = new System.Drawing.Size(145, 17);
			this.radioButton1.TabIndex = 13;
			this.radioButton1.Text = "Windows Authentification";
			this.radioButton1.UseVisualStyleBackColor = true;
			this.radioButton1.CheckedChanged += new System.EventHandler(this.radioItegratedSequrity_SelectedIndexChanged);
			// radioButton2
			this.radioButton2.AutoSize = true;
			this.radioButton2.Checked = true;
			this.radioButton2.Location = new System.Drawing.Point(15, 69);
			this.radioButton2.Name = "radioButton2";
			this.radioButton2.Size = new System.Drawing.Size(156, 17);
			this.radioButton2.TabIndex = 14;
			this.radioButton2.TabStop = true;
			this.radioButton2.Text = "SQL Server Authentification";
			this.radioButton2.UseVisualStyleBackColor = true;
			this.radioButton2.CheckedChanged += new System.EventHandler(this.radioItegratedSequrity_SelectedIndexChanged);
			// ConnectionBuilderForm
			this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
			this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
			this.ClientSize = new System.Drawing.Size(367, 229);
			this.ControlBox = false;
			this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedDialog;
			this.Name = "ConnectionBuilderForm";
			this.ShowIcon = false;
			this.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen;
			this.Text = "Connection";
			this.Load += new System.EventHandler(this.ConnectionBuilderForm_Load);



		private ComboBox cmbServer;
		private ComboBox cmbBd;
		private TextBox txtPassword;
		private TextBox txtUser;
		private System.Windows.Forms.Button btnSave;
		private System.Windows.Forms.Button btnTest;
		private System.Windows.Forms.BindingSource simpleConnectionStringBuilderBindingSource;
		private System.Windows.Forms.PictureBox ajax;
		private Label labelControl1;
		private Label labelControl2;
		private Label labelControl3;
		private Label labelControl4;
		private RadioButton radioButton1;
		private RadioButton radioButton2;

It will not run becouse of

this.ajax.Image = ((System.Drawing.Image)(resources.GetObject(“ajax.Image”)));

the last thing you need to do is -go to and download any ajax lice icon you whant, and put it into the image box
Use it 🙂

June 10, 2009

Windows Service Restarting Itself

Filed under: Uncategorized — er2v @ 3:14 pm

Yes, it’s not possible for the service to be restarted for itself. Actualy this could be very handy. I have two servers, with Sql Server on one of them an service, that connects to this sql server on the start. Sometimes electricity shuts down, so both servers goes down, but when they rises up, server with Sql server do it slower then server with services, so servise can’t be started sucessfull. It never starts, nothing ever works. Huge problem. So in my case I needed something that will be starting my service untill connection returns. In my case the problem was, that OnStart event have had initialisation part that had sql connection, and it was realy not so easy to remove this initialisation from OnStart. Actualy I didn’t whant to do this, becouse it’s logicall to do initialisation on start. Why am I tolking about this? Becouse there is an easy way to solve the problem.

Easy Way

Windows Services have a wonderfull tab. Windows Service Recovery Tab.

All you need is

  catch(SomeException exc)
     ExitCode = -1;

But, stupid me, I didn’t new about this solution and I did it my way.

Service that starts another service

I desided to write service, that will check every n minutes is desired services started and start them if they not. The code of such a service is very simple.

using System;
using System.ServiceProcess;
using System.Timers;
using System.Configuration;

namespace Asc.ServiceStarter
    public partial class ServiceStarterService : ServiceBase
        Timer timer = new Timer();
        public ServiceStarterService()

        protected override void OnStart(string[] args)
            timer.Elapsed += timer_Elapsed;
            timer.Interval = double.Parse(ConfigurationManager.AppSettings["IntervalInMilliseconds"]);
            timer.Enabled = true;

        void timer_Elapsed(object sender, ElapsedEventArgs e)
            timer.Interval = double.Parse(ConfigurationManager.AppSettings["IntervalInMilliseconds"]);
            string[] Services = ConfigurationManager.AppSettings["CommaDelimitedOrderedServicesNames"].Split(new char[] { ',' });
            for (int i = 0; i < Services.Length; i++)
                    string CurrentService = Services[i].Trim();
                    using (ServiceController serviceController = new ServiceController(CurrentService))
                        if (serviceController.Status == ServiceControllerStatus.Stopped)
                    //Yes, it's never stops



        protected override void OnStop()
            timer.Enabled = false;

App.config file should be as follows

<?xml version="1.0" encoding="utf-8"?>
<add key="IntervalInMilliseconds" value="1000" />
<add key="CommaDelimitedOrderedServicesNames" value="CoolingService, Metal Quality" />

<?xml version="1.0" encoding="utf-8"?>



<add key="IntervalInMilliseconds" value="1000" />

<add key="CommaDelimitedOrderedServicesNames" value="CoolingService, Metal Quality" />



Security Issues

Service that that starts another service and this service should be run under the same username. Otherwise Service would not be able to run it.

Hope, someone will use it.

May 26, 2009

32bit ODBC driver on 64bit Vista surprises

Filed under: Uncategorized — er2v @ 2:36 pm

Once upon a time I’ve decided to install old 32bit ODBC driver on my 64bit Vista and write and run .Net project, that use it. There were not 64bit driver available so I had no choice. 

After passing thru installation of driver without any problems surprises have begun. First big surprise was when I had tried to open Data Sources(ODBC) and to create System DSN.  There were not such a driver. I tried a lot of things, even writing directly to registry – no result. Finaly I’ve descovered that there is a folder C:\Windows\SysWOW64 and there is a file odbcad32.exe that is for 32 bit. When you open Administration->Data Sources(ODBC) it’s opensC:\Windows\System32\odbcad32.exe  wich works only with 64 bit drivers. So first problem was solved. I was able to create datasource with C:\Windows\SysWOW64\odbcad32.exe.

Second surprise was that Visual Studio project was not able to acees this data source. The problem was in build configuration. After changing active solution platform in Build->Configuration manager from Any CPU to x86 everething started working just fine. 

Hope it helpfull for someone.

April 15, 2009

Install Trac on 64 bit Windows and run it under IIS7 fast cgi.

Filed under: Uncategorized — Tags: — er2v @ 10:02 pm

As a windows user, I realy like to download latest versions of sofware, because they have bugfixes ( and brand new bugs 🙂 I also love everething that is 64bit, and as an ASP.NET developer I love IIS7. So when I decided to install trac to organise our team’s development process, I’ve opened and started from the begin. This article is some kind of the step by step tutorial of how to make it 64 bit IIS7 fast cgi.

Simple things

If you are looking for trac, that means that you are already know what svn is. You’ll need subversion client, such as I’m pretty shure you already have it. Second thing you need is Visual Studio VC++ to cmpile sources. If you don’t have it – you can do the following:

1. Download and install trial professional edition – I hope 90 days will be enough to install trac 🙂

2. Donload free express version and do the magic guided by

The last thing create folder C:\src4trac\ – for sources. There will by lot of them 🙂  Shourely you can create any folder you like.

Install Python

First, that I’ve read was that I need Python. I was surprised that trac is written on Python. I’ve never used python before, but alway’s whanted to try. So without bothering myself with reading of what I need I went  to and downloaded 64 bit 2.6.2 python installer. I have not noticed

Notes regarding 64 bit Python:

  • SetupTools does not yet provide an install that works with 64-bit Python, it’s nevertheless possible to use the (see
  • The Subversion project does not provide amd64 or ia64 setup executables, so if you want to use Subversion integration, you’ll need to either compile the bindings yourself, or use the x86 version of Python.
  • It’s generally hard to find pre-compiled extensions, so you most often have to compile them yourself (e.g. for Genshi, Mercurial, the bindings for the DB backends) 

But I realy heapy about not noticed that. I’ve had very intersting week 🙂

So, go ahead, install 64 bit Python 2.6.2 or later.

Install easy_install

The second thing we’ll not be able to enjoy trac without is easy_install. Easy install is cool thing, it’s helps install different python programs easily. So you can type in command line

easy_install trac

and it will download and install trac and everething trac needs. You can learn more about this tool here Pretty cool, but it’s not so easy to install easy_install on 64bits :). See So let’s do the folowing.

  1. Create C:\src4trac\SetupTools folder and checkout with tortoisesvn from
  2. Download 64bitlauncher.patch to C:\src4trac\SetupTools folder and apply it (context menu -> tortisesvn->apply patch)

Now you have cli-64.exe and gui-64.exe files in C:\src4trac\SetupTools\setuptools directory. Open command line (press winkey-r and type cmd) and type

cd C:\src4trac\SetupTools\setuptools
rename cli.exe cli-old.exe
rename cli-64.exe cli.exe
rename gui.exe gui-old.exe
rename gui-64.exe gui.exe

go to C:\src4trac\SetupTools\ typing

cd ..

and now we can finaly type

python install


easy_install --help

and if you get error add C:\Python26\Scripts to the PATH environment variable and reload command line.

Congratulations we’ve overjumped first problem. It was not so hard, and now we can install trac itself 🙂

Install Trac and Genshi

If you have internet connection without proxy server – then simply type

easy_install trac

It will do all the job.

If you have proxy on computer you install trac or if you don’t have internet connection on this computer at all then download from other computer from zip or tar of laterst trac(not the installer) and put it’s unziped/untared content to C:\src4trac\Trac. After that download genshi tar or zip from and put  unziped/untared code to  C:\src4trac\Genshi. Now do the following

cd C:\src4trac\trac
easy_install .
cd C:\src4trac\Genshi
easy_install .

So that’s it! We have trac installed! But that’s only the beginning of the problems 🙂

But let’s forget about them for now and let’s do some checks,  if everething is alright.

Checking if everething is ok till now

Create folder C:\TracProjects. Type

trac-admin c:\ TracProjects\TestProj initenv

Ansver all questions. Actualy you can always press enter except in the path to the repository question where you should provide path to the subversion repository.

tracd --port 8000 c:\TracProjects\TestProj

Open http://localhost:8000/TestProj.
It’s alive!!! Alive!!!
If it’s not – then you have to reread all above very carefuly.

Running Trac under IIS 7, fast cgi

Standalone server is good, but hard to manage. So it’s much better to use some more powerful server such as IIS. We can run it trac as CGI but it’s not an option – too slow. The very reasonable way to make it run under IIS is it’s new FastCGI module. But here we can read

Note for Windows: Trac’s FCGI does not run under Windows, as Windows does not implement Socket.fromfd, which is used by If you want to connect to IIS, your choice may be AJP.

As for me AJP is realy strange thing and not an option – I want FastCGI.  So if trac’s fcgi does not support Windows, then we need to find other FCGI module for python. So let’s download and put code to C:\src4trac\PyFCGI folder. Do you think it’s all? No. The most interesting part starts right now.

Download The Development Kit from and put the code to the C:\src4trac\FastCgiKit Open C:\src4trac\FastCgiKit\Win32\FastCgi.dsw. If you get error

Connot load project due to a corrupt project file.

on opening projects – you should open dsp files in the text editor that supports conversion between Unix format and windows format. Notepad++ is the right thing. So after the conversion solution will open with all projects.

Visual studio will open.  Config_h project will be unavailable – it’s ok. Now you should open Main menu -> Build-> Configuration Manager

Set Active solution configuration: Release. Set Active Solution Platform x64. If there is only win32 option – click on <New> and in Type or select new platform: select x64, Copy settings from Win32.Leave checkbox about creation new platform checked. Cntrl-shift-B. Does not complile. Right.

open C:\src4trac\FastCgiKit\fcgi_config.h and comment following lines :

#define HAVE_NETDB_H 1
#define HAVE_SYS_PARAM_H 1
#define HAVE_SYS_TIME_H 1

Now you are finally able to  compile the code 🙂

Compiled? Good. So now you can fynaly install python-fastcgi. But first open C:\src4trac\PyFCGI\ in editor and replace

c_ext = Extension("fcgi", ["fastcgi/pyfcgi.c"], libraries=["fcgi"],


c_ext = Extension("fcgi", ["fastcgi/pyfcgi.c"], libraries=["libfcgi"],

Be carefull about indents on copy/paste.

Now you can

cd C:\src4trac\PyFCGI
easy_install .

Copy libfcgi.dll from C:\src4trac\FastCgiKit\libfcgi\Release to C:\Python26\Lib\site-packages\python_fastcgi-1.1-py2.6-win-amd64.egg\fastcgi

For testing if it’s all right run in command line

import fastcgi

If it’s not – reread and redo.

Changing code of trac 🙂

Create C:\Python26\Lib\site-packages\trac-0.11.4-py2.6.egg\trac\cgi-bin directory and a file trac.fcgi with the following content:

# -*- coding: utf-8 -*-
# Copyright (C) 2003-2009 Edgewall Software
# Copyright (C) 2003-2004 Jonas Borgström
# All rights reserved.
# This software is licensed as described in the file COPYING, which
# you should have received as part of this distribution. The terms
# are also available at
# This software consists of voluntary contributions made by many
# individuals. For the exact contribution history, see the revision
# history and logs, available at
# Author: Jonas Borgström 

import os

    os.environ['TRAC_ENV'] = "C:/TracProjects/TestProj"
    from trac.web import fcgi_frontend
except SystemExit:
except Exception, e:
    print 'Content-Type: text/plain\r\n\r\n',
    print 'Oops...'
    print 'Trac detected an internal error:'
    print e
    import traceback
    import StringIO
    tb = StringIO.StringIO()
    print tb.getvalue()

As you can remember C:/TracProjects/TestProj is the place where we’ve created test environment for trac. Pretty long way 🙂 I’m tired of typing alredy 🙂
There is not much left to do. Now open C:\tracbackup\trac-0.11.4-py2.6.egg\trac\web\ file and replace it’s code with following:

#!/usr/bin/env python
# -*- coding: utf-8 -*-
# Copyright (C)2005-2009 Edgewall Software
# Copyright (C) 2005 Matthew Good
# All rights reserved.
# This software is licensed as described in the file COPYING, which
# you should have received as part of this distribution. The terms
# are also available at
# This software consists of voluntary contributions made by many
# individuals. For the exact contribution history, see the revision
# history and logs, available at
# Author: Matthew Good

import pkg_resources

from trac import __version__ as VERSION
from trac.web.main import dispatch_request

import fastcgi

def run():
    s = fastcgi.ThreadedWSGIServer(dispatch_request, workers=1)

if __name__ == '__main__':
    pkg_resources.require('Trac==%s' % VERSION)

There is a time for looking if we are on the right way.
Run from command line

python C:\Python26\Lib\site-packages\trac-0.11.4-py2.6.egg\trac\cgi-bin\trac.fcgi

and you should get
unknown listenType (0)
If you do – then it’s greate! If you get indent errors -read 🙂 If some other error – reread and redo.

One more last thing you need to do. Open C:\tracbackup\trac-0.11.4-py2.6.egg\trac\web\ find

path_info = property(fget=lambda self: self.environ.get('PATH_INFO', '').decode('utf-8'),
                            doc='Path inside the application')

and replace it with

    path_info = property(fget=lambda self: self.environ.get('PATH_INFO','').decode('utf-8').replace(self.environ.get('SCRIPT_NAME', ''), ''),
                     doc='Path inside the application')

Configure IIS7

Create application pull, named trac and without managed code. Create appliction named trac in the default web site called trac aimed on C:\Python26\Lib\site-packages\trac-0.11.4-py2.6.egg\trac\htdocs in trac application pool.
Create virtual directory in your trac appliction called cgi-bin pointed on C:\Python26\Lib\site-packages\trac-0.11.4-py2.6.egg\trac\cgi-bin.

In trac application open Handler Mappings, click Add module mapping…  and  fullfill form with the following values:

Request Path: *trac.fcgi

Module: FastCgiModule

Executable(optional):  c:\Python26\python.exe|C:\Python26\Lib\site-packages\trac-0.11.4-py2.6.egg\trac\cgi-bin\trac.fcgi

Yes it’s right. With | symbol. Last field is name – feel free in naming it as you want 🙂

Open your browser. Deep breath.


If it works – you are lucky. If not – set rights on folder c:\Python26 for


There is one more posible bug. Open C:\Python26\Lib\site-packages. There is folders wich ends on .egg. If there is files wich ends with .egg – it’s zip archive. Unzip it to the folder with exactly same name wich have file in the same folder. For example if you have

C:\Python26\Lib\site-packages\genshi-0.5.1-py2.6-win-amd64.egg file – you should inzip it’c content to the C:\Python26\Lib\site-packages\genshi-0.5.1-py2.6-win-amd64.egg folder. This bug is about PYTHON_EGG_CACHE environment variable. Google it if you want:)

So now – it should work. Trac on IIS 7 on fast cgi! Wow! We are greate. Is it the end of our journey? No.


To be completely heappy – we need to be able to login. First of all turn on Basic Authentification for trac application in Autherization in IIS management console.
After that open C:\Python26\Lib\site-packages\trac-0.11.4-py2.6.egg\trac\htdocs\web.config file and add

<location path=”cgi-bin/trac.fcgi/login”>
<add accessType=”Deny” users=”?” />

as a first level child of <configuration> tag. Actualy you can configure security in any way you like, per user or per role.

Trac and Subversion

Trac and subversion are made for each other 🙂  You can read about it. This article is for unix. As a Windows user we will do everething in our way :).
Actualy when you need to connect to the subversion repository from trac – you need python bindings of subversion’s dll’s so Trac could do all subversion can. Happyly subversion project include everething you need for such bindings.

Note. When you compile subversion python bindings – you will get subversion + subversion python bindings. Someone can deside to use this compiled subversion binaries not onle for bindings, but for the subversion itself too. I recomend not to do so and do the following – compile subversion bindings for python and use them for trac. But for the subversion functionality itself get subversion binaries from and instal subversion, create repository and checkin something there and live heapyly. Why? Becouse if you compile them for truck only – you don’t need ssl libraries, berkley db libraries and so on, becouse truck will not use them anyway. You can use minimal number of subversion satellite projects – so the less code you’ll need to compile – the less problems you’ll get 🙂

If you already have subversion 1.x.y. installed then you need to create bindings of 1.x.y. We will make 64bit bindings. Don’t worry – it does not matters how many bits have your installed subversion. If you don’t have subversion yet – download the version you like and install it. Create repository. If you don’t cnow how – read (till the end;))

I have had subversion version 1.5.2 so I had to make my bindings for this version. So let’s do so. First create folder C:\src4trac\svnTheGreate – to show our respect for subversion :). Checkout Planty of files.
So while you are reading C:\src4trac\svnTheGreate\subversion\bindings\swig\INSTALL – I’ll go get some cofee. It will take you some time 🙂
So welcome back. As you’ve read, you need Download for example and unzip it to C:\src4trac\swig folder. After that download APR from and unzip it to the C:\src4trac\svnTheGreate\apr folder. Download latest APR -util and put it to the C:\src4trac\svnTheGreate\apr-util folder. So let’s compile them. In 64 bit. Let-s start from apr.
It’s simple. Release. x64. Build.
Now open C:\src4trac\svnTheGreate\apr-util\aprutil.dsw. There will be 4 projects that contains iconv in name. They will be unawalable. Never mind. Open C:\src4trac\svnTheGreate\apr-util\include\apu.hw file and set #define APU_HAVE_APR_ICONV 0 instead of 1.
So Release, x64. Build.
Dont worry about _bdb_ projects – you just don’t need them. 6 project’s will fail. Not more.
Now you should do the folowing.

Copy folders Release and LibR from C:\src4trac\svnTheGreate\apr-util\x64 to C:\src4trac\svnTheGreate\apr-util\
Copy folders Release and LibR from C:\src4trac\svnTheGreate\apr-util\x64 to C:\src4trac\svnTheGreate\apr-util\
Copy folder LibR from C:\src4trac\svnTheGreate\apr-util\xml\expat\lib\x64 to C:\src4trac\svnTheGreate\apr-util\xml\expat\lib\

Download Zlib. – and unzip it to the C:\src4trac\svnTheGreate\zlib folder. We do not need to compile it. It will be compiled later with bindings.
Download Neon and unzip it to C:\src4trac\svnTheGreate\Neon

Open comand line type

cd C:\src4trac\svnTheGreate -t vcproj --with-swig="C:\src4trac\swig" --vsnet-version=2008

and look how does magic happens.

Open C:\src4trac\svnTheGreate\subversion_vcnet.sln and compile it. Release! 64bit!

All java perl and ruby projects will fail – do not worry, we don’t need them. But if libsvn_fs fails – this is fatal.
If it’s not compile – reread. You must be mised something. Is apr and apr-util compiled in 64 bits? Have you moved folders from x64 and so on.

Now create c:\src4trac\BindingsInstaller.bat

@echo off
::Standard commission
SET _svn=C:\src4trac\svnTheGreate\
SET _psb=C:\Python26\Lib\site-packages\

rmdir /q %_psb%svn
rmdir /q %_psb%libsvn

md %_psb%svn
md %_psb%libsvn

xcopy %_svn%subversion\bindings\swig\python\svn\*.py %_psb%svn
xcopy %_svn%subversion\bindings\swig\python\*.py %_psb%libsvn
xcopy %_svn%Release\subversion\bindings\swig\python\*.dll %_psb%libsvn

cd %_psb%libsvn

ren _client.dll _client.pyd
ren _core.dll _core.pyd
ren _delta.dll _delta.pyd
ren _diff.dll _diff.pyd
ren _fs.dll _fs.pyd
ren _ra.dll _ra.pyd
ren _repos.dll _repos.pyd
ren _wc.dll _wc.pyd

xcopy %_svn%Release\subversion\libsvn_client\*.dll %_psb%libsvn
xcopy %_svn%Release\subversion\libsvn_delta\*.dll %_psb%libsvn
xcopy %_svn%Release\subversion\libsvn_diff\*.dll %_psb%libsvn
xcopy %_svn%Release\subversion\libsvn_fs\*.dll %_psb%libsvn
xcopy %_svn%Release\subversion\libsvn_fs_fs\*.dll %_psb%libsvn
xcopy %_svn%Release\subversion\libsvn_fs_util\*.dll %_psb%libsvn
xcopy %_svn%Release\subversion\libsvn_ra\*.dll %_psb%libsvn
xcopy %_svn%Release\subversion\libsvn_ra_local\*.dll %_psb%libsvn
xcopy %_svn%Release\subversion\libsvn_ra_neon\*.dll %_psb%libsvn
xcopy %_svn%Release\subversion\libsvn_ra_svn\*.dll %_psb%libsvn
xcopy %_svn%Release\subversion\libsvn_repos\*.dll %_psb%libsvn
xcopy %_svn%Release\subversion\libsvn_subr\*.dll %_psb%libsvn
xcopy %_svn%Release\subversion\libsvn_wc\*.dll %_psb%libsvn
xcopy %_svn%\Release\subversion\bindings\swig\python\libsvn_swig_py\*dll %_psb%libsvn
xcopy %_svn%apr\Release\*.dll %_psb%libsvn
xcopy %_svn%apr-util\Release\*.dll %_psb%libsvn

Run it. Two folders should appear in C:\Python26\Lib\site-packages. They are svn and libsvn with following content



svn should start working now

The End

I’ve spent 2 weeks to find the ways. Nothing worked from the first time, and there were no any infomation via google. So I’ve decided to write my experience down in a very detailed way. I know, that it just can’t be too detailed. This article is valuable for the following reasons: Trac on IIS 7 fast cgi – no information in internet at all. Second reason is detailed instructions on subversion python bindings 64 bits. It has it’s tricks like x64 directories. Thank you for spending your time on reading this tutorial. Hope it was usefull. Comment please 🙂

Create a free website or blog at