Wednesday, October 22, 2008

Visual Studio 2005 Bootstrapper

  • Scenario

    Assuming that you are going to package an application developed by Visual Studio 2005 and assuming also that you did the job successfully - as you think – and that you take the package and to test it right –as you think too – you install it on another developer's PC and everything goes well ..

    What is the next step ?

    A user buy this application and the following scenario is expected to occur :

    The app won't run ;D or even installed , of course, unless the .NET Framework 2.0 is installed. Consider that you use a SQL Server 2005 Express Edition database. Hmmm Okay, you have to inform the user that these components should be installed on his/her machine.

    First, the user has to check whether each component is already installed on the machine. Then he/she must manually download and run the installers for each missing component, selecting the appropriate choices in the installation UI. If any reboots are required, he/she must restart the machine and resume from where they left off. If the components need to be installed in a particular order, there are additional opportunities for things to go wrong. This is a poor user experience, to say the least, and many users would give up.


     

    The Visual Studio® 2005 Bootstrapper solves this problem by allowing you to provide an easy, integrated way to install all of the different prerequisite pieces required by your application.


     

  • What is Visual Studio 2005 Bootstrapper ?

    The Visual Studio 2005 Bootstrapper lets you provide users with a simple, automated way to detect, download, and install an application and its prerequisites. It serves as a single installer that integrates the separate installers for all the components making up an application, and provides a wealth of features and services.


     

    The Bootstrapper is a small executable that weighs in at a mere 222 KB, and takes about one minute to download on a 28.8 Kbps modem. It therefore adds only a small amount of overhead to the installation process, which can save the user from having to download much larger redistributables if he does not need them. It doesn't install a component that will not run on the target machine, the bootstrapper notifies the user and ends the installation before installing the component. It provides a flexible options for detecting whether a component is already installed or not.

    Most components include an End-User License Agreement (EULA) that serves to protect the component vendors' intellectual property. The Bootstrapper can be configured to present license agreements for individual components. It can also present a single shared license agreement for multiple components in order to minimize the number of pop-ups the user has to click through.

    The Bootstrapper can install prerequisites form local drives, web and file shares. It can be configured to download prerequisites components from the same location as the app installer. It detects whether any of the prerequisites are already installed. If any of the prerequisites are missing, the Bootstrapper shows an install dialog box that lists those components and displays their license agreement. Otherwise, if all of the prerequisites are detected, the Bootstrapper simply launches the application installer.


     

  • Configuring the Bootstrapper

    The Bootstrapper offers a couple of options for where redistributable files can be located. By default, the Bootstrapper assumes that all files, including the redistributables, the Bootstrapper setup.exe itself, and the actual application files, are located together under the same folder. This is ideal for applications that will be installed from local disk (CD-ROM, USB device) or a network share. This option also supports the application publisher who wants to serve up everything from a single deployment server. Alternatively, if the publisher wants to balance the load across different servers, or maintain a central location for prerequisite components that can be shared by multiple applications, the Bootstrapper can be configured to download any prerequisite files from a separate location.


     

  • Custom Redistributables in Visual Studio

    Adding your own redistributables to Visual Studio requires that you author the product and package manifests, then copy these files along with your redistributable files into a special folder that Visual Studio has reserved for redistributables that plug into the Bootstrapper. This folder is installed by default like so:

    C:\Program Files\Microsoft Visual Studio 8\SDK\v2.0\Bootstrapper


     

The problem that you might face is that you need two xml files – two manifests – that is required for installing the redistributables which are product and package. I have noticed that product.xml should be in the same folder that has the redistributable file and the package.xml file has to be in a 'en' folder in the same location of the redistributable. If you have a license agreement text file put it beside package.xml file.

Manifest files has tags that are easy to be understood ,but It will require a good effort to insert it for your redistributables may try to use Bootstrapper Manifest Generator. You have to note that when you try to open the setup project you may encounter a warnings, but it will be went away when you fix the product and package manifests.


 

Wednesday, July 9, 2008

Mapped Network Drive Disconnection Problem

If you are using mapped network drives to share files across multiple computers across windows workgroup, you will suffer from mapped network drives random disconnection. We made a lot of testing regarding this issue and at last we found a solution that will keep mapped network drives connection.

The following is a description of issues you may face with mapped network drives and the solution for each issue.

Use IP Address Instead of Computer Name

In workgroup environment using computer name results in latency accessing shared resources. Since there is no Domain Name System Server (DNS) that resolves computer names to its corresponding IPs.

To achieve less latency between workgroup connected computers, use IP address instead of computer name to access remote computers without the need for DNS.

To use IP address in workgroup, configure each computer to have a static IP address instead of relying on DHCP. Ensure that all computers in the workgroup are using static IPs in the same range e.g. 192.168.10.1 to 192.168.10.255.

In case of existence of DHCP, ask you network administrator to reserve a set of IP addresses to use in the workgroup installation.

You can use the IP address of each PC to access it or configure windows hosts (this file can be found under C:\WINDOWS\system32\drivers\etc) file to assign each PC name to its static IP address.

Mapped Network Drive Connections

