Jan 15 2010

To reset auto increment SQL SERVER

Category: SQLLatif @ 16:52

Hi,

If you want to reset auto increment field, use the code below.

 DBCC CHECKIDENT('TableName', RESEED, 2) ;

See you soon...

 

Tags:

Oct 21 2009

Short way of converting file lines to Array by regex. Also pay attention to usage of HashSet

Category: C#Latif @ 23:57

 

Hi again,

 

You can see the code below that simply how to convert txt file lines to array by means of regex. Also give attention to usage of HashSet.

 

Before running the code, create a txt file named myTxtFile.txt.

 

Code with comment:

 

using System;

using System.Collections.Generic;

using System.IO;

using System.Text.RegularExpressions;

 

namespace File2Array

{

    class Program

    {

        //Convert file lines to Array

        public static string[] FileLines2Array(string filename)

        {

            string[] returnArray;

            using (TextReader textReader = new StreamReader(new FileStream(filename, FileMode.Open)))

            {

                Regex regexForSplit = new Regex(Environment.NewLine);

                returnArray = regexForSplit.Split(textReader.ReadToEnd());

            }

            return returnArray;

        }

 

        //Convert file lines to HashSet

        public static HashSet<string> FileLines2HashSet(string filename)

        {

            HashSet<string> array2HashSet = new HashSet<string>();

            foreach (var item in FileLines2Array(filename))

            {

                array2HashSet.Add(item);

            }

            return array2HashSet;

        }

 

 

        static void Main(string[] args)

        {

            Console.WriteLine("Convert file lines to array");

            string[] testArray = FileLines2Array("myTxtFile.txt");

            foreach (var item in testArray)

            {

                Console.WriteLine(item);

            }

 

            Console.WriteLine("Delete duplicate lines automatically if any. Also see usage of HashSet");

            HashSet<string> testHashSet = FileLines2HashSet("myTxtFile.txt");

            foreach (var item in testHashSet)

            {

                Console.WriteLine(item);

            }

 

            Console.ReadKey(true);

        }

    }

}

 

 

See you soon...

Tags: , , ,

Sep 12 2009

Prevent URL Rewriting of Requests for ASP.NET-WebResources.axd

Category: Ajax | ASP.NETLatif @ 14:50

Hi again,

 WebResources.axd is created by ASP.NET for performing AJAX processes in the page. İn Addition, there is no such file on the web server due to the fact that ASP.NET produce the content dynamically when WebResources.axd is requested.

 

If you want to see the content of WebResources.axd, you have to run it on browser. Script path is in the page source code like below,

 

<script src="/WebResource.axd?d=7OCAQ3R3VOQC0D4ciLQ5OCpSc8_wxlQ0C-KYhGZ-_ag1&amp;t=633566872339565967" type="text/javascript"></script>

 

İf you are using Url Rewring, URL rewrite rule may accidentally make the requests to WebResources.axd and this will break your application.

 

Anyway, in order to prevent URL Rewriting of Requests for ASP.NET Web Resources(.axd) and other type of files such as .xml,.js,.css , you should add rule to web.config.

<rewriter>

     <rewrite url="^(/.+(\.gif|\.png|\.jpg|\.ico|\.xml|\.pdf|\.axd|\.css|\.js)(\?.+)?)$" to="$1" processing="stop" />

     <rewrite url="/([0-9]{6})(.*)/(.*)-(.*)" to="~/Detail.aspx?aid=$1" />

 </rewriter>

 

The problem can be easily prevented by this rule.

 

Have a good time...

Tags:

Aug 26 2009

How to Capitalize the First Letter of Each Words in a string in C#

Category: C#Latif @ 16:24

Hi,

İf you wonder as to how to capitalize simply first letter of each words in a string, you can use ToTitleCase.

Check the sample below,

using System;

using System.Globalization;

 

namespace ToTitleCaseApp

{

    class Program

    {

        static void Main(string[] args)

