SQL Error : Column already has a DEFAULT bound to it

The Problem

Today I was testing an application that using SQL server 2008 DB. I got an error in my application says that a table is missing in the DB. I decided to generate CREATE SQL script from other DB that has the missing table and execute in this target DB.

While executing the CREATE SQL script I got these errors:

There is already an object named 'SANotify' in the database.

Msg xxx, Level xx, State x, Procedure sp_addextendedproperty, Line xx
Property cannot be added. Property ... already exists for ...

Msg xxx, Level xx, State x, Line x
 Column already has a DEFAULT bound to it.

Msg xxx, Level xx, State x, Line x
 Could not create constraint. See previous errors.

Troubleshoot and Solution

To trouble shoot this error, I decided first to list all constrains in this table, for that I found this helpful post. In my table, all constrains names starts with DF_SANotify so to get all these constrains I executed the following SQL:

SELECT name,OBJECT_NAME(parent_object_id) AS TableName, OBJECT_NAME(object_id) AS ConstraintName
FROM sys.objects
WHERE type_desc LIKE '%CONSTRAINT' and name like 'DF_SANotify_%' order by name

and I got this result:

As you can see .. I found that the constrains are really exist because the table SANotify I am trying to create is already exist but renamed to XXSANotify.

So I deleted the XX table, ran the SQL script and it is executed successful. Instead of deleting the XXSANotify I could just rename it back to SANotify.

Text Direction Button Disappeared From Gmail Message Editor

In last two days I found that the text directions buttons disappeared from gmail message editor. Today a fried told me that there is an option for that in Gmail settings.

For now me editor is like this:

Gmail Editor without Text Direction Buttons

 

So To add the text Direction button to the tools box of message editor simply do this:

Open Gmail options menu and select settings:

Gmail Options Menu

in the settings page, see the marked two options of text direction:

Gmail Settings - Text Directon

Select the second option to enable the Direction Buttons .. then save the settings.

 

Now the text direction buttons will appear and message editor will look like:

Gmail Message Editor

 

Thats it

Clear Saved Login

Sometime I want to access a network shared folder from normal user PC and when I call the computer using \\computer-name it ask me to type the credentials to access the destination computer shared folder, by mistake I type the administrator account Username and Password and even I select “Remember my credentials”

Then I needed to clear this connection session to log-in back with the correct user account not the administrator. So I found that I can use this command:

rundll32.exe keymgr.dll, KRShowKeyMgr

it will show you all active session to the computer then you can manage them (Add/Edit/Delete)

also you can use this command:

control keymgr.dll

it will open this page:

I tried both commands in windows 7 it works, I didn’t try on windows XP, but I guess at least first one will work.

References:

http://www.sakana.fr/blog/2007/02/27/windows-clear-saved-windows-networking-passwords/

http://www.microsoft.com/resources/documentation/windows/xp/all/proddocs/en-us/key_howto_delete.mspx?mfr=true

http://www.faqforge.com/windows/how-delete-saved-passwords-for-network-drives-in-windows/

“Licensing for this product has expired” Adobe CS4 Applications

Licensing for this product has expired

If you are getting this error message when you start your Adobe CS4 application like Dreamweaver. And you want to tray another serial but not able to because application is not starting but only showing this message “Licensing for this product has expired”

Then.. Go to C:\Program Files\Common Files\Adobe\Adobe PCD\cache
and rename or delete the file “cache.DB”

Try to start the application again .. it should start .. then you will get a chance to enter your correct serial number.

check this link for more details.

 

BTW .. I am talking about Windows OS .. MAC people said another solution work for them, that is to do the following:

  1. Change your DATE to a previous (those working days)
  2. Re-open Program (It will, now)
  3. On the menus-> HELP->DEACTIVATE and close program
  4. Change DATE to present
  5. Open program again, it will ask for a new KEY, enter a new key

 

 

CF Function to Clean MS Word HTML Mess

I was have a trouble with our clients using our CMS system, that is, they used to copy their text from MS Word and paste into the CMS editor directly. If you already know, that will make trouble and create a lot of unwanted HTML and XML tags  (as I see on internet people call it MS Word Mess). I Used to paste the MS Word stuff into the design area of Dreamweaver because it gives me a control and options to clean unwanted things while pasting. you can find that options by :

