Ajax AutoCompleteExtender with MSSQL datasource

I’m building a form and wanted to use the autocompleteextender control of the Ajax Toolkit. Having limited skills with ASP.net and C#, I began by looking for examples online. However, nothing I found and tried seemed to be working. I finally found a simple example here that helped me get on my way.

I’ve reproduced my code below as a self-reference, and to hopefully help someone else avoid troubles with this control.

 

Default.aspx










TargetControlID – the ID of the textbox that we’ve chosen to use
ServiceMethod – name of the method as defined in your codebehind file

Default.aspx.cs (C#)

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;
using System.Data.SqlClient;
using System.Configuration;

namespace ITIventory
{
    public partial class _Default : System.Web.UI.Page
    {
            // AUTO COMPLETE SECTION
            [System.Web.Services.WebMethodAttribute(), System.Web.Script.Services.ScriptMethodAttribute()]
            public static string[] GetCompletionList(string prefixText, int count, string contextKey)
            {
                List ListCempName = new List(); // List Object
                try
                {
                    // Open the connection (can re-use connection string as defined in web.config)
                    SqlConnection SqlCon = new SqlConnection(System.Configuration.ConfigurationManager.ConnectionStrings["ITInventoryConnectionString"].ConnectionString);
                    SqlCon.Open();

                    // Create a Command
                    SqlCommand SqlComm = new SqlCommand();
                    SqlComm.Connection = SqlCon;

                    // Add a employee name SQl Parameter
                    SqlComm.Parameters.Add("@cempname", SqlDbType.VarChar).Value = prefixText; // retrievable throught prefixText parameter

                    // Query for get country name from database
                    SqlComm.CommandType = CommandType.Text;
                    SqlComm.CommandText = "SELECT cempname FROM BMEMP WHERE (BMEMP.LISTERM = 'false') AND (BMEMP.cempname LIKE ''+@cempname+'%') ";

                    // Read the data and add in List object.
                    SqlDataReader SqlDr = SqlComm.ExecuteReader();

                    if (SqlDr != null)
                    {
                        while (SqlDr.Read())
                        {
                            ListCempName.Add(SqlDr["cempname"].ToString());
                        }
                    }
                }
                catch (Exception ex)
                {
                    throw new Exception(ex.Message);
                }
                return ListCempName.ToArray();
            }
       }
}

Inject 3rd party drivers into WDS image

I use Windows Deployment Services (WDS) under Server 2008 to deploy images of Windows 7 x64 over PXE to my desktops and laptops.

I’ve standardized on Dell Latitude and Optiplex computers, so I want these drivers to remain in place after the sysprep, so they don’t need to be added later.

Apparently Server 2008 R2 WDS has the ability to add drivers through the GUI, but I don’t have that luxury yet. Here’s how I’ve gotten these drivers into my image.

 

The major prerequisite is that you’ll need the Windows AIK tools installed on your server. They can be found here:

http://www.microsoft.com/downloads/en/details.aspx?familyid=696DD665-9F76-4177-A811-39C26D3B3B34&displaylang=en

Note: you’ll need to have extracted folders of each driver you wish to inject, with the .INF file available. For each model, put all your drivers in it’s own folder under the master one. For example:

  • E5420
    • Video
    • LAN
    • Audio
    • Chipset

First, open the WDS console, and export the image you want to modify. Right click on the image, and choose Export. Export it to D:\ExportedImages

WDS Export image right click context menu

Then, from an elevated command prompt window, run the following (two separate lines):

"C:\program files\windows aik\tools\petools\copype.cmd" amd64 d:\windowspe-amd64
Imagex /mountrw D:\ExportedImages\Windows7-x64-Field.wim 1 mount

Then copy d:\windowspe-amd64\mount\windows\system32\dism.exe to d:\windowspe-amd64\mount\windows\system32\dism\

Use the following command template to inject the drivers for each system:

dism.exe  /image:d:\windowspe-amd64\mount /add-driver /driver:d:\drivers\E6420\ /recurse

When completed, run this command:

imagex /unmount /commit mount

Now re-import the image, either by adding, or replacing the existing one from the right click menu.

Replace WDS image

Automated DFSR Backlog email

If you’re using DFSR for branch office replication, chances are you’re concerned about the number of files in the backlog queue. This page details a script I’ve been using to automate sending of emails, using a combination of blat and dfsrdiag.

To begin you’ll need to download Blat.

I suggest placing the Blat files within C:\Windows so that it’s automatically added to the system path; you could just use the full folder path when calling it though.

Here’s an example batch script I’m using for one replication group:

:: BATCH SCRIPT START
@ECHO OFF
dfsrdiag Backlog /receivingmember:hub-server /sendingmember:branch-server /rgname:domain.com\files\departments /rfname:Departments >C:\users\administrator\documents\backdept-from-branch-server.txt
FOR /R "C:\users\administrator\documents\" %%F IN (backdept-from-branch-server.txt) DO (
       IF %%~zF GTR 3000 (blat C:\users\administrator\documents\backdept-from-branch-server.txt -to email@domain.com  -server smtp.domain.com -f dfsbacklog@domain.com -subject "Backlog exists: Departments incoming from Branch-Server"))