        {

            string capitalizedFirstLetter = CultureInfo.CurrentCulture.TextInfo.ToTitleCase("shoot for the moon. even if you miss, you'll land among the stars.");

            Console.WriteLine(capitalizedFirstLetter);

            Console.ReadKey();

        }

    }

}

 

Result :

Shoot For The Moon. Even If You Miss, You'll Land Among The Stars.

I think, it is a handy method.

have a good time!

Tags: ,

Aug 14 2009

ASP.Net AJAX Not Working (Full page postback)

Category: Ajax | ASP.NETLatif @ 15:45

 Hi,

After carrying my web application to windows server 2003 R2 from windows  XP - IIS 5.1,  I have encountered a ASP.Net AJAX issue that my page is performing a full page postpage instead of a partial page postback of the expected AJAX page elements.

        I have searched everywhere, and this is the only solution I can find.  I just stumbled upon this page below and I applied what it is saying.  I would like to thank to Neil kilbride for sharing this solution with us.

http://neilkilbride.blogspot.com/2008/01/aspnet-ajax-not-working-full-page.html

Solution :

I just added to my web.config file following code to solve the problem.

   <system.web>

        <xhtmlConformance mode="Transitional" />

  </system.web>

 And also he says thatIf you are having ASP.Net AJAX issues I recommend removing the <xhtmlConformance> section from your web.config file or perhaps set it to Transitional or Strict.

 

Tags: ,

Jul 27 2009

How can I use ampersand in AppSettings value - app config file

Category: ASP.NETLatif @ 00:28

Hi,

If you want to put an & (ampersand) character into the value attribute of a key in the appSettings part of the XML .config file(web.config, app.config etc.)

Let's say, you have param like following, (The error will occur if you use like this)

   <appSettings>

    <add key="MyUrl" value="http://localhost:8080/mysite/summarize?name=testPDF&format=pdf"  />

  </appSettings>

Solution : 

   <appSettings>

    <add key="MyUrl" value="http://localhost:8080/mysite/summarize?name=testPDF&amp;format=pdf"  />

  </appSettings>

use &amp; instead of &

Cause :

It is because of XML rules that the & character is the token for beginning of a reference. For more information http://www.w3schools.com/xml/xml_cdata.asp

 tot ziens...

 

Tags: ,

Jul 14 2009

IsPostBack was always false after installing .NET Framework 3.5 SP1

Category: .Net frameworksLatif @ 02:19

Hi,

 After installing .NET 3.5 SP1, I realized some problems on my old project which has written on framework 2.0.

 My observations/symptoms on the project-login form:

  • IsPostBack was always false
  • İmagebutton click event not firing
  • I could not login the system

     After 2 days searching  ,luckily I stumbled upon following page. Thanks god :) http://blogs.msdn.com/tess/archive/2009/04/14/validation-of-viewstate-mac-failed-after-installing-net-3-5-sp1.aspx?CommentPosted=true#commentmessage

 

 Cause:

 There was a form tag in the Login.aspx. Pay attention to action="Default.aspx" (this was the problem)

<form id="form1" method="post" action="Default.aspx" runat="server">

 This problem may occur if your page(in this case Login.aspx) and  form action property(Default.aspx) are different.

 Reason :

      This occurs after installing SP1 for .NET 3.5 is because prior to this service pack, the action property was ignored.  Now that it is no longer ignored.It will work properly. I mean, this is not a bug, it’s a feature...

 Solution:

       Remove the form-action property or change it to post correct page(in this case Login.aspx).

 References :

 http://blogs.iis.net/webtopics/archive/2009/05/13/httpexception-due-to-invalid-viewstate-after-installing-net-framework-3-5-sp1.aspx

 

http://blogs.msdn.com/tess/archive/2009/04/14/validation-of-viewstate-mac-failed-after-installing-net-3-5-sp1.aspx?CommentPosted=true#commentmessage

See you soon....

 

Tags:

Jul 11 2009

Choosing between ADO.NET Entity Framework and LINQ to SQL

Category: Entity framework | LINQLatif @ 17:55

Hi,

       I just would like to share the information I have found from Wriju's BLOG. I want to copy and paste here to share with you. You can find some part of his observation about topic below.