Click in Design area in Dreamweaver > open Edit meun and select “Paste Special…

Then select the cleaning option you want.  Still after that you may need to do some RegExp replacements.

But as you know you can’t ask your clients to use Dreamweaver to clean MS Word mess.

Clean MSWord Mess Function

I decided to create a ColdFusion Function to replace all unwanted HTML and XML Tags from MS Word pasted text. Here is the function:

<cffunction name="cleanWordMess" output="no" returntype="string">
 <cfargument name="inString" default="">
 <!--- if nothing passed , return empty string --->
 <cfif Not Len(Trim(arguments.inString))><cfreturn "" /></cfif>
 <!--- create a tmporary variable to cold the passed text --->
 <cfset local.text = arguments.inString />
 <!--- remove the HTML comments --->
 <cfset local.text = REReplace(local.text, "<!--.*-->", "", "ALL") />
 <!--- remove most of the unwanted HTML attributes with their values --->
 <cfset local.text = REReplace(local.text, "[ ]+(style|align|valign|dir|class|id|lang|width|height|nowrap)=""[^""]*""", "", "ALL") />
 <!--- clean extra spaces & tabs --->
 <cfset local.text = REReplace(local.text, "\s{2,}", " ", "ALL") />
 <!--- remove exra spaces between tags --->
 <cfset local.text = REReplace(local.text, ">\s{1,}<", "><", "ALL") />
 <!--- remove any &nbsp; spaces between tags --->
 <cfset local.text = REReplace(local.text, ">&nbsp;<", "><", "ALL") />
 <!--- remove empty <b> empty tags --->
 <cfset local.text = REReplace(local.text, "<b></b>", "", "ALL") />
 <!--- remove empty <p> empty tags --->
 <cfset local.text = REReplace(local.text, "<p></p>", "", "ALL") />
 <!--- Remove all unwanted tags opening and closing --->
 <cfset local.text = REReplace(local.text, "</?(span|div|o:p|p)>", "", "ALL") />
 <!--- remove and repetation of &nbsp; and make it one only --->
 <cfset local.text = REReplace(local.text, "(&nbsp;){2,}", "&nbsp;", "ALL") />
 <cfreturn local.text />
</cffunction>

Of course the sequence of replacement code is very important. I think you know how to call this function .. or do I need to explain!  🙂

Feel free to use the function personally, commercially .. whatever.

Clean Truncated HTML Tags

While showing list of articles in a website usually you will see a short description with each article. As a programmer, sometimes I have to gather some number of words or characters from the article body text and show it as a short description.

When I get this number of letters from the body say by using CAST in SQL, as example:

SELECT TOP 10 ID, Title, CAST (Body AS NVARCHAR(100)) AS shortDescription FROM Articles

Assume I in one of the records I has this original value in the body field:

While comparing two entities, we tend to see both of them as competitors and <a href=http://www.somesite.com&#8221; target=“blank”>consequently comparing</a> them to find a winner.

After running the SQL I will get:

While comparing two entities, we tend to see both of them as competitors and <a href=http://www.so

As you can see the result has invalid/corrupted HTML which definitely will effect the page display if I output it as it is. Say I decided to strip out the HTML tags from the description before outputing it with this code:

<cfset text = REReplace(text, "<[^>]*>", "", "ALL")>

It will not do any thing because there is no correct tags in this string, so it will not replace any thing. For that you need to replace any unclosed tags, it could be ‘<blockquote class=”somting”‘ of even ‘<blockquo’. Hence, I use this line of code to clean any truncated HTML tags:

<cfset text = REReplace(text, "<[^>]*$", "", "ALL")>

Mostly I use the both replacement above.

 

Show & Hide Loading/Processing Indicator in iPhone App

To show the loading or processing indicator in your iPhone Application just add this line:

[UIApplication sharedApplication].networkActivityIndicatorVisible = YES;

and to hide the loading indicator use the same with changing  YES to NO, like this:

[UIApplication sharedApplication].networkActivityIndicatorVisible = NO;