EXIT
pause
:: BATCH SCRIPT END

 

Here’s a quick rundown on what this is doing:

dfsrdiag Backlog: this command generates a backlog report for the specified sending and receiving server, for the specified replication group, and outputs it to a text file.

This report looks like this:

Member  Backlog File Count: 1367
Backlog File Names (first 100 files)
     1. File name: DSC03752.JPG
     2. File name: DSC03786.JPG
     3. File name: DSC03794.JPG
     4. File name: DSC03796.JPG
     5. File name: DSC03809.JPG
     6. File name: DSC03810.JPG

 

The next line in the script beginning with “FOR /R”, looks for the text file just generated, and runs logic on it.

IF %%~zF GTR 3000: If the size of the backlog report text file is greater than 3KB, then generate an email to the specified people, with the text file as the message body.

Scheduling the commands

So I’ve got 16 batch files that generate reports; 2 replications groups in two transfer directions to 4 separate locations. To reduce the number of scheduled tasks, and ensure that all 16 backlog reports aren’t run at the same time, I’ve got separate batch files that call 4 at a time, and are scheduled 5 minutes apart.

Find Hyper-V VM GUID

While creating and converting VM’s using SCVMM puts the configuration files and VHD’s in a nicely structured set of folders, if you create a VM through Hyper-V Manager or convert using disk2vhd, the files will be stored based on the GUID for the VM, which isn’t found anywhere in the GUI tools for Hyper-V.
Luckily I came across this blog post to which I owe full credit for the solution:

http://blogs.technet.com/b/m2/archive/2008/07/04/how-to-get-the-bios-guid-from-a-hyper-v-vm.aspx?ppud=4&wa=wsignin1.0#comments

Save the VBS script below as guid.vbs, copy to your Hyper-V host, and use psexec to execute it with this:

psexec \\hyperv cmd.exe

cscript c:\guid.vbs

You are using PSexec right?

Option Explicit
Dim WMIService
Dim KvpComponents
Dim VMList
Dim VMSettingList
Dim VM
Dim item
Dim setting
Dim component

'Get instance of 'virtualization' WMI service on the local computer
Set WMIService = GetObject("winmgmts:\\.\root\virtualization")
'Get all the MSVM_ComputerSystem object
Set VMList = WMIService.ExecQuery("SELECT * FROM Msvm_ComputerSystem")   
For Each VM In VMList  
 if VM.Caption = "Virtual Machine" then      
  WScript.Echo "========================================"      
  WScript.Echo "VM Name: " & VM.ElementName      
  WScript.Echo "VM GUID: " & VM.Name     
  WScript.Echo "VM State: " & VM.EnabledState   

  ' Now get the BIOS GUID for this VM
  Set VMSettingList = WMIService.ExecQuery("SELECT * FROM Msvm_VirtualSystemSettingData")   
  For Each setting In VMSettingList
   Dim tempVMname
   tempVMName = "Microsoft:"  + VM.Name
   if setting.InstanceID = tempVMName then      
    WScript.Echo "VM BIOS GUID: " & setting.BIOSGUID  
   end if
  Next
 end if
