Demolishing the house to change a window

22 08 2008

The Important of AJAX

To understand the benefits of AJAX, consider a
renovation scenario. You’ve decided you want
a stained glass window beside the front door.
The renovator removes the existing plain glass
and window frame, takes it to the shop for
replacement with the stained glass, and returns
to reinstall it. He obviously has no need to
touch the other windows or — to be completely
ridiculous — tear down the house and replace
everything in the process.

The same concept applies to a Web page. If you
just want to change the content in one area of the
page, you don’t need to wipe out the existing page
and ask the server to resend all the images and
HTML markup. AJAX works like the renovator,
doing just what’s required but not more.





Server Availability

11 08 2008

-:Introduction:-

Making generalized database server connection utility.

Steps:
1. Fetch the list of server instances available in LAN.
2. Give user functionality to select particular server instance name from the list of server instances.
3. Fetch the list of databases by connecting with the selected server instance.
4. Give user functionality to give user name and password if there is any to connect with database.
(it is needed only when user selected SQL Authentication mode)
4. Give user functionality to select particular database name from the list.
5. Connect with the database and give user confirmation that successfully connection established.

-:In Detail:-
There are mainly three methods to find the list of servers in local area network:
1. Using SQLDMO class
2. Using SQLSMO class
3. Using general .NET class

Each and every method have their own pros and cons

1. Using SQLDMO class

There are more cons than advantages of use of SQLDMO class
-> It only lists SQL Server 2000 server instances over the LAN.
-> It requires SQLDMO.DLL in specific path C:\Program Files\Microsoft SQL Server\80\Tools\Binn
-> It requires SQLDMO.DLL to be registered under windows server registry through
regsvr32 C:\Program Files\Microsoft SQL Server\80\Tools\Binn\SQLDMO.DLL
command

You cannot use SQLDMO class directly in your application. For using SQLDMO class there is
wrapper provided by microsoft is Interop.SQLDMO.DLL
The wrapper provides you sqldmo wrapper classes to use it inside your application.

You can fetch the list of server instance in LAN by using

Code:
/*
For getting list of server instances name.
*/
//Declaring new object of type SQLServer defined in Interop.SQLDMO.DLL
SQLDMO.SQLServer o_SqlServer;
//Instantiating object o_SqlServer
o_SqlServer = new SQLDMO.SQLServer();
//Declaring namelist object to store list of sql server instances
SQLDMO.NameList o_List;
//Fetching list of sql server instances over the LAN
o_List = o_SqlApplication.ListAvailableSQLServers();
//You can access particular server name by using integer index number.
o_List.Item(index);

/*
Fetch list of databases based on server instance name user have selected
*/
List<String> o_DBList = new List<string>();
o_SqlServer.LoginSecure = true;
if (userName == String.Empty)
{
o_SqlServer.Connect(serverName, null, null);
}
else
{
o_SqlServer.Connect(serverName, userName, password);
}
foreach (Database o_database in o_SqlServer.Databases)
{
o_DBList.Add(o_database.Name);
}

2. Using SQLSMO class

-> It will give you list of both SQL Server 2000 as well as SQL Server 2005

There are some pitfalls of using SQLSMO which prevents us to use this method.
-> It requires four dlls along with the solution or setup to carry, to use this method.
Microsoft.SqlServer.ConnectionInfo.dll
Microsoft.SqlServer.Smo.dll
Microsoft.SqlServer.SmoEnum.dll
Microsoft.SqlServer.SqlEnum.dll

Code:
/*
For getting list of server instances name.
*/
DataTable serverName;
// get all data sources available in network using SMO
serverName = SmoApplication.EnumAvailableSqlServers();
//To access server names
foreach (DataRow ds in serverName.Rows)
{
string ds_server_name;
ds_server_name = ds[“Name”].ToString();
}

/*
Fetch list of databases based on server instance name user have selected
*/
private Server server = new Server(“selected-server instance-name”);  // SMO server object
foreach (Microsoft.SqlServer.Management.Smo.Database db in selected_ds.Databases)
{
//To access database name
String db_name;
db_name = db.Name
}

3. Using general .NET classes

.NET provides some internal classes that comes along with .NET Framework which will give you the
list of server instances.
Once you got server there are some mechanism which you can use to connect with the server and
fetch the list of databases.
Once you got server instance name and database name, it is very easy to connect with that particular
selected database in the selected server instance name.