The mapped network drives configured on client PCs may suffer disconnection during windows startup or during the day. This occurs for two reasons:

  1. Computers running in Workgroup may fail to reestablish the Mapped Network Drive Connection during computer logon process.
  2. The Computer that hosts the shared folders will disconnect idle clients if no action occurred in the current session. This will result in disconnection of mapped network drives in client PCs

To resolve the above issues several actions should be taken

  1. Reconnect the network drives in workgroup PCs every time users logon to windows. This can be achieved automatically using windows script that runs during windows startup
  2. Configure the shared folder host computer to disable automatic session disconnect. This can be achieved automatically using windows script that runs during windows startup

The above actions can be performed using windows net command. To make life easier, a windows script can be used to call the required net commands. The following code snippet describes how such script can be done.

MappDrives.JS Code Snippet

This code need to run on each PC that needs to have mapped network drive. This can be done in the computer startup, as auto run entry in the host computer registry under HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\Run.

var shell = WScript.CreateObject("WScript.Shell");
var serverIP = "\\\\192.168.10.1";
var username = "";
var password = "";
var zDrive = serverIP+"\\Shared";
DisableAutoDisconnect();
MapDrive("Z:",zDrive);
function MapDrive(drive,share)
{
var netcmd = "net use " + drive + " " + share;
if(username != "")
{
netcmd = netcmd + " /USER:" + username + " " + password
}
netcmd = netcmd + " /P:YES";

RunCmd(netcmd);
}
function DisableAutoDisconnect()
{
var netcmd = "net config server /AUTODISCONNECT:-1";
RunCmd(netcmd);
}
function RunCmd(cmd)
{
shell.Run(cmd,0,false);
}

serverIP:
has the IP of the host PC with shared folder we want to map network drive from

username & password:
has the username and password required to access shared folders in the host PC

zDrive:
the target shared folder path [Computer Name]\\[Shared Folder Name]

MapDrive: construct the required net command to map the shared folder to Z drive.

DisableAutoDisconnect.JS Code Snippet

This script needs to run on the host PC. This can be done in the computer startup, as auto run entry in the host computer registry under HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\Run.

var shell = WScript.CreateObject("WScript.Shell");
DisableAutoDisconnect();
function DisableAutoDisconnect()
{
var netcmd = "net config server /AUTODISCONNECT:-1";
RunCmd(netcmd);
}
function RunCmd(cmd)
{
shell.Run(cmd,0,false);
}

DisableAutoDisconnect: disable the host PC automatic session disconnect by setting the timeout to -1

Avoid Disconnect During the Day

To ensure that there are no disconnect will occur, additional step can be done. Schedule a periodic task on windows to run the MapDrives.JS script. You can use windows tasks scheduler to do this or implement your own scheduler in your software application.

Wednesday, June 11, 2008

Get Database Tables Sizes

This script lists the database table's size. This script found under the following post:

http://forums.microsoft.com/MSDN/ShowPost.aspx?PostID=1784430&SiteID=1

I modified it to include the schema for table name to be useful with tables with non default schema.


DECLARE

@TotalRows int,

@Counter int,

@TableName varchar(50)


DECLARE @MyTables table


( RowID int
IDENTITY,

TableName varchar(50),


Rows
bigint,

Reserved varchar(12),

Data varchar(12),

IndexSize varchar(12),

Unused varchar(12)


)


INSERT
INTO @MyTables ( TableName )


SELECT TABLE_SCHEMA +
'.'
+ TABLE_NAME FROM
INFORMATION_SCHEMA.TABLES


SELECT @TotalRows =
@@ROWCOUNT, @Counter = 1


WHILE
( @Counter <= @TotalRows )


BEGIN


SELECT @TableName = TableName FROM @MyTables


WHERE RowID = @Counter


INSERT
INTO @MyTables EXECUTE
sp_spaceused @TableName


SET @Counter =
( @Counter + 1 )


END


DELETE
FROM @MyTables


WHERE RowID <= @TotalRows


SELECT TableName,
Rows, Reserved,Data, IndexSize, Unused FROM @MyTables


ORDER
BY Rows DESC

GO

Tuesday, May 20, 2008

SQL 2005 and SET OPTIONS Tip

In SQL 2005 if you have stored procedure or SQL statement that execute update operation on table with computed column that refer to function, or have update triggers, one of the following errors may occur:

  • Msg 8624, Level 16, State 1, Procedure Patient_Update, Line 96
    Internal Query Processor Error: The query processor could not produce a query plan. For more information, contact Customer Support Services.
  • UPDATE failed because the following SET options have incorrect settings: 'ANSI_NULLS'. Verify that SET options are correct for use with indexed views and/or indexes on computed columns and/or query notifications and/or xml data type methods.

The cause of this problem can be that the SET OPTIONS for stored procedure is different in the computed column function or update triggers.

For example, if computed column function has SET ANSI_NULLS ON and stored procedure has SET ANSI_NULLS OFF, one of the above errors may occur

To resolve this, ensure that you are using the same SET OPTION in the stored procedures, computed columns functions and update triggers.