Wednesday, July 10, 2013

Steps to Migrate MS Access 2007 Database to SQL Server 2008 using Upsizing Wizzard

-          Install SQL server 2008 on the database server with the default settings.
-          Check if installed correctly by using SQL Server Management Tools.
-          Open SQL Server Configuration Manager, and go to SQL Server Network Configuration, click on Protocol for MSSQLSERVER and enable TCP/IP protocol. Check IP address with port 1433 (default port for SQL server).
-          Open SQL Server Management tools and connect to the server.
-          Right click server name and click properties.
-          Go to Security tap and enable SQL Server and Windows Authentication Mode found on the right pane. Click ok
-          Still on the SQL Server Management tools open Security-Logins at the left pane.
-          Right click Logins and click add new Login.
-          Type Login Name: wie_admin.
-          Chose SQL Server Authentication and type password for it.
-          Uncheck enforce password policy and click ok.
-          Open Logins and right click the user you have just created (wie_admin) and chose properties.
-          Go to Roles and check the following roles for this user: Dbcreator, public, serveradmin, and sysadmin.
-          Be sure that you enable telenet client service on the server.
-          Test the telenet on the server locally by write command:
telnet 10.242.25.231 1433.
-          If telnet connection is successful then you are now able to connect to the SQL server from any device.
-          On the Web server create new txt file on the desktop and rename it to SQL_TestConnection.Udl.
-          Right click the udl file and click properties.
-          On the connection tab, enter the server IP, chose enter specific username and password, select master database and click test connection.
-          If the connection is successful then you are now able to connect to the SQL server from remote server.
-          Now it’s time to migrate the Access Database to the SQL server.
-          Open the mdb access file using MS Access 2007.
-          Go to Database tools pane and click SQL server.
-          Chose create new Database, and click next.
-          Enter the IP of the server and remove check from Trusted Connection so that you can enter the SQL authentication username and password (wie_admin), click next.
-          Chose the tables you want to migrate, click next.
-          Keep the default selection on how you want to transfer your tables and data, but change the timestamp settings to NEVER, click next.
-          Chose No programs needed and click next then finish.
Process will start and you can progress how tables are transferred.

Wednesday, September 19, 2012

Building your own Captcha


Capatcha is used in web forms, or forms authentication in order to apply a challenge-response to ensure that the website is dealing with human response. This means that the website is protected against brute force attack codes.
Google uses captcha in its own way (repcatcha) which could be downloaded and integrated into your code (.Net, or Php, visit: http://www.captcha.net/ for more info). Sometimes recaptcha connection doesn’t work into your site for any reason which we will not deal with it here. What are we going to talk about in this blog is that you still can write your own Captcha and use it anywhere you want. That’s what I want to share with you on my blog.
For people who will continue reading this blog, the code used is in .Net platform using C#, this doesn’t mean that you are restricted to use it only in .Net. the criteria is the same in almost all other languages.

Let’s start:
I will summarize the steps here and then enter in details.
1.      Create the web service responsible of generating the captcha image upon specific random string.
2.      Integrate the web service above in your code (through web reference and wsdl file).
3.      Write down the handler responsible of converting the byte[] (comes from web service) to a real image used in your code.
4.      Write down your code that will use the above web service and the handler.
Now let us enter into the details.



Captcha Web Service:
1.       Open a new project in visual studio, and make a new website. Add new item to the website type of web service (.asmx file) named captcha_gen.asmx, by default the code behind will be stored in the App_Code folder in a file name captcha_gen.cs, open the cs file and add the following code into it:


 [WebMethod]
    public byte[] GenCaptchaImg(string CaptchaStr)
    {
        //create Empty Img and new font
        Bitmap objBmp = new Bitmap(100, 25); //100: width, 25 height

        Graphics objGraphics = Graphics.FromImage(objBmp);
        objGraphics.SmoothingMode = SmoothingMode.AntiAlias;
        objGraphics.Clear(Color.Gray);
        objGraphics.TextRenderingHint = TextRenderingHint.AntiAlias;

        Font objFont = new Font("Verdana", 10, System.Drawing.FontStyle.Bold);

        //generate Captcha string
        string strCaptcha = string.Empty;
        strCaptcha = CaptchaStr;  //"334Aw2eQ" for example

        //Write Captcha string to the img and then generate byte[].
        objGraphics.DrawString(strCaptcha, objFont, Brushes.White, 3, 3);
        MemoryStream ms = new MemoryStream();
        objBmp.Save(ms, ImageFormat.Png);

        byte[] bmpBytes = ms.GetBuffer();
        return bmpBytes;
    }

This web method simply gets a string of characters or numbers (a random combination) and generates a byte[] array which will be later the image.
Web Service Integration
Now it’s time to build your website to use recaptcha, the following steps depend on this project. To start, open visual studio and create a new website. Then add a (Web Reference) to your website and enter the link to your web service built before. For local use enter (http://localhost/my_webservices/captcha_gen.asmx?wsdl ) this is the wsdl file of your service, then chose the web service to use, this is off course  (captcha_gen) service.
In the default.aspx.cs file in your website and at page_load event  write the following code:


 protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            string myStrCaptcha = StringGenerator();
            Session["just_captcha"] = myStrCaptcha;
            //define web reference and use it.
            myWebService.captcha_gen x = new myWebService.captcha_gen();
            byte[] bmpBytes = x.GenCaptchaImg(myStrCaptcha);
            HttpContext.Current.Session["ImgCaptcha"] = bmpBytes;
           
        }

    }
