Search This Blog

Tuesday, November 15, 2011

Saving changes is not permitted (SQL Server 2008)


While creating and editing a database in SQL server 2008 I soon ran into a brick wall, or a 'by design' feature of the Database Management Studio.
When you design a table in a database and then try to make a change to a table structure that requires the table to be recreated, the Database Management Studio will not allow you to save the changes.
This is caused by a configuration setting that default results in the following dialog:
Error dialog
This dialog states: "Saving changes is not permitted. The changes you have made require the following tables to be dropped and re-created. You have either made changes to a table that can't be re-created or enabled the option Prevent saving changes that require the table to be re-created."
You can only react clicking the Cancel button.
And than Management Studio shows this dialog:

So what you want to do to configure the setting with the value you want (IMHO should be the default setting!).
Go to: Tools > Options
Tools menu choose Options
Select the tab Designers and choose Tables and designers
And uncheck the option: "Prevent saving changes that require table re-creation".
Once you now save changes it will work.

Monday, November 14, 2011

Nokia Secret Codes

Nokia Secret Codes
*#06# for checking the IMEI (International Mobile Equipment Identity).

*#7780# reset to factory settings.

*#67705646# This will clear the LCD display(operator logo).

*#0000# To view software version.

*#2820# Bluetooth device address.

*#746025625# Sim clock allowed status.

#pw+1234567890+1# Shows if sim have restrictions.

*#92702689# - takes you to a secret menu where you may find some of the information below:

1. Displays Serial Number.

2. Displays the Month and Year of Manufacture

3. Displays (if there) the date where the phone was purchased (MMYY)

4. Displays the date of the last repair - if found (0000)

5. Shows life timer of phone (time passes since last start)

*#3370# - Enhanced Full Rate Codec (EFR) activation. Increase signal strength, better signal reception. It also help if u want to use GPRS and the service is not responding or too slow. Phone battery will drain faster though.

*#3370* - (EFR) deactivation. Phone will automatically restart. Increase battery life by 30% because phone receives less signal from network.

*#4720# - Half Rate Codec activation.

*#4720* - Half Rate Codec deactivation. The phone will automatically restart

If you forgot wallet code for Nokia S60 phone, use this code reset: *#7370925538#

Note, your data in the wallet will be erased. Phone will ask you the lock code. Default lock code is: 12345

Press *#3925538# to delete the contents and code of wallet.

Unlock service provider: Insert sim, turn phone on and press vol up(arrow keys) for 3 seconds, should say pin code. Press C,then press * message should flash, press * again and 04*pin*pin*pin# \

*#7328748263373738# resets security code.

Default security code is 12345

Change closed caller group (settings >security settings>user groups) to 00000 and ure phone will sound the message tone when you are near a radar speed trap. Setting it to 500 will cause your phone 2 set off security alarms at shop exits, gr8 for practical jokes! (works with some of the Nokia phones.) Press and hold "0" on the main screen to open wap browser.

Reading xml file in Javascript

Reading xml file in Javascript

Here I am trying to read a xml file using javascript and displaying it's tag value and attribute values



menux.xml file is as follows....





In javascript the following functions will be using for reading xml file...




