Friday, November 27, 2009

VMware error: "Another task is already in progress"

Sometimes, in VMware ESX 3.5 and vSphere 4.0, when you try to perform some actions against a virtual machine (like for example to take a snapshot or to rename it) the system throw an exception with the message "Another task is already in progress" even if there are no active tasks.

The solution is to ssh to the physical ESX server that the virtual machine resides on and restart the “mgmt-vmware” service as the user root.

service mgmt-vmware stop
    Stopping VMware ESX Management services:
    VMware ESX Host Agent Watchdog [ OK ]
    VMware ESX Host Agent [ OK ]


Wait 30 seconds and start the service

service mgmt-vmware start
    Starting VMware ESX Management services:
    VMware ESX Host Agent (background) [ OK ]
    Availability report startup (background) [ OK ]


The ESX server and any virtual machines hosted on it will disconnect from the Virtual Infrastructure/vSphere Client and can be reconnected by right clicking on the ESX server and choosing “reconnect”.

When it reconnects attempt the tasks that were failing earlier and they should now as intended.

Friday, November 6, 2009

Exchange 2007 Message Size Limit

In Microsoft Exchange 2007 you have 10Mb limit for messages size. To increase this limit, you have to do several configurations.

After setting the single user mailbox limit from the GUI (Exchange Management Console), go to the shell (Exchange Management Shell) and type the commands below. Uppercase commands print the configuration parameters, "set" commands modify the values.


GET-TRANSPORTCONFIG

set-transportconfig -MaxReceiveSize VALUE
set-transportconfig -MaxRecipientEnvelopeLimit VALUE
set-transportconfig -MaxSendSize VALUE


GET-RECEIVECONNECTOR LIST

set-receiveconnector -MaxMessageSize VALUE (if requested, the "identity" are listed by the upper command)


GET-SENDCONNECTOR LIST


set-sendconnector -MaxMessageSize VALUE (if requested, the "identity" are listed by the upper command)



VALUE can be expressed, for example, like 10000 or 10MB

Monday, September 28, 2009

VMware vSphere Client on Windows 7

VMware vSphere client doesn't work if you have a Windows 7 pc.

When you try to connct to an Esx server or a Virtual Center server, you'll give these errors:

  • Error parsing the server "nome del server" "clients.xml" file.
  • The type initializer for 'VirtualInfrastructure.Utils.HttpWebRequestProxy' threw an exception.

But with this workaround, the program will works fine:

  1. Edit the VpxClient.exe.config file:
    <?xml version="1.0" encoding="utf-8"?>

    <configuration>

    <system.net>

    <connectionManagement>

    <clear/>

    <add address="*" maxconnection="8" />

    </connectionManagement>

    </system.net>

    <appSettings>

    <add key = "protocolports" value = "https:443"/>

    </appSettings>

    <runtime>

    <developmentMode developerInstallation="true"/>

    </runtime>

    </configuration>
  2. Create in C:\Program Files\Vmware\Infrastructure\Virtual Infrastructure Client\Launcher folder (or in the folder qhere you have installed the software) a subfolder called Lib. In this subfolder copy the system.dll .Net file from a non Windows 7 box (see above)
  3. Crete a new system variable named DEVPATH with value C:\Program Files\Vmware\Infrastructure\Virtual Infrastructure Client\Launcher\Lib


Now the program works fine

PS: A copy of the configuration and of the system.dll file are downloadable here.

Wednesday, June 24, 2009

SQL Server Log File Shrink for all databases on a server

If you use SQL Server, you certainly now that the grow up of transacion log file (.ldf file) is a serious problem.

The faster method to resize the transaction log is to do a shrink.

But if there are N databases on a server, a DBA has to repeat the operation for N times. So, I've created this T-Sql script with that you can automatically execute this operation for all databases on a server.


EXECUTE sp_msforeachdb
'USE ?;
DUMP TRANSACTION ? WITH NO_LOG;
DECLARE @LogLogicalName nvarchar(100);
SELECT @LogLogicalName = file_name(2);
DBCC SHRINKFILE(@LogLogicalName, 100);'


sp_msforeachdb: an undocumented microsoft stored procedure that allow to execute T-SQL code on each database on a DB server.