Why I should use Entity Framework?

Ø       It simplifies the data access and allows me to create conceptual model required for my business.

Ø       EF allows you to handle Many to Many relationship without extra join.

Ø       Map related tables into single entity to reduce code complexity.

Ø       Strong inheritance supports for (Table per hierarchy, subclass and concrete type)

Ø       Consolidation for complex object is very easy.

Ø       It has powerful query mechanism through EntitySQL. For them who do not like LINQ you can use EntityClient provider with EntitySQL.

Ø       You can expose your modeled data through ADO.NET Data Services (Astoria).

Ø       Database independent and based on standard ADO.NET Providers.

Ø       There are many third party providers currently available.

o        Devart offers provider for Oracle, MySQL and PostgreSQL

o        Phoenix Software Solution offers EF provider for SQLite.

o        Npgsql offers another provider for PostgreSQL.   

o        OpenLink Software offers a very wide range of support for Oracle (versions 7.x to 11.x), Microsoft SQL Server (6.x to 2005), IBM DB2 , Sybase (4.2 to 12.x+), IBM Informix (5.x to 11.x), Ingres (6.4 to 9.x), Progress (7.x to 10.x), MySQL, PostgreSQL, and Firebird 

o        Sybase SQL Anywhere provides support for SQL Anywhere.

o        IBM natively supports databases like DB2, Informix and U2.

Ø       <TODO: will add few more as and when come across>

 

Closing

At the end of the story I still feel good about LINQ to SQL when it comes to smaller applications with less complexity. Entity Framework is capable of handling large enterprise applications and will have more power in v2 (in .NET 4.0). So if you are targeting your application for multiple databases the L2S is not the right choice for you.

My vote is for ADO.NET Entity Framework. You will enjoy with the conceptual model and Astoria.  

Reference: http://blogs.msdn.com/wriju/archive/2009/03/08/choosing-between-ado-net-entity-framework-and-linq-to-entity.aspx?CommentPosted=true#commentmessage

Till later..

Tags: ,

Jul 11 2009

Removing Entity in Designer leaves references in XML - missing delete functionality in ADO.NET Entity Data Model Designer

Category: Entity frameworkLatif @ 15:07

Hi,

         When I deleted table(entity) on the designer(edmx), I have found that all the reference about entity ,I have deleted, in XML file remain. And also we cannot add same entity to the designer without doing workaround below,

WORKAROUND:

         We have to delete all the references by hand. Only by this workaround(I cannot say it is a solution), we will be able to add same entity to the designer again.

Then I thought that the ADO.NET Entity Data Model Designer is still in its infancy. it is really big missing feature so I hope Microsoft will repair this big issue in a Hotfix at the earliest.

And I have found some discussions on internet and one of them is :

 http://social.msdn.microsoft.com/forums/en-US/adodotnetentityframework/thread/041aee9a-3947-47bc-9fd0-7272b1dffb7e/ 

But I could not see any tangible solution.

See you again..

 

Tags: ,

Jul 10 2009

Cannot start SQL Server service + SQL Server 2005 Error 3417

Category: SQL Server 2005Latif @ 22:57

Hi,

When I try to start the Sql Server (MSSQLSERVER) or  Sql Server (SQLEXPRESS) services, get the following error :

Windows could not start the SQL Server (MSSQLSERVER) on Local Computer. For more information, review the System Event Log. If this is a non-Microsoft service, contact the service vendor, and refer to service-specific error code 3417.

After that, I looked at eventvwr. This is the error.

The file "C:\Program Files\Microsoft SQL Server\MSSQL.1\MSSQL\DATA\modellog.ldf" is compressed but does not reside in a read-only database or filegroup. The file must be decompressed.

SOLUTION :

Go to the folder C:\Program Files\Microsoft SQL Server\MSSQL.1\MSSQL\DATA\ and select all the files

and right click advanced, uncheck, “Compress contents to save disk space”.

That`s it,piece of cake. Now you can start the services. Try it.

See you...

 

Tags: