Remote connect to SQL Server 2005 Express or SQL Server 2005

Microsoft SQL Server 2005 or Microsoft SQL Server 2005 Express do not allow remote access by default. If you want to remote connect or use another computer in your LAN, you have to configure on your SQL Server 2005 or SQL Server 2005 Express.

In this article, we will use SQL Server 2005 Express as the sample database.

If you don’t set something for remote connection, you may receive an error message. The following error message is a sampe:

Sqlcmd: Error: Microsoft SQL Native Client: An error has occurred while establishing a connection to the server. When connecting to SQL Server 2005, this failure may be caused by the fact that under the default settings SQL Server does not allow remote connections.

Enable remote connections for SQL Server 2005 Express or SQL Server 2005 Developer Edition

First, I suggest that you use SQL SQL Server Authentication connection but not Windows Authentication connection (you still can) for your SQL Server Database connection. If you use Windows authentication, you should have identical accounts on both server PC and remote PC (username and password are the same), This is not good for remote database connection. Don’t you think so ?

To enable remote connections on the instance of SQL Server 2005 Express, please read the following steps:

   1. Find your Microsoft SQL Server 2005 program on the Start menu in your Windows XP or related OS, point to Configuration Tools, and then you will see the menu item SQL Server Surface Area Configuration (please see below):

   2. Click SQL Server Surface Area Configuration, then click Surface Area Configuration for Services and Connections.

   3. On the new page: Surface Area Configuration for Services and Connections page,select the database which you want to set for remote connection, in our case, we have installed 2 SQL Server Express databases, we select SQLEXPRESS2005 database, then expand Database Engine, click Remote Connections, check on the Local and remote connections radio button, then select the appropriate protocol to enable for your environment, and then click Apply.

   4. Please Click OK if you receive the following message:

   5. Return to the Surface Area Configuration for Services and Connections page, expand Database Engine, select Service, On the right side, click Stop button, then wait until the MSSQLSERVER (MSSQL$SQLEXPRESS2005) service stops, and then click Start button to restart the MSSQLSERVER (MSSQL$SQLEXPRESS2005) service.

(part of above text were from Microsoft website)

Other instruction info:


The first thing that can block a connection to SQL Server is a firewall. If you have any firewalls, make sure they are configured to allow connections to SQL Server. The default TCP port that SQL Server uses is 1433. Firewalls include McAfee, Norton, Windows Firewall which ships with Windows XP SP2, and Internet Connection Firewall (ICF) which ships with Windows 2000.

(Above text copied from here Teratrax site, more info please click to visit )

Intel Dual Core vs Intel Core 2 Duo

When you buy a computer with the label “Intel Inside” which means the computer’s CPU is Intel CPU, Then maybe you were confused by “Pentium Dual Core” and “Core 2 Duo” .

Actually, when we say “Dual Core”, it should cover all processors that has 2 cores. That means: Pentium Dual Core is a Dual Core CPU, and also Core 2 Duo is a Dual Core CPU. Pentium Dual Core and Core 2 Duo are two types of Dual Core CPU.

People always simply ask Which one is better between Pentium Dual Core and Core 2 Duo ?  If you can get correct answer you should give these two CPU’s feature and data, for example, we might have to say Pentium Dual Core 935 at 3.4Ghz and the Core 2 Duo at 1.86Ghz, Then the answer should be clear is that Core 2 Duo is better.

Why lower frequency Core 2 Duo 1.8Ghz is better than Pentium Dual Core 3.4Ghz ? because the former is faster.

Frequency is not the only one factor which effect the CPU speed, The main factor might should be IPC (instruction per clock cycle), Core 2 Duo has much higher IPC which means it can process much more data each clock cycle. Just like there are two persons move stones, Both of them have 1 hour limited, person A might move slower (lower frequency) than person B (faster frequency), but each time Person A can move 10 stones while person B only move 5 stones,   So finally after 1 hour, Person A will move higher amount of stones, which means in the computer field, person A can handle more data, so person A (Core 2 Duo) is faster.

So we can not simply say Core 2 Duo is better or Pentium Dual Core is better, but normally, most of computer which you see in comupter store with Core 2 Duo is more expensive than computer with Pentium Dual Core, The first reason is that people always think Core 2 Duo is newer or better than Pentium Dual Core, the second reason is that the CPUs in those computer should be really different. The more expensive computers really has faster and better CPU such as Core 2 Duo, as long as the computer store is not a cheating store.

Actually, I wanted to write this article 2 years ago, but I done it until today. When I wrote this, the CPU technology and market has changed very much, there are more new generation CPU has been in market, such as Intel i3, i5, i7..etc. I will write another short article for them some day later.

How to change all tab pages’s title for a TabControl using C# ?

In some cases such as Multiple languages dynamically switching and if you have a main TabControl with some sub tab pages will be dynamically added into it, you might find it is not easy if you want to change all these dynamic tab pages.