Code:
/*
For getting list of server instances name.
*/
System.Data.Sql.SqlDataSourceEnumerator servers = System.Data.Sql.SqlDataSourceEnumerator.Instance;
System.Data.DataTable serversTable = servers.GetDataSources();
foreach(DataRow row in serversTable.Rows)
{
//row[0]=networked computer name
//row[1]=database server instance name
//to get full name for connection use following method
string serverinsance_name;
serverinsance_name=row[0].ToString() + @”” + row[1].ToString()
}

/*
Fetch list of databases based on server instance name user have selected
*/
//In generalized method you need to make connection with the selected server instance name
//for fetching list of databases
String ml_conxString;
DataTable o_DatabaseList;
if(string.IsNullOrEmpty(UserName.Text))
{
ml_conxString = “Data Source=” + ServerName.Text.Trim() + “;Integrated Security=True”;
}
else
{
ml_conxString = “Data Source=” + ServerName.Text.Trim() + “;Initial Catalog=” + DataBaseName.Text.Trim() + “;User ID = ” + UserName.Text.Trim() + “;Pwd = ” + Password.Text;
}
using (SqlConnection sqlConx = new SqlConnection(ml_conxString))
{
sqlConx.Open();
o_DatabaseList = sqlConx.GetSchema(“Databases”);
sqlConx.Close();
}
//To access database name
foreach (DataRow row in o_DatabaseList.Rows)
{
string ml_databasename;
ml_databasename = row[“database_name”].ToString();
}

//Testing connection is same as we have fetched database list based on server instance name
String ml_conxString;
if(string.IsNullOrEmpty(UserName.Text))
{
ml_conxString = “Data Source=” + ServerName.Text.Trim() + “;Initial Catalog=” + DataBaseName.Text.Trim() + “;Integrated Security=True”;
}
else
{
ml_conxString = “Data Source=” + ServerName.Text.Trim() + “;Initial Catalog=” + DataBaseName.Text.Trim() + “;User ID = ” + UserName.Text.Trim() + “;Pwd = ” + Password.Text;
}
SqlConnection sqlConx = new SqlConnection(ml_conxString);
sqlConx.Open();
sqlConx.Close();

-:Demo Project (Using General .NET Classes):-

Download GetListOfServers.zip – 4.86 KB

-:Downloads:-

SQLDMO.DLL
Microsoft.SqlServer.ConnectionInfo.DLL
Microsoft.SqlServer.Smo.DLL
Microsoft.SqlServer.SmoEnum.DLL
Microsoft.SqlServer.SqlEnum.DLL





My Life in a Bush of Legacy Code – Michael Feathers

11 08 2008

I am attending this session from the godfather of legacy code. How could I pass it up?

Michael’s core assertion is that a code base reflects the business climate of the organization that created it.

Session Quotes

  • The result of my book has been the opportunity for me to see some of the worst code you can imagine.
  • Two things we deal with: Laziness and ignorance. Ignorance is forgivable and correctable.
  • Code is alive and it has its own defenses. A big one is the code’s complexity increases in order to keep you from messing with it. Like a garden getting out of control.
    • Personal Note: I like to think about this as “trending to entropy”. Organic systems (like a code base or a human) ill trend to entropy without constant attention to its health.
  • Organic systems go through periods of recession and recovery.
    • Like breaking down muscles to get stronger.
    • Like the U.S. economy today.
  • If an organization has no competition, code will atrophy
  • TCO of a code base increases due to complexity, not its size.
  • The way of the magpie is to chase shiny things. Magpie’s create sticky balls of mud. Don’t be a magpie.
  • Emergence works. Put a small group of people together and let them own a problem. They will almost always succeed.
  • Dunbar’s Number. Look it up, this is cool. Group sizes larger than this require restrictive rules, laws, and policies in order to maintain stability.

My question: “Do you have some prescriptive guidance for an individual team member who would like to evolve the the team and reclaim a code base that has trended toward entropy?”

  • Have someone on the team who can do green field TDD. Someone on the team needs to understand what to strive for.
  • Set standards for quality and team behavior and hold people accountable to those standards.
  • Find the area of code that everyone is scared of. Attack that one first. The team will feel better having relieved its pain and realized initial success.
    • Note: This one reminds me of Mary Poppendieck’s saying, “Find the thing that is hard to do, and do it more often.”







Follow

Get every new post delivered to your Inbox.