"If at first you don't succeed; call it version 1.0" :-Unknown

Pages

Monday, January 31, 2011

Recover the Database in SQL SERVER

 

Steps to Recover

1.create the Database with same Name,MDF Name,LDF Name.
2.Stop the Sql Server and then Replace the only new MDF file by old database (Corrupted database) MDF file and delete the LDF File of newly created database.
3.Now Start the Sql Server again.
4.you can notice that database status became 'Suspect' as expected.
5.Then run the given script to know the current status of your newly created datatbase.
(Better you note it down the current status)
SELECT *
FROM sysdatabases
WHERE name = 'yourDB'
6.Normally sql server would not allow you update anything in the system database.SO run the given script to enable the update to system database
sp_CONFIGURE 'allow updates', 1
RECONFIGURE WITH OVERRIDE
7.After run the above script, update the status of your newly database as shown below. once you updated the status, database status become 'Emergency/Suspect'.
UPDATE sysdatabases
SET status = 32768
WHERE name = 'yourDB'
8.Restart SQL Server (This is must, if it is not done SQL Server will through an error)

9.Execute this DBCC command to create the LDF file.make sure the Name of LDF file which you are giveing is same as deleted LDF file of Newly Created database.
DBCC TRACEON (3604)
DBCC REBUILD_LOG(bmpos,'D:\yourDB_Log.ldf')

DBCC accepts two parameters

1. parameter is database name and
2. parameter is physical path (where the MDF file is located) of the log file. (*Make sure the path is physical, if you specify the logical file name it will throw an error.)
10.Run the given stored procedure to reset the status of your database.
sp_CONFIGURE 'allow updates',0
RECONFIGURE WITH OVERRIDE
11.Do not forget to disable theallow update to system datatbase.
sp_CONFIGURE 'allow updates',0
RECONFIGURE WITH OVERRIDE
12.At last, update the status which you have noted in the 5th step.
UPDATE sysdatabases
SET status = 1073741840
WHERE name = 'yourDB'
Note : During steps 8, 9 , 10 you may encounter any errors if database is in use.
in this case you Set the database to single user.
sp_DBOPTION 'yourDB', 'single user','true'
Once the steps 8,9,10 are completed and database is already single user mode, then run this script to set it multiple users mode.
sp_DBOPTION 'yourDB', 'single user','false'
That's all, now database ready to use with multiple users mode. hopes help and save your time.


Have a nice day... 'N happy Coding :)

Saturday, January 22, 2011

Dynamically Adding Controls in ASP.NET

In my previous post i show Dynamically adding controls on grid with validation. I know this an old topic I have read the forums many readers asking about add controls dynamically in asp.net giving problems and also it not working properly with events. So I have decided write the snippet for you.


Implementation

Let’s create a simple page with a PlaceHolder to add control from code behind.

Html Code


<html xmlns="http://www.w3.org/1999/xhtml">
<head id="Head1" runat="server">
    <title>Dynamically Adding Controls in ASP.NET</title>
</head>
<body>
    <form id="form1" runat="server">
        <div>
            <asp:PlaceHolder ID="plMain" runat="server"></asp:PlaceHolder>
        </div>
    </form>
</body>
</html>



C# Code




protected override void OnPreInit(EventArgs e)
    {
        Button btn = new Button();
        btn.ID = "btnSave";
        btn.Text = "Click Me";
        btn.Click += new EventHandler(btn_Click);
        this.plMain.Controls.Add(btn);
        base.OnPreInit(e);
    }
    protected void Page_Load(object sender, EventArgs e)
    {
        // here only processing.
    }

    void btn_Click(object sender, EventArgs e)
    {
        Response.Write("<p>The Button has clicked</p>");

    }

Now the reason why some programmers getting error because they try to create controls(Button) on pageload event. After the button is added and when I click button make a post back, but unfortunately button was disappeared. The reason is when we are click button it make post back, so each post back there page load from top to bottom.

