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.

Advertisements

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 🙂

Good Android Resources I Use

Of course Google Android Developers
http://developer.android.com/sdk/installing.html

Android Application Development for Dummies
http://jacyar.googlecode.com/files/Android.Application.Development.for.For.Dummies.pdf 

Even can check Android Developers Google Group
http://groups.google.com/group/android-developers 

The application … (process …) has stopped unexpectedly. Please try again

This Bug Solved on Mon June 20, 2011

I am writing my first Andoid application. And facing an error .. I consider it too strange but also expecting to face a lot of strange errors and bugs.

I googled to find out what cause that error. And tried to learn how to debug Android application on Eclipse but no luck.

The application I am writing is having only an image and button. The button is to switch the mobile from normal mode to silent mode and the reverse and the image is an indicator the for which mode currently is active.

When I got the error I highlighted all the the code and started unhighlighting one by one, till I found the this line specifically cause the error:

int ringerMode = mAudioManager.getRingerMode();

when I run the application, on the Debug prespective view , in the error log tab I am getting :

Android Debug

here is a text copy of that error:

No command output when running: ‘am start -n ameen.android.silentModeToggle/ameen.android.silentModeToggle.Silent-
ModelToggleActivity -a android.intent.action.MAIN -c android.intent.category.LAUNCHER’ on device emulator-5554

com.android.ddmlib.ShellCommandUnresponsiveException
	at com.android.ddmlib.AdbHelper.executeRemoteComm...
	at com.android.ddmlib.Device.executeShellCommand(...
	at com.android.ide.eclipse.adt.internal.launch.Ac...
	at com.android.ide.eclipse.adt.internal.launch.An...
	at com.android.ide.eclipse.adt.internal.launch.An...
	at com.android.ide.eclipse.adt.internal.launch.An...
	at com.android.ide.eclipse.adt.internal.launch.An...
eclipse.buildId=M20110210-1200
java.version=1.6.0_24
java.vendor=Apple Inc.
BootLoader constants: OS=macosx, ARCH=x86, WS=cocoa, NL=
en_US
Framework arguments:  -keyring /Users/ameen/.eclipse_key...
Command-line arguments:  -os macosx -ws cocoa -arch x86
-keyring /Users/ameen/.eclipse_keyring -showlocation

and here is all the code :

Android Bug

all other functions are highlighted.

I feel that something is missing in my development environment. Please I need help

I uploaded the zipped project folder into my DropBox folder if someone iterested to test it:

http://www.4shared.com/file/owbZCn0m/Silent_Model_Toggle.html

UPDATE – Mon June 20, 2011

The bug above is solved be a huge help from Mr. Greg Krimer (thank you) .. see details

He mentioned DDMS in hes message. DDMS (as I learned) is a way to debug your Android application in Eclipse. You can read learn it and read more about it from here.

DDMS

DDMS screenshot

The brief of bug reason as Mr Greg wrote:

As you can see, the cause of the problem is just a NullPointerException on line 22 of your activity owing to the fact that mAudioManager is used before it is unitialized. You initialize it on line 28.

So, I was having this line in my code:

int ringerMode = mAudioManager.getRingerMode();

and just by modified it to:

mAudioManager = (AudioManager)getSystemService(AUDIO_SERVICE);

int ringerMode = mAudioManager.getRingerMode();

it works fine 🙂 .. I am so happy