You will need to use this feature normally when you are processing something in background using thread(I will try to write about thread later Inshallah) and you want user to know that something is going on in background.

thats it;

My First iPhone Application – simple Book Library

Last week I attended a course on iPhone Application Development – Beginners

During the course we built a simple book library application.  This application has 4 different pages only:

  1. Home Page : listing only two items (Programming and My Books)
  2. List of Books : if you clicked on any item on home page will show the list of books of selected item
  3. Book Details : if you clicked on any book in the second page you will see the book details
  4. Add Book Form : if you where in “My Books” and you clicked on “+” button at the top right you will go to add book form

I am not on my Mac right now, otherwise I will place some screen shot of the application here. Any way, you can download the application from here:

http://www.4shared.com/file/F1pKSCWa/day42.html

downoad -> extract -> open -> build -> run 🙂

Using JSON in iPhone App Developlment

I am attending an iPhonh Application Development course these weeks. And in the next week we are going to deal with HTTP to gather XML data. As I know, and as instructor said, iPhone has built-in libraries to read and parse XML but there is nothing for JSON.

I decided to search and immediately I got this very useful post by Dan Grigsby on an interesting website:

Tutorial: JSON Over HTTP On The iPhon

http://mobileorchard.com/tutorial-json-over-http-on-the-iphone/

He explain “JSON and how to use” in very nice clear way, also there you will find a free library for JSON to use .. don’t miss it.

Run SQL script file from Dos command prompt

Note: The solution is at the bottom of the post, you can jump there directly if you don’t to read my silly story 😉

I have MS SQL Server 2008 R2 RTM – Express with Advanced Services. At work I got SQL script file from a client contains a table creating and record insertion scripts.

I tried to run SQL script file from SQL Management studio  but the file size was huge. So I got this error:

SQL2008RunScript

TITLE: Microsoft SQL Server Management Studio
——————————
Cannot execute script.
——————————
ADDITIONAL INFORMATION:
Insufficient memory to continue the execution of the program. (mscorlib)
——————————
BUTTONS:
OK
——————————

Then I decided to run the SQL script file from DOS command prompt as SQL server is supporting it.

I used this command:

osql -S <SQL Server IP/Name> -d <DB Name> -E -i <sql script file path>

where:

-S put your SQL server IP or Name
-d type your database name
-E the means trusted connect .. when you use this you don’t need to use -U & -P

in my case the command was:

osql -S dbserver -d SMSPortal -E -i c:\tmp\GroupContact.sql

Unfortunately, when I run the command I got another error that is:

[ODBC Driver Manager] Data source name not found and no default driver specified

after searching and digging I found that there are two files with name “osql.exe”. One in this folder:

C:\Program Files\Microsoft SQL Server\90\Tools\Binn\OSQL.EXE

and the second is in this folder:

C:\Program Files\Microsoft SQL Server\100\Tools\Binn\OSQL.EXE

But how to know which one is used when I run the command. While I am able to run the command from any place in command prompt that means the folder of one of two above files is added the PATH system variable. To check that, from DOS I run:

c:\>path

and I got this:

PATH=C:\WINDOWS\system32;C:\WINDOWS;C:\WINDOWS\System32\Wbem;C:\Program Files\Microsoft SQL Server\90\Tools\binn\;c:\Program Files\Microsoft SQL Server\100\Tools\Binn\;

of course I got lengthy result but I truncated and removed unwanted stuff. Any way, as you can see both folders are added to the path. So I dont know which one is used when I run the command “osql …”. the best way is the navigate to the path of first folder and the command from there and navigate to the second folder and also run the file from there.

The Solution:

the file:

C:\Program Files\Microsoft SQL Server\90\Tools\Binn\OSQL.EXE

giving that same error:

[ODBC Driver Manager] Data source name not found and no default driver specified

While file:

C:\Program Files\Microsoft SQL Server\100\Tools\Binn\OSQL.EXE

Working fine and solved the problem.

So the command was like this:

C:\Program Files\Microsoft SQL Server\100\Tools\Binn>osql.exe -E -d SMSPortal -i c:\tmp\GroupContact.sql

with ruining this command I was able to run the script huge file successfully 🙂