var xmlDoc;
var nodedisplay="\n\n";
var idDisplay="\n\n";
var nameDisplay="\n\n";
if (window.ActiveXObject)
{
xmlDoc=new ActiveXObject("Microsoft.XMLDOM")
xmlDoc.load("menus.xml")
getValuesie();
}
else if (document.implementation && document.implementation.createDocument)
{
xmlDoc=document.implementation.createDocument("","",null);
}
function getValuesie()
{
nodes=xmlDoc.documentElement.childNodes
for(var i=0;iIn the body ....there are three span's with ids....in each span ...after the span tag closed in script, write the following code...




In first span with Id of "nodeValue"


if (document.implementation && document.implementation.createDocument)
{
document.getElementById("nodeValue").innerHTML=afor();
}

next span with the Id of "idValue"


if (document.implementation && document.implementation.createDocument)
{
document.getElementById("idValue").innerHTML=bfor();
}

last span with the Id of "nameValue"


if (document.implementation && document.implementation.createDocument)
{
document.getElementById("nameValue").innerHTML=cfor();
}

Thursday, November 10, 2011

Singleton Pattern implementation using Private Constructor in C#

In this article, I have tried to show the implementation of singleton pattern in C# using Private constructor. the source of this article is dofactory

using System;

namespace ConsoleApplication1
{
  /// <summary>
  /// MainApp startup class for Structural
  /// Singleton Design Pattern.
  /// </summary>
  class Program
  {
    /// <summary>
    /// Entry point into console application.
    /// </summary>
   public  static void Main()
    {
      // Constructor is private-- cannot use new
      Singleton s1 = Singleton.Instance(); // trick to creating object 
      Singleton s2 = Singleton.Instance();

      // Test for same instance
      if (s1 == s2)
      {
        Console.WriteLine("Objects are the same instance");
      }

      // Wait for user
      Console.ReadKey();
    }
  }

  /// <summary>
  /// The 'Singleton' class
  /// </summary>
  class Singleton
  {
    private static Singleton _instance;

    // Constructor is 'private'
    private Singleton()
    {
    }

    public static Singleton Instance()
    {
      // Uses lazy initialization.
      // Note: this is not thread safe.
      if (_instance == null)
      {
        _instance = new Singleton();
// creating the instance and guaranteeing for single instance 
      }

      return _instance;
    }
  }
}

Output
Objects are the same instance

Adding a Contact Us Form and sending email with ASP.NET 4.0 and C#

Feed back form in asp.net 4.0 using gmail account for sending mail.


This tutorial will demonstrate how to add a simple Contact Us form for users to leave feedback via email in ASP.NET and C#. 

Setting Up the Form 
At this point in the tutorial I have created a new ASP.NET Empty Web Site in Microsoft Visual Studio and have added in a blank Web Form named Default.aspx. What we need to do now is setup a simple form to collect the data from the user. This will include a Name, Subject, and Message. Also, we will need a submit button that the user will click to send the email, and a label to show a result if the email was sent or not.

To do this, open up Default.aspx to source mode and add the following code in the div tag:
<h2>Contact Us</h2>
<br />
<table>
    <!-- Name -->
    <tr>
        <td align="center">
            Name:</td>
        <td>
            <asp:TextBox ID="txtName" 
                            runat="server"
                            Columns="50"></asp:TextBox>
        </td>
    </tr>
 
    <!-- Subject -->
    <tr>
        <td align="center">
            Subject:
        </td>
        <td>
            <asp:DropDownList ID="ddlSubject" runat="server">
                <asp:ListItem>Ask a question</asp:ListItem>
                <asp:ListItem>Report a bug</asp:ListItem>
                <asp:ListItem>Customer support ticket</asp:ListItem>
                <asp:ListItem>Other</asp:ListItem>
            </asp:DropDownList>
        </td>
    </tr>
 
    <!-- Message -->
    <tr>
        <td align="center">
            Message:
        </td>
        <td>
            <asp:TextBox ID="txtMessage" 
                            runat="server"
                            Columns="40"
                            Rows="6" 
                            TextMode="MultiLine"></asp:TextBox>
        </td>
    </tr>
 
    <!-- Submit -->
    <tr align="center">
        <td colspan="2">
            <asp:Button ID="btnSubmit" runat="server" Text="Submit" 
                onclick="btnSubmit_Click" />
        </td>
    </tr>
            
    <!-- Results -->
    <tr align="center">
        <td colspan="2">
            <asp:Label ID="lblResult" runat="server"></asp:Label>
        </td>
    </tr>
</table>

If you then open the Default.aspx page up to design mode you should see a table that looks similar to this: 

SS1.gif

Adding the Code 
The next thing we need to do is add the code to send the data from the form to our email address in the event that the submit button is clicked. To do this, double click the submit button to generate the Click event method for that button. Now in the Default.aspx.cs file, we will want to add in a few using statements that will allow us to send this email. Under the other using statements, add the following:
using System.Net.Mail;
using System.Net;

Next, we need to add some code to the Button's Click event method. The following code is a template for sending an email using a Gmail account, however you will need to customize this based on the RecipientAddress, which will be the email you are sending the message to, the SenderAddress, which will be the email account you will be sending the message from and also the SMTP server and port that are appropriate for your email provider.
try
{
    //Create the msg object to be sent
    MailMessage msg = new MailMessage();
    //Add your email address to the recipients
    msg.To.Add("RecipientAddress@gmail.com");
    //Configure the address we are sending the mail from
    MailAddress address = new MailAddress("SenderAddress@gmail.com");
    msg.From = address;
    //Append their name in the beginning of the subject
    msg.Subject = txtName.Text + " :  " + ddlSubject.Text;
    msg.Body = txtMessage.Text;
 
    //Configure an SmtpClient to send the mail.
    SmtpClient client = new SmtpClient("smtp.gmail.com", 587);
    client.EnableSsl = true; //only enable this if your provider requires it
    //Setup credentials to login to our sender email address ("UserName", "Password")
    NetworkCredential credentials = new NetworkCredential("SenderAddress@gmail.com", "xxxx");
    client.Credentials = credentials;
 
    //Send the msg
    client.Send(msg);
 
    //Display some feedback to the user to let them know it was sent
    lblResult.Text = "Your message was sent!";
 
    //Clear the form
    txtName.Text = "";
    txtMessage.Text = "";
}
catch
{
    //If the message failed at some point, let the user know
    lblResult.Text = "Your message failed to send, please try again.";
}