Actually, if you have done Multiple languages dynamically switching mechanism in your code, for these dynamic tab pages, you can use the following code to “re-write” their title so that this title can get a chance to retrieve resource file and get text due to current cultural setting:

                for (int i = 0; i < tabControl.TabPages.Count; i++)
                    TabPage page = tabControl.TabPages[i];
                    string pTitle = "";
                    foreach (Control ctl in page.Controls)
                        if (ctl is Form)  //Asume tab page include the sub control which is Form
                            pTitle = ((Form)ctl).Text;  //The Text has already been set by cultural resource somewhere (before this block of code)
                    page.Title = pTitle;

Open Visual Studio 2008 project file in Visual Studio 2005 ?

We know the Microsoft Visual Studio IDE Higher version can open the project which created in lower version by convert wizard steps. For example, whey you try to open a VS 2005 project in VS 2008, you will see a convert wizard windows firstly, it helps you convert old project to new project which can be opened in VS 2008.

But, Is it possible to open a Visual Studio 2008 project in Visual Studio 2005 ?

The answer is : Yes.

Of course we can not do it in the Visual Studio IDE directly. We need to do some works by manual.

Firstly, we need to know the higher version project doesn’t use higher version of VS studio’s features. Then it is possible to open the higher version of project in lower version of VS studio.

The solution is that we just need to change some information related Visual Studio Version such as version number.

For example:

1: .sln

    Microsoft Visual Studio Solution File, Format Version 10.00
    # Visual Studio 2008
    Project(”{F184B08F-C81C-45F6-A57F-5ABD9991F28F}”) = “ProjectConverter”,
    “ProjectConverter.vbproj”, “{B637ACFD-0AFC-4FBB-A8C0-602B5ABA62F0}”
    Project(”{54435603-DBB4-11D2-8724-00A0C9A8B90C}”) = “Setup”, “Setup\Setup.vdproj”,



2: .vbproj, .csproj, .vcproj

ToolsVersion="3.5" DefaultTargets="Build" xmlns="">
9.0.21022    2.0
{B637ACFD-0AFC-4FBB-A8C0-602B5ABA62F0}    WinExe

    ProjectConverter.My.MyApplication    ProjectConverter    ProjectConverter    512

    WindowsForms    v2.0    On    Binary


The above examples copied from This Article in Chinese.

Also, there is another More Professional Article and there are much more detail information (Visual Studio 2005/2008 Interoperability).

How to add a Uninstall option in Visual Studio Setup project without writing code

Using Visual Studio 2005/2008, you don’t need to write any code to add a uninstall option for a Setup project (Yes I know some people can write code to do it)

1) In the Setup Project –> File System windows –> Right Click “File System on Target machine” –> add a Special Folder, select System Folder;

2) Into this system folder Add a file. Browse for msiexec.exe from local System32 folder and add it. Override default properties of this file as follows:

Condition:=Not Installed (make sure you put ‘Not Installed’ exactly like that, same case and everything),

3) Create a new shortcut under the ‘Users Program Menu’, Set Target to the System Folder which you created in the step 1. and point it’s at the msiexec.exe. Rename the shortcut to ‘Uninstall Your Application’. Set the Arguments property to /x{space}[ProductCode].

5) Build the project, ignore warning about the fact that msiexec should be excluded, DONT exclude it or the setup project wont build.

The ‘Not Installed’ condition and Permananet:=True ensure that the msiexec.exe is only placed into the system folder as part of the install IF it doesn’t aready exist, and it is not removed on an uninstall – therefore it;s pretty safe to ignore that warning and just go for it.

(Based on the description from SlapHead)

Create SQL Server Database using C#

Here is a sample from codeproject :

