Monthly Archives: April 2012

Is jQuery Ajax?

You can do  of lot of things with jQuery like click ona button and it it creates new content for you. Click on another it and disppears itself. The question is “Is jQuery Ajax?”.

 

Ans. jQuery is not aJax but it is aJax like. An Ajax Application consists of a client,  webserver, and an asynchronous request between the client (which is the browser) and the Server. The Server runs script and it sends it response back to the client.

 

A jQuery does not have a server. It is simply JavaScript that does it work. jQuery is JavaScript library that has some powerfully functionally. It can bring you contents out of nowhere just like Ajax without using Ajax. That may fool some people jQuery is actually Ajax.

Q. So what are the limitations of jQuery?

A. jQuery is very powerful but it does not have a server side script. Basically you are the mercy of JavaScript. You can do a lot of powerful things but everything is done inside your script. Lets say you want to do some validation on the server for example verify username and login, that cannot be done by jQuery because jQuery does not have access to your server. It can only be done using Ajax because your Ajax Script is actually on the server and has access to everything that is available on the server, including the database.

SQL Interview Questions

Basic questions

Q.How do you query a database?

A. We use select statement against a table. We can choose the particular fields that we want or we can pull everything in the table using * for fields.

Q.You have student tables which has the enrollment student first name, last name and enrollment date. How do you pull the list of students who are were enrolled the last (most recently)

Q. How do you enter date in SQL Server 2008?

The general accepted form for data in SQL is YYYY-MM-DD. That is year first, followed by – then month then – than day. However depending on which country we are in, we can also use datatime in the format that the operating system understands. For exmaple we can enter

We may also use / instead of – when entering date. E.g

Q. Can you write syntax of join two tables A and B?

 

Q.You have two tables both contain similar data and the same number of fields? Can I find the difference between the two tables?

 

 

JOIN using LIKE in SQL

Q. Can I join tow tables using like (more flexible criteria) than exact match?

Ans. Yes

Table A and B

Result

Word to XML : Object reference not set to an instance of an object

Word to XML Mapping

You are working with Word. You are mapping a field to XML and you end up getting this error

Object reference not set to an instance of an object

Cure

The error can result if the field that you mapping to is underlined. Simply select the richedit text box (that you place from developer menu in Microsoft office 2007). Bring the cursor inside and remove any character that is there. Just leave the mapping only. Hopefully this issue will be resolved.

I had to go a long way to figure this out. I thought I would share.

BETWEEN DATES SQL Server 2008

When dealing with dates, remember there is not such field as date in SQL Server 2005/2008. There is datetime field.

For reference there is a date type in MySQL which I think is very useful.

There could be problems when you use between dates in SQL Server 2008. The problem comes because datetime has time information also and that give a new meaning when you are doing comparision.

Lets get the current date.

If I do

This is because when comparing dates, sql server 2008/2005 compares time information also. if the time information is 00:00:00, in that case it will print the date but that is not the case. Therefore it does not finds a match.

Using between with dates

Keep this information, if there is no time information, everything will be simple but if there is time information, it gives a new meaning to the day.

Using SQL BETWEEN in SQL SERVER 2008

In SQL sever 2008, when you use between the lower limit and the upper limit are inclusive in inclusive in the result.

Note the result. The above query will include record with id=3 but 2 and 4 also.

Output

BETWEEN DATES SQL Server 2008

The column ‘LOCK_ID’ was specified multiple times for ‘BB’.

SQL Server 2008

Error Message: The column ‘LOCK_ID’ was specified multiple times for ‘BB’.

Example:

select BB.LDC_ACCT_ID from
(
select * from STUDENTS S
JOIN RECORDS R
on S.STUDENT_ID = R.STUDENT_ID
) as TEMP

If you run this query in SQL SERVEr 2008, you will get the above error.

Reason

The problem is

select * from <-- this line

What is happening is (possibly), both students table and records table have the same field name. When you use * to put two fields with the same name in one table, you get this error. Note that the subquery runs fine by itself. But when you put it inside TEMP table, it causes the error.

Cure

select S.STUDENT_ID, …. from <-- this line

This way not duplicate fields are inserted in the TEMP table.

Using SVN Server on Mac LION OSX

On Windows we are familiar with Visual SVN (Server) and Tortoise SVN (Client), What are my options on Max OSX Lion/Tiger/Mountain Lion? Well Mac OSX Lion comes with SVN Server built in. That means you do not need to install anything for SVN Server. You can create repositories and commit changes right out of the box.

Svn Server Tutorial on Mac Lion

Start Terminal. Go the the directory where you want to create repository. Lets say we can to create Repository in Sites folder. We would issue the following commands

Now the second step is to import the files for the first time. Issue the following command

First time Import files

Check out the Repository

Checkout is important step so that you must do. Basically you are creation a working copy when you checkout. You can check out as many copies as you want. But obviously you should check out only once on a PC unless you want to do some experiments

svnadmin create /Repo_Master/Sketch_svn

The create command creates only the last directory in the specified path; in this command, for example, the /Repo_Master directory must already exist.

In Step 4, you import your project from the temporary structure into the new repository and place it under Subversion source control. The following command accomplishes this:

svn import /Users/myUserName/Projects/Sketch_tmp \
file:///Users/myUserName/Repositories/Sketch_svn -m “Initial import”

Regular Expressions in Visual Studio 2010

Regular Expressions is a power tool that is used in Web Application for verifying valid emails address, password strength among other things. If you have not worked in Web Development environment, you are missing on this powerful tool.

Interesting regular expressions search is available in Visual Studio. Although Visual Studio’s regular expression does not comply with the regular expression implemented in other languages like PHP, Ruby etc, they still can be used in very powerful way.

Case studies

Putting “,” at the end of a link

Example you have a scenario where you just copied the integer data as follows

(assume there are a lot of them)

You want to put a , at the end of each line, who do you do it? You can do it using regular expression search and replacement.

Bring in the Search Dialog by Ctrl+F. Screen shot is attached.

Regular Expression Search in Visual Studio

Note that the last check box Use “Regular expression” is checked. Now you can type a regular expression in the find field and can perform your search. As I have said Visual Studio 2010 does not use the same Reg Expression as in JavaScript and other languages, the good thing is, some help is already available. Click on the right arrow icon next to “Find What:” text box. It shows the reg expression option available to you.

In this case choose the $ End of Line. Now when you click find, it will stop at the end of every line.

Next click the “Quick Replace” tab. And enter “,” in the replace kewyord (without the quotes). And click replace.

You may want to hit replace each time you want to insert a comma. Doing replace all will put , at the end of every line which is not desirable. You can do that with a more complex regular expression. But this is just a quick toturial.

Cannot cannot to SQL Server database but can connect to Server

Problem

You can connect to SQL Server 2005/2008 instance in SQL Server Management Studio (SSMS). It list all the databases but when you try to create a query or right click on a database and select properites, you see this error

“A connection was successfully established with the server, but then an error occurred during the login process. (Provider: Shared Memory Provider, error:0 – No process is on the other end of the pipe.) (Microsoft SQL Server, Error:233)”

Solution

You might want to look at the log file created by SQL Server. They are located in

C:\Program Files\Microsoft SQL Server\MSSQL.2\MSSQL\LOG

Look at the ERRORLOG file (using notepad++ or just plain notepad). Somewhere in the end it might say

Could not connect because the maximum number of ‘2’ user connections has already been reached. The system administrator can use sp_configure to increase the maximum value. The connection has been closed

If this is the error in the log file, you might want to run this code as it is to cure the problem. Make sure to restart the server after. Note the original code was used from this site

sp_configure ‘show advanced options’, 1;

go

reconfigure

go

sp_configure ‘user connections’, 0

go

reconfigure

go