database locked error
<p>iam getting database locked error .</p>

<pre><code>-(IBAction)YesData:(id)sender
 {
 [self Check_Create_DB];

sqlite3 *database;



if(idimg == 0)
{

 NSData *imgData = UIImagePNGRepresentation(image.image);  

UIImage *dataImage=[[UIImage alloc] init];

 dataImage=[UIImage imageWithData:imgData];  

    int ycount1=1;

int ncount1=0;

int neutcount1=0;  

if(sqlite3_open([dbpath UTF8String],&amp;database)==SQLITE_OK)

{
    NSLog(@"Connection Open");  

   const char *sqlTmp="insert into 

    images(imgname,ycount,ncount,neutcount)values(?,?,?,?)";


    sqlite3_stmt *cmp_sqlstmt;

    int returnvalue=sqlite3_prepare_v2(database,sqlTmp,-1,&amp;cmp_sqlstmt,NULL );

    if(returnvalue ==  SQLITE_OK)
    {      
      sqlite3_bind_blob(cmp_sqlstmt, 1, [imgData bytes], [imgData length], NULL);

        sqlite3_bind_int(cmp_sqlstmt, 2, ycount1);


        sqlite3_bind_int(cmp_sqlstmt, 3, ncount1);

        sqlite3_bind_int(cmp_sqlstmt, 4, neutcount1); 

        if(SQLITE_DONE != sqlite3_step(cmp_sqlstmt))
                               NSAssert1(0, @"Error while inserting. '%s'",sqlite3_errmsg(database));

        NSLog(@"insert successfully") ;              

    }
    sqlite3_step(cmp_sqlstmt);

    sqlite3_finalize(cmp_sqlstmt);

   sqlite3_close(database);





    lblvote.text=@"You Voted Yes";

     [newView setHidden:NO];
  }
    else
    {
        sqlite3_close(database); 
   }


  }
   else
  {
   // [self Check_Create_DB];
    //sqlite3 *database;

    sqlite3_open([dbpath UTF8String],&amp;database);

    if(sqlite3_open([dbpath UTF8String],&amp;database)==SQLITE_OK)
    {

        NSLog(@"Connection Open");

        idycount+=1;

         const char  *sqlTmp="update Images set ycount=? where imgid= ?";  


        sqlite3_stmt *cmp_sqlstmt;


        int returnvalue=sqlite3_prepare_v2(database,sqlTmp,-1,&amp;cmp_sqlstmt,NULL);


        NSLog(@"return value.....%d",returnvalue);


        if(returnvalue == SQLITE_OK)

        {  

          sqlite3_bind_int(cmp_sqlstmt,1,idycount );


             sqlite3_bind_int(cmp_sqlstmt,2,idimg );


            NSLog(@"updated");

            if(SQLITE_DONE != sqlite3_step(cmp_sqlstmt))

                NSAssert1(0, @"Error while updating. '%s'", sqlite3_errmsg(database));


            sqlite3_reset(cmp_sqlstmt);     


        }
        else
        {

            NSAssert1(0, @"Error while creating update statement. '%s'", sqlite3_errmsg(database));


        }

        sqlite3_step(cmp_sqlstmt);


        sqlite3_finalize(cmp_sqlstmt);


        sqlite3_close(database);



    }
    else
    {

    sqlite3_close(database);


    }


  }
}
</code></pre>