private void CreateDatabase(DatabaseParam DBParam)
    System.Data.SqlClient.SqlConnection tmpConn;
    string sqlCreateDBQuery;
    tmpConn = new SqlConnection();
    tmpConn.ConnectionString = "SERVER = " + DBParam.ServerName +
                         "; DATABASE = master; User ID = sa; Pwd = sa";
    sqlCreateDBQuery = " CREATE DATABASE "
                       + DBParam.DatabaseName
                       + " ON PRIMARY "
                       + " (NAME = " + DBParam.DataFileName +", "
                       + " FILENAME = '" + DBParam.DataPathName +"', "
                       + " SIZE = 2MB,"
                       + " FILEGROWTH =" + DBParam.DataFileGrowth +") "
                       + " LOG ON (NAME =" + DBParam.LogFileName +", "
                       + " FILENAME = '" + DBParam.LogPathName + "', "
                       + " SIZE = 1MB, "
                       + " FILEGROWTH =" + DBParam.LogFileGrowth +") ";
     SqlCommand myCommand = new SqlCommand(sqlCreateDBQuery, tmpConn);
         MessageBox.Show("Database has been created successfully!",
                           "Create Database", MessageBoxButtons.OK,
     catch (System.Exception ex)
         MessageBox.Show(ex.ToString(), "Create Database",

There are many others. Another sample from Microsoft :

using System;
using System.Data.SqlClient;

String str;
    SqlConnection myConn = new SqlConnection ("Server=localhost;Integrated security=SSPI;database=master");

    str = "CREATE DATABASE MyDatabase ON PRIMARY " +
        "(NAME = MyDatabase_Data, " +
        "FILENAME = 'C:\\MyDatabaseData.mdf', " +
        "SIZE = 2MB, MAXSIZE = 10MB, FILEGROWTH = 10%) " +
        "LOG ON (NAME = MyDatabase_Log, " +
        "FILENAME = 'C:\\MyDatabaseLog.ldf', " +
        "SIZE = 1MB, " +
        "MAXSIZE = 5MB, " +
        "FILEGROWTH = 10%)";

    SqlCommand myCommand = new SqlCommand(str, myConn);
    MessageBox.Show("DataBase is Created Successfully", "MyProgram", MessageBoxButtons.OK, MessageBoxIcon.Information);
    catch (System.Exception ex)
    MessageBox.Show(ex.ToString(), "MyProgram", MessageBoxButtons.OK, MessageBoxIcon.Information);
    if (myConn.State == ConnectionState.Open)

If you want to create a database that is similar to the SQL Server Model database, and you want the database in the default location, then change the str variable in the code, as in the following sample code:

str = "CREATE DATABASE MyDatabase"

Also, the 3rd sample is using Microsoft “SQLDMO.dll”:

(you can find the SQLDMO.dll in C:\Program Files\Microsoft SQL Server\80\Tools\Binn or download it from
to add refference to a project , From project menu select “add refference” -> select the browse tab and select the dll file from the location and add to the project

public bool CreateDb(string serverName, string Uid, string Pwd, string dbName)
            bool result = true;
            SQLDMO.SQLServer gSQLServerDMO = new SQLDMO.SQLServer();
            SQLDMO.Database nDatabase = new SQLDMO.Database();
            SQLDMO.DBFile nDBFileData = new SQLDMO.DBFile();
            SQLDMO.LogFile nLogFile = new SQLDMO.LogFile();

                gSQLServerDMO.LoginSecure = true;
                gSQLServerDMO.Connect(serverName, Uid, Pwd);

                nDatabase.Name = dbName;

                nDBFileData.Name = dbName;

                nDBFileData.PhysicalName = gSQLServerDMO.Registry.SQLDataRoot + "\\DATA\\" + dbName + "_Data.mdf";
                nDBFileData.PrimaryFile = true;

                nDBFileData.Size = 2;

                nDBFileData.FileGrowthType = SQLDMO.SQLDMO_GROWTH_TYPE.SQLDMOGrowth_MB;

                nDBFileData.FileGrowth = 1;

                //Add the DBFile object


                nLogFile.Name = dbName + "Log";

                nLogFile.PhysicalName = gSQLServerDMO.Registry.SQLDataRoot + "\\DATA\\" + dbName + "_Log.ldf";
                nLogFile.Size = 2;



                MessageBox.Show("Database Created Sucessfully);



            catch (Exception SQLDBException)


                result = false;



            return (result);

Above 3rd sample from here

List enum item names using C#

Assume you have define an enum like :

public enum LanguageCollection : int
    English = 0,

Is it possible to populate all enum item to a dropdownlist control without hard code each enum name ? The answer is Yes.

Here is sample code :

for (int i = 0; i &lt; Enum.GetNames(typeof(LanguageCollection)).Length; i++)
     this.menuCBLanguage.Items.Add(Enum.GetName(typeof(LanguageCollection), i));

Remove subversion (SVN) source control from a project

How to remove subversion (SVN) source control from a project ?

Too easy ways:

Way 1: Just simply delete all .svn folders under your project folder and all sub folders in Windows Explorer;

Way 2: Create a new folder  which you can get a Non-SVN control project code later, go to your SVN controled project, right click on root folder, TortoiseSVN -> Export , then select the folder that you created just now, click OK, then you will get a clear project without SVN control;

Good luck !

Should I add the Visual Studio .suo and .user files to source control ?

.suo and .user file are two types of hidden user files in Visual Studio project.

.suo file which is a binary file. .user file is the project user file which is a text file.

You don’t need to add these 2 files to your source control (SCM) since they contain per-user settings and SUO (Solution User Options) records all of the options that you might associate with your solution so that each time you open it, it includes customizations that you have made.

What is .suo file in Visual Studio project ?

Copied explanation from Microsoft official site:

Solution Files (.sln and .suo)

Visual Studio uses two file types (.sln and .suo) to store settings specific to solutions. These files, known collectively as solution files, provide Solution Explorer with the information it needs to display a graphical interface for managing your files. They allow you to concentrate on your projects and final goals rather than on the environment itself each time you return to your development tasks.

.sln:   Visual Studio Solution

Organizes projects, project items and solution items into the solution by providing the environment with references to their locations on disk.

.suo  Solution User Options

Records all of the options that you might associate with your solution so that each time you open it, it includes customizations that you have made.

Content from here