Yahoo Search

Search the web Search this site

Live Search

Google Search

Custom Search

Translate this Web Site to

Monday, May 31, 2010

Changing the Shared Feature Directory in SQL Server Setup

Today when I tried to install SQL Server 2008 R2 I couldn’t change the shared feature installation directory in the setup. Both the textbox and browse button were disabled restricting me to select the desired path.

After sometime I found the cause for this. It is because there were some SQL related programs already installed in my computer, because they are there the SQL setup uses the same directory to setup the rest of the programs.

If you need to relocate the install directory then simply you need to uninstall all the SQL related programs using Programs and Features and re-run the SQL Server setup. Then the browse buttons will be active enabling you to select an alternate location.

Saturday, May 29, 2010

How to Make a Bootable Flash Drive

Recently I installed Windows using a flash (Pen/Thumb) drive, since I couldn’t get hold of a blank DVD to burn the ISO into.

It might be helpful to you as well. Because we don’t need to burn DVDs to install OSs that are coming as ISOs anymore.

Follow the steps below.

1. Find a good USB Flash drive with required space.

Make sure you have backed up all the required data in the flash drive because the flash drive will be formatted.

2. Get a command prompt by typing “cmd” in the run window.

3. Type “diskpart” and press enter.

This will open up a new window for DiskPart utility, you need to use the following commands within the diskpart utility to make the flash drive bootable.

4. In the diskpart utility select the flash drive by typing “select disk 2”.

Use extra caution when selecting the flash disk since if you select the wrong disk you will loose all data of that disk. You can use “list disk” command within the diskpart utility to list all the disks attached to your computer. Note the disk referred here is a physical disk attached to the computer not a partition.

5. Clean the disk by using the command “clean”.

6. Create a primary partition inside the flash drive by typing in “create partition primary”.

7. Select the newly created partition by using command "select partition 1”.

8. Make the selected partition active by typing in the command “active”.

9. Then you need to format the partition by using the command “format fs=fat32” inside the diskpart.

Note that we are formatting the disk using FAT32 file system.

10. Use the command “assign” to assign a drive letter for the newly formatted drive, since we are not giving a drive letter it will get the next available drive letter automatically. Then exit the diskpart utility by typing in “exit”.

11. Now we need to copy the setup files to the flash drive.

For this we can use the good old xcopy command as of below.

xcopy F:\*.* /s/e/f G:\

In the above command I am coping the contents of the drive F (which is a virtual drive created by Power ISO) to drive G which is the flash drive I created.

The meanings of the flags I used are as follows.

“xcopy F:\*.* /s/e/f G:\”

F:\ – Source Drive

*.* – All Contents

/s – Copies directories and sub directories which are not empty

/e – This will add the empty directories also so now all the directories and sub directories will be copied even though they are empty

/f  – Will show the source and destination file names while copying.

G:\ – Destination Drive

When xcopy completes you will have a flash drive which you can boot your computer, in my case I had a Windows 2008 R2 installer. You may even be able to copy the OS files to your flash drive and boot an OS with this method.

Then you may need to change your BIOS options and/or press function keys to let you boot from the flash drive.

Wednesday, May 19, 2010

Connecting to MySQL in Visual Studio 2010

If you need to access MySQL databases using Visual Studio you have to install MySQL connector into your machine.

Currently only mysql-connector-net-6.3.1 is supporting Visual Studio 2010 which is still an alpha product.

To download it, use this link and switch to Development Releases tab.

Saturday, May 15, 2010

Preserving State in ASP.Net

As you know a main challenge in web development is preserving the state of the application. We say web is stateless because web server treats each HTTP request for a page as an independent request. The server will not know any knowledge of variable values that were set/used during the previous requests. For example in Windows applications after we start the application if we set a variable to a certain value in a form it will be there until we close the form. But in web since the page is getting posted back the value will be normally lost.

To overcome this limitation in web ASP.Net provides two main methods and they are having different options under them.

  1. Client Side State Management
    1. View State
    2. Cookies
    3. Query String
  2. Server Side State Management
    1. Session State
    2. Application State
    3. Profile Properties

1.1- View State

Viewstate is a technique used in ASP.Net to preserve the state changes during the page postbacks. The viewstate data is always belong to the page, so this needs to be used when we want to store data at page level and retrieve them on the same page. Viewstate data will not be available from another page.

Viewstate uses a hidden form field named __VIEWSTATE as default to store the state information. When the “EnableViewstate” property of a control is set to true ASP.Net will start saving the control state in the viewstate. If we enable this property for many controls then soon the viewstate hidden variable will be large, and that may slow our application since this needs to be transferred at each postback. For example each time we submit a page the viewstate will go from our machine to server and from server to our machine. Due to this reason we should consider whether it is really required before enabling viewstate for a control. One advantage viewstate has is that it is not using server resources.

Apart from the viewstates of the controls in the form we can also add the values we need to preserve to the viewstate.

Adding a value -

  1. ViewState["Text"] = value;

  1. ViewState.Add("Text", value);

Retrieving a value -

  1. object o = ViewState["Text"];

  1. string str = (string) ViewState["Text"];


1.2- Cookies

We use cookies to store frequently changed small amount of data at client side. We can control the life span of a cookie. For example we can create a cookie which expires when the session is over or which exists indefinitely in the client machine.

Cookies are light weight since they are text based structures having key value pairs. They are not taking any server resources since they are at client, but this also adds a disadvantage on security because users/hackers can tamper them. To prevent this we can encrypt cookies but this will reduce application performance. There is also a limit to the amount of data which we can be stored in a cookie. Also if cookies are blocked in browser the application will fail.