?: the database name given from stored procedure.

file_name(2): a function that return the logical name of db transaction log file.


Wednesday, June 3, 2009

Disable a button after click (Asp.Net)

To disable a button after click, to avoid that a user re-click on it before the completion of the operation, we have tu use javascript.
The problem is that the disable javascript function remove the postback ability of the button.

To bypass this problem, we can use the following code, writing it into Page Load event:

Me.btn.Attributes("onclick") = "this.disabled = true; " & Page.GetPostBackEventReference(btnSub).ToString

Into this code, btn is the id of the button and btnSub is the routine that normally handles btn.Click event

Thursday, May 14, 2009

Windows Server 2008 and Shared Folders

Working with shared folders on Windows Server 2008 operating system server, there could be some problems:

The system detected a possible attempt to compromise security. Please ensure that you can contact the server that authenticated you.

To work around this problem, make sure that client computers use the cryptography algorithms that are compatible with Windows Server 2008. You may have to request software updates from the product vendors.

If you cannot install software updates because a service outage will occur, follow these steps:

1.       Log on to a Windows Server 2008-based domain controller.

2.       Click Start, click Run, type gpmc.msc, and then click OK.

3.       In the Group Policy Management console, expand Forest: DomainName, expand DomainName, expand Domain Controllers, right-click Default Domain Controllers Policy, and then click Edit.

4.       In the Group Policy Management Editor console, expand Computer Configuration, expand Policies, expand Administrative Templates, expand System, click Net Logon, and then double-click Allow cryptography algorithms compatible with Windows NT 4.0.

5.       In the Properties dialog box, click the Enabled option, and then click OK.

Notes

o        By default, the Not Configured option is set for the Allow cryptography algorithms compatible with Windows NT 4.0 policy in the following Group Policy objects (GPO):

§         Default Domain Policy

§         Default Domain Controllers Policy

§         Local Computer Policy

By default, the behavior for the Allow cryptography algorithms compatible with Windows NT 4.0 policy on Windows Server 2008-based domain controllers is to programmatically prevent connections from using cryptography algorithms that are used in Windows NT 4.0. Therefore, tools that enumerate effective policy settings on a member computer or on a domain controller will not detect the Allow cryptography algorithms compatible with Windows NT 4.0 policy unless you explicitly enable or disable the policy.

o        Windows 2000 Server-based domain controllers and Windows Server 2003-based domain controllers do not have the Allow cryptography algorithms compatible with Windows NT 4.0 policy. Therefore, pre-Windows Server 2008-based domain controllers accept security channel requests from client computers even if the client computers use the old cryptography algorithms that are used in Windows NT 4.0. If security channel requests are intermittently processed by Windows Server 2008-based domain controllers, you will experience inconsistent results.

6.       Install third-party software updates that fix the problem, or remove client computers that use incompatible cryptography algorithms.

7.       Repeat steps 1 through 4.

8.       In the Properties dialog box, click the Disabled option, and then click OK.

Important For security reasons, you should set the option for this policy back to Disabled.


Saturday, May 9, 2009

jQuery Intellisense in Visual Studio 2008 (VS 2008)

To enable intellisense completion for jQuery within VS you'll want to follow three steps:


Step 1: Install VS 2008 SP1

VS 2008 SP1 adds richer JavaScript intellisense support to Visual Studio, and adds code completion support for a broad range of JavaScript libraries.

You can download VS 2008 SP1 here.


Step 2: Install VS 2008 Patch KB958502 to Support "-vsdoc.js" Intellisense Files

Few weeks ago Microsoft shipped a patch that you can apply to VS 2008 SP1 that causes Visual Studio to check for the presence of an optional "-vsdoc.js" file when a JavaScript library is referenced, and if present to use this to drive the JavaScript intellisense engine.

These annotated "-vsdoc.js" files can include XML comments that provide help documentation for JavaScript methods, as well as additional code intellisense hints for dynamic JavaScript signatures that cannot automatically be inferred. You can download it here.


Step 3: Download the jQuery-vsdoc.js file

Microsoft worked with the jQuery team to put together a jQuery-vsdoc.js file that provides help comments and support for JavaScript intellisense on chained jQuery selector methods. You can download both jQuery and the jQuery-vsdoc file from the official download page on the jQuery.com site.

Save the jquery-vsdoc.js file next to your jquery.js file in your project (and make sure its naming prefix matches the jquery file name). For example, if the jQuery library file is jquery.1.2.6.js, the vsdoc file will be named jquery-.1.2.6-vsdoc.js


You can then reference the standard jquery file with an html <script/> element like so:

<script src="../Folder/jquery.1.2.6.js" type="text/javascript"></script>

When you do this VS will now look for a -vsdoc.js file in the same directory as the script file you are referencing, and if found will use it for help and intellisense.

Thursday, April 23, 2009

Uninstalling System Center Essential (SCE) 2007

If you’re evaluating SCE or plan on moving SCE to new hardware it is important to understand how to correctly remove SCE from your environment prior to starting a new installation. We have performed many reinstallations while developing our SCE installation procedures and I thought I would share the steps.


Delete SCE Managed Computers Group from Active Directory

Start > Run > dsa.msc
Right-click on DomainName and click Find
Type SCE Managed Computers into the Name box and click Find Now
Right-click SCE Managed Computers in the results pane and click Delete
Close Active Directory Users & Computers


Delete Group Policies

If you performed a default installation of System Center Essentials you will have two group policy objects that were automatically created for you. Follow these steps to delete the group policies.

Start > Run > gpmc.msc
Expand DomainName > Group Policy Objects in the left pane
Right-click SCE Managed Computers Group Policy (…) and click Delete
Right-click System Center Essentials All Computers Policy and click Delete
Close Group Policy Management Console


Delete Service Connection Point (SCE)

The following procedure requires ADSI Edit.

Start > Run > adsiedit.msc
Right-click ADSI Edit in the left pane and click Connect
Select Default naming context in the Select a well known Naming Context box and click OK
Right-click Default naming context in the left pane and select New > Query…
Type SCESCP in the Name box
Click the Browse… button, select DomainName , and click OK
Paste (&(objectCategory=serviceConnectionPoint)(cn=SCESCP)) into the Query String box and click OK
Highlight and then expand Default naming context in the left pane
Select SCESCP in the left pane
Right-click CN=SCESCP in the middle pane and click Delete
Leave ADSI Edit open for the next step


Delete Service Connection Point (SDKServiceSCP)

Right-click Default naming context in the left pane and select New > Query…
Type SDKSCP in the Name box
Click the Browse… button, select DomainName , and click OK
Paste (&(objectCategory=serviceConnectionPoint)(cn=SDKServiceSCP)) into the Query String box and click OK
Highlight and then expand Default naming context in the left pane
Select SDKSCP in the left pane
Right-click the appropriate CN=SDKServiceSCP entry in the middle pane and click Delete

Identifying the appropriate entry to delete in step 7 above requires finding the entry that corresponds to the name of the SCE server to be removed. Look at the distinguished name column in the middle pane to locate the right computer name.

Thursday, April 16, 2009

Asp.Net Menu and Internet Explorer 8 (IE8)

If you use Asp.Net Menu control, you have surely noticed that with Internet Explorer 8 there are a problem with submenus.

Microsoft give out a patch for webservers IIS to fix that problem, but for me there is a better solution: working with CSS.

The Css Class to create is very simple:

.IE8Fix
{
z-index: 100;
}

and then you ave to apply it to DynamicMenuStyle tag:

<asp:Menu ID="MioMenu1" runat="server" ... >
...
<DynamicMenuStyle CssClass="IE8Fix" />
...
<asp:Menu>

Tuesday, April 7, 2009

SQL Server 2008 Row Constructors

SQL Server 2008 Row Constructors

SQL Server 2008 come with “Row Constructor”. It helps to write more compact code in less time.
With the use of Row Constructors its possible to insert some rows in a table using a single INSERT instruction:

INSERT INTO dbo.Customers(custid, companyname, phone, address)
VALUES
(1, 'cust 1', '(111) 111-1111', 'address 1')
,(2, 'cust 2', '(222) 222-2222', 'address 2')
,(3, 'cust 3', '(333) 333-3333', 'address 3')
,(4, 'cust 4', '(444) 444-4444', 'address 4')
,(5, 'cust 5', '(555) 555-5555', 'address 5');



In aggiunta a questa possibilità, now VALUES clause also works with other commands. In simple words, its possible to rewrite some SELECt with UNION operator as a single SELECT…VALUES:

SELECT *
FROM
(VALUES
(1, 'cust 1', '(111) 111-1111', 'address 1')
,(2, 'cust 2', '(222) 222-2222', 'address 2')
,(3, 'cust 3', '(333) 333-3333', 'address 3')
,(4, 'cust 4', '(444) 444-4444', 'address 4')
,(5, 'cust 5', '(555) 555-5555', 'address 5')
) AS C(custid, companyname, phone, address);

Thursday, March 5, 2009

Transparent redirect (HTML)

Sometimes we have to create a redirect for a web application or a web site. Usually, the browser address bar change its text, so users see the redirection.

But there is a very simple way to redirect user to another site/domain without the change of the address bar: just create a page like this

<html>
    <head>
    </head>
    <frameset>
        <frame name="main" src="http://www.newdomain.it">
    </frameset>
    <body>
    </body>
</html>

PS: There are some other ways to do this, but all uses javascript. This is the only method that doesn't use scripts or other.

Wednesday, February 25, 2009

Modal Dialog (window.showModalDialog) and cache problem

When using Modal Dialogs (esclusive focus windows) in Asp.Net with DataBase retrieved data, there are one small problem: data are loaded from db only the first time you open the window. After that, data is going to be loaded from the cache.

To solve this problem, we have to put into page load even onf the modal dialog page the following lines of code:


Response.Cache.SetCacheability(HttpCacheability.NoCache)
Response.Cache.SetExpires(DateTime.Now - New TimeSpan(1, 0, 0))
Response.Cache.SetLastModified(DateTime.Now)
Response.Cache.SetAllowResponseInBrowserHistory(False)




To open the window as modal dialog, use this javascript method:

hlkNewWindow.Attributes.Add("onclick", "javascript: window.showModalDialog('PageToOpen.aspx', null, 'status:no; dialogWidth:500px; dialogHeight:400px; dialogHide:true; help:no; scroll:no;')"

This example opens a modal dialog of 400x500 pixel, without status bar, buttons and scrolls with a click on the hlkNewWidow HyperLink.

Wednesday, February 18, 2009

Load an image from Database with VB.Net

    Dim count As Integer = 1
    Dim Album As New Collection
    Dim Query As String
    Dim Archive As SqlConnection

Private Sub Form2_Load(ByVal sender As System.Object,ByVal e As System.EventArgs) Handles MyBase.Load
    Archive = New SqlConnection
    Archive.ConnectionString = "connection string"
    Query = "SELECT Photo FROM ALBUM"
    Dim cmd As New SqlCommand(Query, Archive)
    Archive.Open()
    Dim I As Integer = 0
    Dim reader As SqlDataReader = cmd.ExecuteReader()
    Dim Temp As Byte ()
    While reader.Read
        Temp = reader(0)
        Album.Add(Temp)
    End While
    If Album.Count > 0 Then
        Temp = CType (Album.Item(count), Byte())
        Dim Img As MemoryStream = New MemoryStream(Temp)
        PictureBox1.Image = Image.FromStream(Img)
    End If
End Sub

Private Sub btnPrev_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnPrev.Click
    Dim Temp As Byte ()
    If count > 1 Then
        count = count - 1
        Temp = CType (Album.Item(count), Byte())
        Dim Img As MemoryStream = New MemoryStream(Temp)
        PictureBox1.Image = Image.FromStream(Img)
    End If
End Sub

Private Sub btnNext_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnNext.Click
    Dim Temp As Byte ()
    If count Album.Count Then
        count = count + 1
        Temp = CType (Album.Item(count), Byte())
        Dim Img As MemoryStream = New MemoryStream(Temp)
        PictureBox1.Image = Image.FromStream(Img)
    End If
End Sub

Load image into Database with VB.Net

    Dim Archive As SqlConnection
    Archive = New SqlConnection
    Archive.ConnectionString = "connection string"
    

Private Sub btnFile_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnFile.Click
    OpenFileDialog1.Filter = "BMP - Bitmap Windows | *.bmp | " _
    & "GIF - CompuServe Graphics Interchange | *.gif | JPG - " _
    & "Compatibile JFIF | *.jpg"
    OpenFileDialog1.Title = "Select image..."
    OpenFileDialog1.ShowDialog()
    If OpenFileDialog1.FileName <> "" Then
         TextBox1.Text = OpenFileDialog1.FileName.ToString
         PictureBox1.Image = Image.FromFile(OpenFileDialog1.FileName.ToString)
    End If
End Sub

Private Function ImageToStream()As Byte ()
    Dim Image As New Bitmap(TextBox1.Text)
    Dim stream As MemoryStream = New MemoryStream()
    Image.Save(stream, _
    System.Drawing.Imaging.ImageFormat.Bmp)
    Return stream.ToArray()
End Function

Private Sub Load()
    If File.Exists(TextBox1.Text) Then
         Dim Query As String
        Query = "INSERT INTO Album (Foto) VALUES (@Img)"
        Dim mycommand As New SqlCommand(Query, Archive)
        Archive.Open()
        Dim param As SqlParameter = New SqlParameter("@Img", SqlDbType.Binary)
        param.Value = ImageToStream()
        mycommand.Parameters.Add(param)
        mycommand.ExecuteNonQuery()
        mycommand = Nothing
        Archive.Close()
        PictureBox1.Image = Nothing
        TextBox1.Text = ""
    Else
        MessageBox.Show("File not found!!" , ""Test DB Image", _
            MessageBoxButtons.OK, MessageBoxIcon.Exclamation, _
            MessageBoxDefaultButton.Button1, _
            MessageBoxOptions.DefaultDesktopOnly)
    End If
End Sub

Monday, January 19, 2009

Read a single value from a query with VB.Net

Sometimes it's necessary to read single value from a table (or a query). Here's the code:

Imports System.Data.Oledb


Dim ConnString As String = "connection string"
' open connection
Dim Conn As New Data.OleDb.OleDbConnection(ConnString)
Cn.Open()

' request execution
Dim SQL As String = "SELECT Data FROM Table WHERE ID = 'aaaa';"
Dim command As New Data.OleDb.OleDbCommand(Sql, Conn)
Dim ID As Integer = command.ExecuteScalar()

'close connection
Cn.Close()

Sunday, January 18, 2009

Image to byte array conversion

It's very easy to convert an image into a byte array, with VB.NET; using MemoryStream object:

Private Function ConvertImageToByteArray(ByVal inputImage As Image) As Byte()
    Dim ms As New System.IO.MemoryStream
    inputImage.Save(ms, System.Drawing.Imaging.ImageFormat.Bmp)
    Return ms.ToArray
End Function


To re-convert the byte array into image, we can use ImageConverter class:

Private Function ConvertByteArrayToBitmap(ByVal array As Byte()) As Bitmap
    Dim ic As New ImageConverter
    Dim img As Image = CType(ic.ConvertFrom(array), Image)
    Dim bmp As New Bitmap(img)
    Return bmp
End Function

Friday, January 16, 2009

Email address validation with Vb.net and Regula Expression

Imports System.Text.RegularExpressions


Dim ValidateMail As String = "^([\w-\.]+)@((\[[0-9]{1,3}\.[0-9]{1,3}\.)|(([\w-]+\.)+))([a-zA-z]{2,4}|[0-9]{1,3})(\]?)$"

Dim EmailAddress As String = "$mymail@domain.com$"

If Regex.IsMatch(EmailAddress, ValidateMail) Then
...
Else
...
End If

Thursday, January 15, 2009

Mounting CdRom on SCO/Unix

After the creation of the folder as mount point with mkdir    /mnt/cdrom, we have to find the "phisycal" name of cdrom unit. To do it, go to device folder with

cd   /dev/cdrom

and then type

ls

to view the name. For this example, assume c0b0t6l0 as the device name

So, the mount command is:

mount   -r   -F   cdfs   /dev/cdrom/c0b0t6l0   /mnt/cdrom