Next

Silent Printer Deployment in Windows

If you don’t use a print server in your Windows environment (for which there are many valid reasons) then printer management can be a major frustration. We don’t use a print server, but rather create static printers with local TCP/IP ports.
Installing these one by one, or updating drivers had become a drain on time, so I set about finding out how to silently deploy them to our client PC’s.

Getting Started

You’ll need a few support files to get this deployment working. The first are 3 vbs scripts:

  • prndrvr.vbs
  • prnmngr.vbs
  • prnport.vbs

You can find these in C:\Windows\System32 on a Windows XP machine.

You’ll also need PSEXEC from here: http://technet.microsoft.com/en-us/sysinternals/bb897553

Place the VBS scripts on a network share, perhaps where you’ll be storing the deployment batch files.

The Script

Below is the contents of a single printer install batch file. You can also combine multiple printer commands into one file, so that all printers in one office would be deployed at once.

This batch file should be run from somewhere other than the client PC you’re deploying to. Make sure you have PSexec somewhere in the path on that machine.

::This Script installs the following: ## denotes commented out by default
:: Printer Name

:: If you do not wish a certain printer to be installed, make a copy of this file, comment out the specific printer, and run the file

:: Define computer to push to, and the password to use for psexec authentication
set computername=TestPC
set password=pa55w0rd

:: Printer1 ::
:: Deletes previously installed printer of the specified name
cscript "\\server\Deploy\prnmngr.vbs" -d -s %computername% -p "Old Printer" 

:: Deletes static port of previous printer, in case of mis-configuration
cscript "\\server\Deploy\prnport.vbs" -d -s %computername% -r IP_192.168.0.42

:: Creates TCP/IP port with specified IP address
cscript "\\server\Deploy\prnport.vbs" -a -s %computername% -r IP_192.168.0.28 -h 192.168.0.28 -o raw -n 9100

:: Copies driver for printer from server to local directory
psexec \\%computername% -u domain\adminaccount -p %password% xcopy /E "\\server\Printer\HP 4500ps W2K-WXP\*.*" "c:\printdrv\"

::Install printer driver to computer from specified location.
cscript "\\server\Deploy\prndrvr.vbs" -a -s %computername% -m "HP Designjet 4500ps HP-GL/2" -v 3 -e "Windows NT x86" -h "c:\printdrv" -i "c:\printdrv\dsgj4500.inf"

:: Removes local directory containing print driver
psexec \\%computername% -u domain\adminaccount -p %password% cmd.exe "/C rmdir /S /Q "c:\printdrv\""

:: Install the printer, using the print driver specified prior.
cscript "\\server\Deploy\prnmngr.vbs" -a -s %computername% -p "Plotter3" -m "HP Designjet 4500ps HP-GL/2" -r IP_192.168.0.28 -u domain\adminaccount -w %password%

:: Sets the Printer Properties according to a template created prior
psexec \\%computername% -u domain\adminaccount -p %password% regedit.exe /s \\server\Deploy\Preferences\SurveyPrinter-WinXP.reg 
pause

If you’re deploying to Windows 7 x64, make sure you’re using x64 drivers, and then in the driver install section, change this: -e “Windows NT x86” to this: -e “Windows x64”

As shown in the last command, you can set printer properties (such as including a duplexer, stapler, additional paper trays) by installing the printer on a test machine, configuring the options you want, and then exporting this registry key:

[HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Print\Printers\Printer Name\PrinterDriverData]

You can also modify Printer Preferences using the same method. The registry key to export there is:

[HKEY_CURRENT_USER\Printers\DevModePerUser]

If you’re doing this, you’ll want to remove the extra printers from that key, and it must be run by the user who needs the preferences. Because of that I haven’t found a way to deploy the Printer Preferences directly to a user. Instead I just distribute the .reg file for them to run.

HP Printer Drivers

Recent versions of the HP printer drivers have been having problems installing using the VBS script. Because of this, a different command is used to install them:

psexec \\%computername% -u domain\adminaccount -p %password% rundll32.exe printui.dll PrintUIEntry /ia /f c:\printdrv\hpcu109u.inf /m "HP Universal Printing PCL 6"