There is easy solution for this issue. You have to select a correct event to place the code to add control into page dynamically. The best and correct event is 
Page_Init.
Init Event:http://msdn.microsoft.com/en-us/library/ms178472.aspx

Have a nice day... 'N happy Coding :)

Sunday, January 9, 2011

setTimeout and clearTimeout javascript Example

 setTimeout returns a value which stores a reference to the timer. The timer can then be cleared using the clearTimeout function. This is done in the following example:

<script language="Javascript">

var timeout;

function timeout_trigger() {
document.getElementById('timeout_text').innerHTML = 'The timeout has been triggered';
}

function timeout_clear() {
clearTimeout(timeout);
document.getElementById('timeout_text').innerHTML = 'The timeout has been cleared';
}

function timeout_init() {
timeout = setTimeout('timeout_trigger()', 3000);
document.getElementById('timeout_text').innerHTML = 'The timeout has been started';
}

</script>

<div>
    <input type="button" value="test timeout" onclick="timeout_init()" />
    <input type="button" value="clear timeout" onclick="timeout_clear()" />
</div>
<div id="timeout_text"></div>

When timeout_init() is called, the timeout reference is stored in the "timeout" variable. The name of the variable can be whatever you want, but it needs to be in the global scope, hence the "var timeout;" declaration at the start of the code.
Clicking the "test timeout" button starts the timer and the "clear timeout" button clears the timeout at the end
Have a nice day... 'N happy Coding :)

Random hexadecimal Numbers

Hi ,
2day i'm showing u some creating random hexadecimal numbers
 Code:

                Random _random = new Random();
                int i = 0;
                string _randomValue = string.Empty;
                for (i = 0; i < 100; i++) // Set the count here
                {
                    _randomValue = _randomValue +" , "+ _random.Next().ToString("X");
                }
                lbl_ErrMsg.Text = _randomValue.ToString();




Have a nice day... 'N happy Coding :)

Friday, January 7, 2011

Reverse Of a string In c#

Hi, 
2day I'm showing a string in reverse
Code

                string _reverse = "Simplyasp.blogspot.com";
                char[] _printArray = _reverse.ToCharArray();
                Array.Reverse(_printArray);
                lbl_Message.ForeColor = System.Drawing.Color.Red;
                lbl_Message.Text = _reverse.ToString() + " Reverse : " +(new       string(_printArray))+"";

Result

          Simplyasp.blogspot.com 

Reverse : moc.topsgolb.psaylpmiS




Have a nice day... 'N happy Coding :)

Thursday, January 6, 2011

Maintaining error log

Here I am simplfying error log implementaiton.
To maintain error log its good to have log for each day for a better review .
so here we will create log file everyday , and when file already exist will append error entry in to it.
For that create one class and write following method....

C#
Add this 2 Namespace
using System.IO;

using System.Globalization;

and the Rest of game will be handled by this class

public static void WriteError(string errorMessage)
    {
        try
        {
            //Specify path where log file to be created
            string logfilePath = "~/Error/" + DateTime.Today.ToString("dd-mm-yy") + ".txt";
            if (!File.Exists(System.Web.HttpContext.Current.Server.MapPath(logfilePath)))
            {
                File.Create(System.Web.HttpContext.Current.Server.MapPath(logfilePath)).Close();
            }
            using (StreamWriter wrtr = File.AppendText(System.Web.HttpContext.Current.Server.MapPath(logfilePath)))
            {
                wrtr.WriteLine("\r\nLog Entry : ");
                wrtr.WriteLine("{0}", DateTime.Now.ToString(CultureInfo.InvariantCulture));
                string err = "Error in: " + System.Web.HttpContext.Current.Request.Url.ToString() +
                ". Error Message:" + errorMessage;
                wrtr.WriteLine(err);
                wrtr.WriteLine("__________________________");
                wrtr.Flush();
                wrtr.Close();
            }
        }
        catch (Exception ex)
        {
            WriteError(ex.Message);
        }
    }