protected string StringGenerator()
    {
        StringBuilder builderStr = new StringBuilder();
        char ch;
        Random random = new Random((int)DateTime.Now.Ticks);
        for (int i = 0; i < 8; i++)
        {
            ch = Convert.ToChar(Convert.ToInt32(Math.Floor(26 * random.NextDouble() + 65)));
            builderStr.Append(ch);
        }
        return builderStr.ToString();
    }

The code above simply generate a random 8 characters string using StringGenerator() method, this method generate random 8 upper case characters and return a string of them, here you are free to build any random string generator you want. Then the code continues to call the web service (captcha_gen) which we referenced before by creating an object from it named (x), x object will call the method in the web service responsible for creating a byte[] array from the string parameter. And finally add the generated bmpBytes array to a session called ImgCaptcha to be used in the handler.
Generic Handler
In your website you are building add a generic handler to it named: ImgHandler.ashx, this handler will receive the byte[] array from the session named ImgCaptcha and then then return a png image. This handler will be referenced in an asp:image with ImageUrl=”ImgHandler.ashx” in the file default.aspx in your website. The following is the code of the handler:





 public class ImgHandler : IHttpHandler, System.Web.SessionState.IRequiresSessionState {
   
    public void ProcessRequest (HttpContext context)
    {
        //context.Response.OutputStream.Write(bmpBytes, 0, bmpBytes.Length);
        //context.Response.ContentType = "image/jpeg";
        if (context.Session["ImgCaptcha"] != null)
        {
            context.Response.ContentType = "image/png";
            byte[] image = (byte[])(context.Session["ImgCaptcha"]);
            context.Response.BinaryWrite(image);
        }
        else
        {
            context.Response.ContentType = "text/html";
            context.Response.Write("Hello World");
        }
        //context.Response.Write(HttpRuntime.Cache["img"]);
        //context.Response.BinaryWrite(imgBytes);
        //context.Response.Write("Hello World");
    }

    public bool IsReusable {
        get {
            return false;
        }
}


In this code I want to focus on an important point which some may ignore, notice how we build the class ImgHandler which inherits from IHttpHandler by default, we also add another class called IRequiresSessionState. Without this class all the sessions of the website will be null, so you have to add it in order to get the value of the session (ImgCaptcha). The hander simply read the session value and generate a response from it by writing a Binary byte[] array.

Thats all guys, if you have any questions please post me, and i will try my best to answer you.

Friday, July 29, 2011

Using DatePicker in .Net

To use datepicker in .net page
1. Attach the following links and scripts to your page:


2. Add The following code into script tags.


3. Add the following code into your form:


4. modify the CSS File of the JQuery UI

The result is:

Resize JQuery UI DatePicker

Hello Programmers,
sometimes its useful to use on the shelf components in your code, but the challenge rises when you want to customize your used objects.
One of the reused components is the JQuery UI datepicker, which you can view its documentation on datepicker by JQuery UI.
The link provides you with alot of options and choises to be customized. But what about resizing datepicker???

well, i have tried alot of things to resize datepicker. and finally came with this solution that i wanna share with you:
one of the files you must use is the: jquery-ui-1.8.14.custom.css, where all themes and styles goes on, at the end of the file simply add the following lines of code:

@import "ui.base.css";

@import "ui.theme.css";
div.ui-datepicker { font-size: 62.5%; }
 
save the file and see you resized datepicker on the web.
Some people said that you can add a style to your page and add the style:
div.ui.datepicker
{
    font-size:10px;
}
but it didnt work for me.
 
hope this was useful for you
 
 
enjoy.
Jalal Hijazi

Wednesday, July 6, 2011

First Post: Open Data Protocol

Hello, this is my first post on blogger, i think it worth to write something i have learned today which is Open Data Protocol. a new technology (SOUP + REST) to deal with web services. Its really convince you to use it because its simply can fetch your data from any source using URL query... is it cool.
Anyway... i will learn more about it and i will share my knowledge with others.
I will start with this link: Open Data Protocol with ASP.Net.