Adding a value -

  1. Response.Cookies["userData"]["Name"] = "Arjuna";
  2. Response.Cookies["userData"]["lastVisit"] = DateTime.Now.ToString();
  3. Response.Cookies["userData"].Expires = DateTime.Now.AddDays(1);

  1. HttpCookie aCookie = new HttpCookie("userData");
  2. aCookie.Values["Name"] = "Arjuna";
  3. aCookie.Values["lastVisit"] = DateTime.Now.ToString();
  4. aCookie.Expires = DateTime.Now.AddDays(1);
  5. Response.Cookies.Add(aCookie);

Retrieving a value -

  1. HttpCookie cookie = Request.Cookies["userData"];
  2. if (cookie == null)
  3. {
  4.     lblCookieText.Text = "Cookie not found.";
  5. }
  6. else
  7. {
  8.     lblCookieText.Text = cookie.Values[0] + ", " + cookie.Values["lastVisit"];
  9. }


1.3- Query String

A query string is the information added at the end of the URL. This is supported by all the browsers and does not consume server resources. But this has limited capacity and security problems.

Adding a value -

  1. Response.Redirect("Webform2.aspx?Name=" +
  2. this.txtName.Text + "&LastName=" +
  3. this.txtLastName.Text);

Retrieving a value -

Using Webform2.

  1. this.TextBox1.Text = Request.QueryString[0];
  2. this.TextBox2.Text = Request.QueryString["LastName"];


2.1- Session State

Session state (variables) needs to be used to store session specific data. For example the logged in user information can be stored in session. Session variables are accessible by the entire set of pages in an application within the same session.

Session is created once a user visits a site and the session will end when the user leaves a site or when user becomes idle. Session variables are stored in a SessionStateItemCollection object that is exposed through the HttpContext.Session property. In an ASP.NET page, the current session variables are exposed through the Session property of the Page object. One disadvantage is that the session variables are taking server resources.

Adding a value -

  1. Session["Name"] = “My Name”;

Retrieving a value -

  1. string str = (string) Session["Name"];


2.2- Application State

Application state (variables) are used to store application specific data. Application state will be accessible to any users connected to the application. Normally global data which are infrequently changed, having no security concerns are stored in an application state.

The HttpApplicatioState instance is created at the first time a user accesses any URL resource in an application and the application state is lost when the application is ended. For example if the web server is restarted. If the value is required after application restart then before application end the required values needs to be transfered to a non volatile medium such as a database for later retrieval. The HttpApplicationState class is most often accessed through the Application property of the HttpContext class. When using the application state we need to remove any unnecessary items as soon as it is not required to maintain the site performance.

Adding a value -

When adding a value to an application variable it is always good to lock it before adding data since application state data can be accessed by multiple threads at the same time. Otherwise invalid data or erroneous data will appear. The loack needs to be removed after adding or changing the value to make the application state available for other threads.

  1. Application.Lock ();
  2. Application["NumberofViews"] = 1;
  3. Application.UnLock ();

Retrieving a value -

  1. string str = (string)Application["NumberofViews"];


2.3 Profile Properties

Profile properties uses an ASP.Net profile and is user specific. This is similar to session state except that the data stored in profile properties are not lost when session is ended.

We can store the profile data in a place that we like. If we are using SQL Server to store them then we can use SqlProfileProvider, if not we can write our own profile provider classes so the profile data will be stored in custom formats and in a custom storage mechanisms, such as an XML file, or even to a Web service. But performance will be less since the data is stored in a data store. Also to use it additional configurations and to keep it in a fully optimized level maintenance activities are required.

Adding a value -

First we need to add the required provider and the properties to the web.config file.

  1. <profile enabled="true">
  2.   <providers>
  3.     <clear/>
  4.     <add name="AspNetSqlProfileProvider" type="System.Web.Profile.SqlProfileProvider" connectionStringName="ApplicationServices" applicationName="/"/>
  5.   </providers>
  6.   <properties>
  7.     <add name="UserName" />
  8.   </properties>
  9. </profile>

Retrieving a value -

  1. TextBox1.Text = System.Web.Profile.DefaultProfile.Properties["UserName"].DefaultValue.ToString();


Read more on ASP.Net state managements at

Thursday, May 06, 2010

"Login failed. The login is from an untrusted domain and cannot be used with Windows authentication."

If you are getting the above error while trying to connect to a database, the reason is you are using Windows Authentication to login to the SQL Server while being in another untrusted domain.

For example if the SQL Server machine is a member of the CompanyDomain and if you are in MyDomain or if you are in a Workgroup the you will face the above issue while trying to connect to the SQL Server.

The connection string used in the web.config while the above error is generated is as follows.

  1. <connectionStrings>
  2.   <add name="cnnStr" connectionString="Data Source=BI-SVR;Initial Catalog=BBIDatabase;Integrated Security=True"/>
  3. </connectionStrings>


There are three ways to fix this problem.

1. Use the SQL Authentication to login to the SQL Server.

You can get this done by changing the connection string to use SQL authentication while connecting. But you need to know the credentials of an account which is having permissions to your required database or the System Administrator (SA) password. For simplicity I will use SA account details in the connection string.

  1. <connectionStrings>
  2.   <add name="cnnStr" providerName="System.Data.OleDb" connectionString="Data Source=BI-SVR;Persist Security Info=True;Password=YourPassword;User ID=sa;Initial Catalog=BBIDatabase"/>
  3. </connectionStrings>


2. Login to your machine using the same Domain.

If you login to your machine using a domain account which the SQL Server is added to, then this error will vanish. But for this you need to add your machine to the same domain which the SQL Server machine is added to (CompanyDomain) also to properly get authenticated the account used should have proper permissions set to access the database in the SQL Server.

3. Make the account trusted in SQL Server.

By making the account you use to login to your machine trusted account in SQL Server and giving it appropriate permissions to access databases will also permit you to fix this error.