Have a nice day... 'N happy Coding :)

Web Hosting and Domain

Hi,
Let me share few information regarding Web hosting and DNS.

Web Host -Means Server where our website resides.This always up and connected to internet to make our web site active.

Shared Hosting:- Most of the host provides Shared Hosting , as it is meaningless to use whole server for small website which does not have very heavy traffic or not a big application.
At that time on a on server more then one website is hosted and manged.shared hosting is widely used , it is very cost effective too.Shared hosting may not provide full access to server(it is depends upon service provider also).

Dedicated Server:- Dedicated Server means only one particuler website or particular user owns a server.Where Owner(Person who purchase Dedicated server from host ,yes your own pc also can be a dedicated server).Owner have full access of server ,freedom of installing new s/w ,uninstall s/w.

DNS:-Domain Name Server
As we all knows on back side web request is made through IPs.
DNS :- Map the IP(where our website hosted) and Domain Name (like www.google.com ).
As defination you can say 
DNS is the service which translates between Internet names and Internet addresses.
If you are working on a Windows machine, you can view your current IP address with the command WINIPCFG.EXE (IPCONFIG.EXE for Windows 2000/XP). On a UNIX machine, type nslookup along with a machine name (such as "nslookup www.howstuffworks.com") to display the IP address of the machine (use the command hostname to learn the name of your machine).

DNS is such a big thing so it can not be explained in a single post I will add more information about it.


Have a nice day... 'N happy Coding :)

Sunday, January 2, 2011

watermark image over image

hi friends,
in my previous post i shown watermark of text over image. 2day I'm showing image over image



using System;
using System.Drawing;
using System.Drawing.Imaging;

//Original Image that you want to watermark
Image image = System.Drawing.Image.FromFile(@"C:\way2sms.png");

//Watermark
Image logo = Image.FromFile(@"C:\Capture.png");

//Create graphics object of the Orignal image
Graphics g = System.Drawing.Graphics.FromImage(image);

//Create a blank bitmap object to which we will draw our transparent logo
Bitmap TransparentLogo = new Bitmap(logo.Width, logo.Height);

//Create a graphics object so that we can draw on the blank bitmap image object
Graphics TGraphics = Graphics.FromImage(TransparentLogo);

//An image is represenred as a 5X4 matrix
//the 3rd element of the 4th row represents the transparency
ColorMatrix ColorMatrix = new ColorMatrix();
ColorMatrix.Matrix33 = 0.50F ; //Transparency

//An ImageAttributes object is used to set all the alpha values.
//This is done by initializing a color matrix and setting the alpha scaling value in the matrix.
//The address of the color matrix is passed to the SetColorMatrix method
//The ImageAttributes object is passed to the DrawImage method
ImageAttributes ImgAttributes = new ImageAttributes();
ImgAttributes.SetColorMatrix(ColorMatrix, ColorMatrixFlag.Default, ColorAdjustType.Bitmap);
TGraphics.DrawImage(logo, new Rectangle(0, 0, TransparentLogo.Width, TransparentLogo.Height), 0, 0, TransparentLogo.Width, TransparentLogo.Height, GraphicsUnit.Pixel, ImgAttributes);

TGraphics.Dispose();

//Do Watermarking
g.DrawImage(TransparentLogo, (image.Width - logo.Width) / 2, (image.Height - logo.Height) / 2);

//Save Image
image.Save(@"C:\MyWatermakedImage.png", ImageFormat.Png);




Have a nice day... 'N happy Coding :)

Saturday, January 1, 2011

Welcome 2011

With a pray we can welcome 2011 
. Oh god, pls give us the strength and health to overcome all the troubles and Pls keep the world around me in peace.
i Wishing  wish u all Fantastic,wonderful, amazing new year






Have a nice day... 'N happy Coding :)