Archive

Archive for October, 2008

Change boot sequence in VMWare

October 21st, 2008

I do all development stuff on virtual machine. Mainly because of trying new software and to have installation which I can always restore without any problem. Today I made update of Windows Vista and reboot problem where it gives the “configuring updates stage 3 of 3″ then reboots ad infinity. What I need to do as one of the steps is to boot from the original CD.

When you restart the virtual machine you will see vmware splash screen. Hit F2 right away to get into the VM’s BIOS settings. It can show only for really short time.
VMWare splash screen

After that you will be in vmware BIOS. Use the right arrow key three times to move over to the “BOOT” menu selection. Use the UP/DOWN arrow key and the +/- keys to toggle the boot order such that “Removable Devices” is the very first (top) in the boot order. Removable Devices includes Legacy Floppy Drives.
VMWare BIOS - Boot sequence

Hit F10 to save and exit
VMWare BIOS - Save

Uncategorized

ASP.NET MVC Beta released

October 17th, 2008

ASP.NET MVC is finally in beta. I’ve been looking for this for some time. ASP.NET with the components and view state is not what I like. This MVC is something what I’ve been missing. When this is in preview 5 I was little bit wary about to make any application which will go to live. Changes between preview 4 and preview 5 changed interface of a few classes. The Beta version should change a lot from first official release.

Today’s ASP.NET MVC Beta release comes with an explicit “go-live” license that allows you to deploy it in production environments.

Read more on ScottGu blog.

MVC

Ajax second postback not working in Sharepoint in UpdatePanel

October 10th, 2008

We have one problem in work, we spend with that two days without any solution, all we found cause some another problem. This is what help us when the page is not making second postback in update panel when the first postback is fired by element in UpdatePanel and refresh only update panels on the page.

Taken from Mike Ammerlaan’s Blog

Windows SharePoint Services JavaScript has a “form onSubmit wrapper” which is used to override the default form action.  This work is put in place to ensure that certain types of URLs, which may contain double byte characters, will fully work across most postback and asynchronous callback scenarios.  However, if your scenarios do not involve double byte character URLs, you may successful disable this workaround and gain the ability to use ASP.NET AJAX UpdatePanels.

To do this, you may need to register a client startup script which disables this workaround, in addition to resetting the default form action:


<script type='text/javascript'>
  _spOriginalFormAction = document.forms[0].action;
  _spSuppressFormOnSubmitWrapper=true;
</script>

This script may be directly embedded in the page, or could be emitted by a control that uses the UpdatePanel. The following is an example of a very simple method which will fix this issue:


private void EnsureUpdatePanelFixups()
{
  if (this.Page.Form != null)
  {<br />
    string formOnSubmitAtt = this.Page.Form.Attributes["onsubmit"];
    if (formOnSubmitAtt == "return _spFormOnSubmitWrapper();")
    {
      this.Page.Form.Attributes["onsubmit"] = "_spFormOnSubmitWrapper();";
    }
  }
  ScriptManager.RegisterStartupScript(this, typeof(AjaxUpdatePanelPart), "UpdatePanelFixup", "_spOriginalFormAction = document.forms[0].action; _spSuppressFormOnSubmitWrapper=true;", true);
}

Sharepoint , ,

Storing Database Connection String in Web.Config

October 9th, 2008

Today I found, that storing connection strings were little bit changed between .NET 2.0 and .NET 3.5.

Here is an example of how to store a database connection string in the application’s Web.Config file for .NET 2.0. The code for accessing the connection string is located in the C# code below.

.NET 2.0


<appSettings>
<add key="ConnectionString" value="server=localhost;database=TestDB;uid=sa;password=secret;" />
</appSettings>

And here is the C# code how to get it.


using System.Configuration;

public class TestGetConnection
{
  public TestGetConnection()
  {
    try
    {
      // Get connection string from Web.Config
      string strConnection = ConfigurationSettings.AppSettings("ConnectionString");
    }
  }
}

.NET 3.5

ConfigurationSettings.AppSettings is now deprecated.


<connectionStrings>
  <add name="YourConnectionString" connectionString="server=localhost;database=TestDB;uid=sa;password=secret;" providerName="System.Data.SqlClient" />
  <add name="NewString" connectionString="server=localhost;database=TestDB;uid=sa;password=secret;" providerName="System.Data.SqlClient" />
</connectionStrings>

And here is the C# code how to get it.


using System.Configuration;

public class TestGetConnection
{
  public TestGetConnection()
  {
    try
    {
      // Get connection string from Web.Config
      string strConnection = ConfigurationManager.ConnectionStrings["YourConnectionString"].ConnectionString;
    }
  }
}

You can use <remove /> to delete connection setting from web.config.


<connectionStrings>
  <remove name="YourConnectionString"/>
  <add name="YourConnectionString" connectionString="server=localhost;database=TestDB;uid=sa;password=secret;" providerName="System.Data.SqlClient" />
</connectionStrings>

Connection String Syntax Notes

  • Values may be delimited by single or double quotes, (for example, name=’value’ or name=”value”). Either single or double quotes may be used within a connection string by using the other delimiter, for example, name=”value’s” or name=’value”s’,but not name=’value’s’ or name=”"value”". The value type is irrelevant.
  • All blank characters, except those placed within a value or within quotes, are ignored.
  • Keyword value pairs must be separated by a semicolon ( ; ). If a semicolon is part of a value, it also must be delimited by quotes.
  • Names are not case sensitive. If a given name occurs more than once in the connection string, the value associated with the last occurence is used.
  • No escape sequences are supported.

If you need to connect to SQL Express, you shold use connection string with specifying the file you want to attach.


connectionString="Server=.\SQLExpress;AttachDbFilename=c:\Program Files\Microsoft SQL Server\MSSQL.1\MSSQL\DATA\SpamTestimonial.mdf;Database=SpamTestimonial;Trusted_Connection=Yes;"

If you need to find all possible connection string, go to web page dedicated to them for more databases than you can image. http://www.connectionstrings.com/

.NET , , , ,

Tree traversal data structure - stored procedures

October 8th, 2008

In the first part of this article I wrote about tree traversal database structure. Now I want to show you how to prepare all stored procedures and triggers to be able to work with it effectively. From the first part we have already database structure and we filled the table with data. Now we need to have these data always with correct informations.

What can happen

There are many scenarios what can happen and you need to recreate lft and rtg in the tree. For inserting new category, deleting old one and move category under another parent, we can use one procedure:


ALTER PROCEDURE dbo.RecreateCategoryTree
  @id INT = NULL,
  @cnt INT = 0
AS
BEGIN
  SET NOCOUNT ON;
  DECLARE @actId INT,
    @actLft INT,
    @actRtg INT;
  DECLARE categories_cursor CURSOR LOCAL
  FOR
    SELECT ID, lft, rtg
    FROM dbo.Categories
    WHERE (ParentID = @id) OR (@id IS NULL AND ParentID IS NULL);
  OPEN categories_cursor
  FETCH NEXT FROM categories_cursor
  INTO @actId, @actLft, @actRtg

  WHILE @@FETCH_STATUS = 0
  BEGIN
    SET @cnt = @cnt + 1;

    UPDATE dbo.Categories SET lft = @cnt WHERE ID = @actID;

    EXEC @cnt = [dbo].[RecreateCategoryTree] @actId, @cnt;
    SET @cnt = @cnt + 1;

    UPDATE dbo.Categories SET rtg = @cnt WHERE ID = @actID;

    FETCH NEXT FROM categories_cursor
    INTO @actId, @actLft, @actRtg
  END
  CLOSE categories_cursor
  DEALLOCATE categories_cursor

  RETURN @cnt;
END
GO

When we call this stored procedure it will recreate all lft and rtg information in Categories table. Second step will be to create trigger what will be fired after insert, update or delete.


CREATE TRIGGER dbo.RecreateCategories
ON  dbo.Categories
AFTER INSERT,DELETE,UPDATE
AS
BEGIN
  SET NOCOUNT ON;
  EXEC [dbo].[RecreateCategoryTree]
END
GO

This is realy the easiest way. It will not be fast with many records. For table with a few hundred record and occasional update it’s enought. Now we can try if everything is working as we need. Try to insert into category:


INSERT INTO dbo.Categories (CategoryName, ParentID) VALUES ('Celeron', 2);

C#, Database , , , , ,