Image Retrevial From Database throws error

Can anyone point out what i'm doing wrong with the code below please..
It all works perfectly and returns the image. The probelm is that it causes
java.lang.IllegalStateException: getOutputStream() has already been called for this response
to be thrown in the site's logfile.
It all works perfectly by causes the log file to fill up as visitors access the image.
<%@ page import="java.io.*" %>
<%@ page import="java.sql.Statement" %>
<%@ page import="java.sql.Connection" %>
<%@ page import="java.sql.ResultSet" %>
<%@ page import="java.sql.DriverManager" %>
<%
Connection connectiongalleryimage = null;
Statement statementgalleryimage = null;
InputStream sImage = null;
try {
Class.forName("com.mysql.jdbc.Driver").newInstance();
connectiongalleryimage = DriverManager.getConnection("jdbc:mysql://cluster_01:3306/site_db", "xxxxxx", "xxxxxxx");
statementgalleryimage = connectiongalleryimage.createStatement();
ResultSet rs = statementgalleryimage.executeQuery("select main_image from galleryobj where galobj_id=5 and rec_status='ACTIVE'");
rs.first();
byte[] bytearray = new byte[4096];
int size=0;
sImage = rs.getBinaryStream(1);
response.reset();
response.setContentType("image/jpeg");
response.addHeader("Content-Disposition","filename=getimage.jpeg");
OutputStream outputStream = response.getOutputStream();
while((size=sImage.read(bytearray))!=-1) {outputStream.write(bytearray,0,size);}
} catch (Exception e) {
out.println("<!-- Error getting requested image: "+e+"-->");
} finally {
response.flushBuffer();
sImage.close();
statementgalleryimage.close();
connectiongalleryimage.close();
%>

Google has lot of examples: http://www.google.com/search?q=imageservlet+code+example
At least here is one: http://balusc.blogspot.com/2007/04/imageservlet.html

Similar Messages

  • Jasper report on HTML when one image loaded from database and for the other

    How to generate jasper report on HTML when one image loaded from database and for the other we give a image path
    My code
    ByteArrayOutputStream baos = new ByteArrayOutputStream();
              exporter = new JRHtmlExporter();
              exporter.setParameter(JRExporterParameter.JASPER_PRINT, print);
              exporter.setParameter(JRExporterParameter.OUTPUT_STREAM, baos);
              exporter.setParameter(JRHtmlExporterParameter.IMAGES_URI, strImageInputDirectory);
         exporter.setParameter(JRHtmlExporterParameter.IMAGES_DIR_NAME, strImageOutputPath == null ? "." : strImageOutputPath);
         exporter.setParameter(JRHtmlExporterParameter.IS_OUTPUT_IMAGES_TO_DIR, Boolean.TRUE);
         exporter.setParameter(JRHtmlExporterParameter.IS_USING_IMAGES_TO_ALIGN, Boolean.FALSE);
         exporter.setParameter(JRHtmlExporterParameter.IS_WHITE_PAGE_BACKGROUND, Boolean.FALSE);
              exporter.exportReport();
              byte[] bdata = ((ByteArrayOutputStream) baos).toByteArray();
    Can any one help pls
    Message was edited by:
    ameet.au

    hey sorry for posting it in this forum.
    but do u have sample code for making it work.. since i am able to do it on PDF format(image from Database and another stored in the webserver) using
    byte image[] =(byte[]) outData.get("image");
                        ByteArrayInputStream img = new ByteArrayInputStream(image);
                        hmimg.put("P_PARAMV3", img);
    print = JasperFillManager.fillReport(reportFileName, hmimg, jrxmlds);
    bdata= JasperExportManager.exportReportToPdf(print);

  • Getting image path from database( Remote server)  & display in jsp page

    hai frnds,
    i have one doudt regarding in my web application Development
    . I want to Getting image path from database( **Remote server**) & display in jsp page here iam forwarding my control through Servlets
    how this will passiable
    Thanks in Advance
    SonyKamesh
    [email protected]

    hai
    I think ur doubt will be...
    1) Getting a Image From Remote Server( & U stored a only path name in Data Base)
    2) Image r stroed in saparate Drive( Not in Webroot-- where u Created domine )
    Please Any Help Will be Appriciated
    [email protected]
    Edited by: Sonykamesha on Dec 18, 2007 11:02 PM

  • Try to retrieve data from database got error message

    Try to retrieve data from database got error message *"java.lang.ArrayIndexOutOfBoundsException: 2*
    *     sun.jdbc.odbc.JdbcOdbcPreparedStatement.clearParameter(JdbcOdbcPreparedStatement.java:1023)*
    *     sun.jdbc.odbc.JdbcOdbcPreparedStatement.setDate(JdbcOdbcPreparedStatement.java:811)*
    *     guestbk.doGet(guestbk.java:32)*
    *     guestbk.doPost(guestbk.java:73)*
    *     javax.servlet.http.HttpServlet.service(HttpServlet.java:710)*
    *     javax.servlet.http.HttpServlet.service(HttpServlet.java:803)"*
    I have used prepared statment
    java.text.SimpleDateFormat sdf = new java.text.SimpleDateFormat("dd/MM/yy");
                java.util.Date dt = sdf.parse(str3);
                       Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
                       con=DriverManager.getConnection("jdbc:odbc:gbook");
                       //Statement stmt=con.createStatement();
    PreparedStatement ps = con.prepareStatement("SELECT * from gbook where emailid =? AND date =?");
    ps.setString(1,str1);
    ps.setString(2,str2);
    ps.setDate(3,new java.sql.Date(dt.getTime()));
    //ps.executeQuery();
                       //ResultSet rs=stmt.executeQuery("select * from gbook where emailid = str1");
                  ResultSet rs = ps.executeQuery();
                       out.println("<Html>");
                    out.println("<Head>");
                       out.println("<Title>GuestBook</Title>");
                       out.println("</Head>");
                       out.println("<Table border=1 align=center >");
                       out.println("<H4><B><center>Teacher's Lesson Plan</center></B></H4><BR>");
                       out.println("<TR><TD><b>Teacher Name</b></TD><TD><b>Class</b></TD></TR>");
               while(rs.next())
                        ctr++;
                        String email=rs.getString("emailid");
                        String cmt=rs.getString("comment");
                        out.println("<TR><TD>"+email+"</TD><TD>"+cmt+"</TD></TR>");
            }Please anybody help .

    PreparedStatement ps = con.prepareStatement("SELECT * from gbook where emailid =? AND date =?");
    ps.setString(1,str1);
    ps.setString(2,str2);
    ps.setDate(3,new java.sql.Date(dt.getTime()));Your SQL query has 2 placeholders but you try to set 3 values.
    And didn't you read the stack trace?
    guestbk.doGet(guestbk.java:32)You could've tracked down line 32 and seen what was there at that line.
    People on the forum help others voluntarily, it's not their job.
    Help them help you.
    Learn how to ask questions first: http://www.catb.org/~esr/faqs/smart-questions.html
    ----------------------------------------------------------------

  • Problem Populating Image Item From Database

    Hi All,
    I am using Oracle 9i & Forms 6i on Windows platform & working in client/server model. I created a form in which, I am reading an image file from the file system & then saving it into the database. In the Databse, i created the column as BLOB. But, when I query, this does not retrive the saved image in Image Item. But image is actually saved. When I tried, changing the database column to LONG RAW, it is working. I mean its reading the image in the image item from the database.
    Can anyone pls tell me, is there any problem like this, as we can retrive from LONG RAW but not from BLOB, or I am missin something here.
    Regards

    Hi,
    I use Forms 6i to save and retrieve image in BLOB column without problems.
    Some weeks ago, my column was long raw and I update it without problems. Nothing to do in Forms and juste modifiy query and recompile in Reports.

  • Image rotator from database

    I want to display a couple of rows that will sow about 4 images per row. But images need to be rotated every time the page is refreshed, and the images come from links on the database. Any help will be appreciated. Thanks

    This might get you started with the basics
    Dynamically populating a JavaScript image slideshow
    Here's another one using Bootstrap, PHP and MySQLi *improved*.
    http://www.phpgang.com/dynamic-image-slider-using-twitter-bootstrap-php-with-mysql_471.htm l
    Nancy O.

  • Issues with Image rendering from Database

    Maestros,
    I have an issue here that I working but can hardly find a plausible solution and would like some help from the community. I'll do my best to explain the my issue in detail that way those of you who are savvy in this domain can jump on it right away.
    I am in the process of implementing a shopping grid where products are shown as items on the grid. Each grid contains a custom product tag that contains a product image thumbnail, the description and price. All picture images are stored in a postgres sql database as byte arrays. I retrieve and rendered them on the product grid using a servlet that calls my product service.
    The problem I am having is that when products are rendered not all the images are rendered even though they are present. One a refresh is done, some of the ones that previously did not render on renders and some that did go missing. I am using jsf and it looks like the application reaches the render response phase before the images are completely retrieved. I am also implement hibernate ehcache to see if that can help solve the problem, to no avail.
    Is my approach the right approach? I know some of you would want to ask why I save images in a database and if you really want to know, the reason is because products are loaded dynamically and one product can have as many images as the e-shop manager wants. If please have another way to solve this problem please feel free to let me know. I am sure there is a better way of retrieving those images and render them without any issues and if you have done anything like that before feel free to send me some directions.
    Thanks
    Edited by: user10444142 on Oct 7, 2010 5:55 AM

    Intermittent problems are often a result of interference. Interference can be caused by other networks in the neighbourhood or from household electrical items.
    You can download and install iStumbler (NetStumbler for windows users) to help you see which channels are used by neighbouring networks so that you can avoid them, but iStumbler will not see household items.
    Refer to your router manual for instructions on changing your wifi channel or adjusting your multicast rate.
    There are other types of problems that can affect networks, but this is by far the most common, hence worth mentioning first. Networks that have inherent issues can be seen to work differently with different versions of the same software. You might also try moving the Apple TV away from other electrical equipment.

  • Error while Image loading from database

    I'am using generic handler for loading Image from data bases. Its work fine when when I hardcode the ImageID in QureyString when call Handler. But it's giving errors of different type when I dynamically pass value to qurey string(from datatable).
    "There is already an open DataReader associated with this Command which must be closed first." 
    OR
    "There is already an open DataReader associated with this Command which must be closed first."
    here is a code of Handler
    public void ProcessRequest(HttpContext context)
    Int64 id = Convert.ToInt64(HttpContext.Current.Request.QueryString["adid"]);
    // dt = obj_dalayer.GetRecpDetailsByID(id);
    dt=GetRecpDetailsByID(id);
    if (dt.Rows.Count > 0)
    //context.Response.ContentType = "image/jpeg";
    context.Response.BinaryWrite((byte[])dt.Rows[0][2]);
    public DataTable GetRecpDetailsByID(Int64 reid)
    try
    obj_DB.Open();
    obj_sqlcmd = new SqlCommand("GetRecpDetailsByID", obj_DB.GetDBConnection());
    obj_sqlcmd.CommandType = CommandType.StoredProcedure;
    obj_sqlcmd.Parameters.Add(new SqlParameter("@rid", reid));
    obj_sqlda = new SqlDataAdapter();
    obj_dt = new DataTable();
    obj_sqlda.SelectCommand = obj_sqlcmd;
    obj_sqlda.Fill(obj_dt);
    return obj_dt;
    finally
    obj_DB.Close();
    And here is a HTML and ServerSide code on ASPX page of call handler.
    <img id="img2" alt="Image" runat="server" src='<%#"~/ImageReqHandler.ashx?adid="+Eval("ReID")%>' width="179" height="148" /
    I'm using Eval("ReID") to get ID of Image from datatable.

    Ayez,
    This is the VB forum, try it in the C# form.
    http://social.msdn.microsoft.com/Forums/en-US/csharpgeneral
    However, there they will probably tell you that although your problem is C#, it is ASP.Net some programmers become scared if it is Web you know.
    Success
    Cor

  • Retrieval of image (Blob) from database - doesn't always work in JSP - Why?

    In my JSP pages, when an image needs to be retrieved, I direct <img src> to a servlet that handles image processing.
    As an example, if I have 30 products that need to be shown on 1 webpage, there will be 30, dynamically generated, <img src="go.imageServlet?id=a1"> tags/statements. The servlet, when called, will make a connection to the database, run a query for the image requested (fetched as type Blob), image displays in <img src> area of JSP page, and finally the ResultSet, Statement, and Connection object(s) are closed.
    I tested this out, and unfortunately, to my surprise, and disappointment, a few images did not display on the page. Though the images are in the database table. I'm a little lost as to why this problem is occurring.
    Can someone please shed some light on this for me?

    evnafets wrote:
    If you request just one image, does that image come back broken, or is it different images that are 'broken' each time?On a page of almost 30 image requests (thumbnail size), it varies, but typically, 1-3 images are 'broken' each time. And they are not always the same images. Very strange.
    There may potentially be thread concurrency errors depending upon how you have written your servlet - ie one request for an image interfering with another because they use the same variable.
    To make it threadsafe, in your servlet make sure that you only use variables local to the doGet/doPost method, and not any class attributes.In my JSP page that makes the requests for these images, a String array generates the <img src> tags on the page, as a very basic example :
    <%  for(int i=0; i<products.length; i++) {
    %>
          <img src="go.imageP?imageNumber=<%=products[[0]%>">
    <% }//for %>
    Sorry for not posting code snippets from my servlet in my first post of this topic....
    Here is my servlet snippet -     public class ImageProcessingServlet extends HttpServlet {
              public Connection conn = null;
              public ResultSet rs = null;
              public Statement stmt = null;
              public PreparedStatement pstmt = null;          
              public PrintWriter out = null;     
              public String siteNameReference = "";
              int maxFullSizeImageWidth = 600;          
              int maxSizeImageWidth = 300;
              int maxSizeThumbWidth = 140;
              int maxImageFields = 4;
              String errorMessage = "";               
              public void doGet(HttpServletRequest req, HttpServletResponse res) throws ServletException, IOException
                   doPost(req,res);
              public void doPost(HttpServletRequest req, HttpServletResponse res) throws ServletException, IOException
              try {                       
         HttpSession session = req.getSession();
         siteNameReference = req.getParameter("snr");
         String process = req.getParameter("process");
         if(process == null) process = "";
                   Context ctx = new InitialContext();
              if(ctx == null )
    throw new Exception("Boom - No Context");
              DataSource ds = (DataSource)ctx.lookup("java:comp/env/jdbc/imageDB");
         conn = ds.getConnection();
         stmt = conn.createStatement();      
              rs = stmt.executeQuery("Select "+imageNumber+" from images");
              rs.next();
              Blob blobImage = rs.getBlob(1);               
              getImage(blobImage,"thumb",res);
              if(rs != null) { rs.close(); }
              rs = null;
         if(stmt != null) { stmt.close(); }
         stmt = null;
         if(pstmt != null) { pstmt.close(); }
         pstmt = null;
         conn.close();
         conn = null;          
              }//try
         catch (Exception e) { }
         finally {
                   if (rs != null) {
                   try { rs.close(); } catch (SQLException e) { ; }
                   rs = null;
                   if (stmt != null) {
                   try { stmt.close(); } catch (SQLException e) { ; }
                   stmt = null;
                   if (pstmt != null) {
                   try { pstmt.close(); } catch (SQLException e) { ; }
                   pstmt = null;
                   if (conn != null) {
                   try { conn.close(); } catch (SQLException e) { ; }
                   conn = null;
              }//finally
         }//post          
              public void getImage(Blob blobImage, String imageType, HttpServletResponse res) {
                   try {                                              
                        //imageType will = Super = 600
                        // = Large = 300
                        //               = Thumb = 150
                        res.reset();
                        res.setContentType("image/jpeg");
                        BufferedInputStream bis = new BufferedInputStream(blobImage.getBinaryStream());                    
                        BufferedOutputStream bos = new BufferedOutputStream(res.getOutputStream());                                                            
                        if(imageType.equals("super")) {
                        byte[] imageBytes = new byte[(int)blobImage.length()]; //picture size           
         int length;
         while((length = bis.read(imageBytes)) > 0) {
    bos.write(imageBytes, 0, length);
         bos.flush();     
                   res.flushBuffer();
                        } else
                        if(imageType.equals("large")) {
                             resize(bis,bos,maxSizeImageWidth);
                             bos.flush();
                             res.flushBuffer();
                        } else
                        if(imageType.equals("thumb")) {
                             resize(bis,bos,maxSizeThumbWidth);
                             bos.flush();
                             res.flushBuffer();                         
                        }//if
                        //close streams
                        bis.close();
                        bos.close();
                   }//try
                   catch(Exception e) {}
              }//end          
         public void resize(BufferedInputStream bis, BufferedOutputStream bos, int maxImageWidth) {
              try {                            
              BufferedImage bufimg = ImageIO.read(bis);                                         
              //size of image
              int img_width = bufimg.getWidth();
              int img_height = bufimg.getHeight();               
              double scale = (double)maxImageWidth/(double)img_width;                    
              Image sized = getScaledInstanceAWT(bufimg, scale, Image.SCALE_SMOOTH);
              //convert image to BufferedImage
              BufferedImage resized = toBufferedImage(sized, BufferedImage.TYPE_INT_RGB);                                                                                
                        ImageIO.write(resized,"jpeg",bos);                                                                           
         }//try
         catch(Exception e){}
    }//end
    Edited by: webnotick on Apr 13, 2010 12:24 PM
    --added a method to the code snippet --                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                               

  • Image reclaim from database ,facing problem

    I am very much new in Flex development.........
    I am facing a problem from  quite a few days to  reclaim  a image from the database with the help of servlet to a flex application .  I am  using HttpRequest Object not  Blaze Ds.
    Actually image byte stream is comming back from Servlet to Flex   End  , but when I want to display it , then it shows the place of the image as black .I think image pixel's are not combining togather ..........Have you any Idea?
    I am trying in  the following way.......... this is in the result handler method................
    private function getPhotoResultHandler(event:ResultEvent):void{
                   try{                     
                              xmldata1=event.result as XML;   
                              mx.control.alert.show(xmldata1.toString);        //  Here I can see the  byte stream  in the browser                                                          
                              var byteData : ByteArray;                                                                                            
                              var dec : Base64Decoder  = new Base64Decoder();              
                              dec.decode(xmldata1.toString());                 
                              byteData = dec.toByteArray();                     
                              imggetPhoto.source=byteData;  
                catch( ex : Error )
              Alert.show( ex.message );

    Hi,
    I use Forms 6i to save and retrieve image in BLOB column without problems.
    Some weeks ago, my column was long raw and I update it without problems. Nothing to do in Forms and juste modifiy query and recompile in Reports.

  • Business Rules security from EAS throwing error while adding locations

    Hi,
    Currently we are trying to provide security to the BR's from EAS. As a part of which, we are trying to add location to the BR's. When we expand the Planning node on Locations, it throws the error, "Cannot connect to the Planning server <server name>". When we expand the Essbase server, we do see the application and database, but after a long time, around 10 mins.
    After a call with Oracle, we have restarted the services RMI, EAS and planning in the sequence suggested. Also checked the RMI service, its running fine as well. Below is the error from hbrclient.log
    "2011-08-06 20:41:58, 076 Warn AWT-Eventqueue -0 com.hyperion.hbr.core.metadatamanagerserviceremote - cannot retrieve connected rppt element for planning/a01gidssapp2a"
    Hbrserver.log doesnt have any error. We also have performed reconfiguration of Planning services, but still no help.
    Appreciate if someone can help us resolve the issue, since we have to release the servers for Planning by tomorrow. Thanks in advance.

    I assume that you are using BR as calculation module.
    1. Try creating a new test user say HBRADMIN,
    2. Provide him the admin access to BR, Essbase and Planning App,
    3. Log into Planning Application,
    4. Check the HBR Plugin Data table in EAS schema/databse, see if there is any entries in that table,
    5. Now, Log into EAS console,
    6. Try creating a test BR,
    7. Select outline,
    8. Select Location,
    9. Add access.
    If there is no entry in the HBR Plugin table, try making a manual entry, below is an example:
         HP11113     11333     App1     HP11113     admin     AABPAAANAAEKAAEHAABPAADOAAAIAAFG     8/7/2011 1:05:16 PM
    AABPAAANAAEKAAEHAABPAADOAAAIAAFG is an encrypted password for 'password'.
    Cheers...!!!

  • How to get images dynamically from database without file paths in the table field

    I have a MS-Access database. I am working with ASP.NET. In the database there is product table in which I have "CodeNo" as a field which is a text field, and the product codes like "SM-R-2035". I also have another field "Image" which is also a text field and which have a file path in it corresponding to the particular product Image (e.g. Images\Products\SM-R-2035.jpg). So far every thing is ok. I have to update this site very frequently and lots of images are added each and every time. Its a tedious work to type the paths and file name every time and it also take a lot of time.
    What I am asking is : Is it possible to get images from a specific folder at runtime which is referenced by the "code no" itself and not the file path from the database. (Say at run time the "code no" is referenced from the database and the corresponding image is loaded dynamically from the specified folder). In other word I want to avoid the tedious work of typing.
    Can any one help with this issue. Any other simple suggestions are welcome.

    All you need to do is simple concatenation to obtain the path for the image file.  You didn't mention whether you are using VB.Net, C# or some other language to do your coding.
    If the code in your database is SM-R-2035, the file name is SM-R-2035.jpg and the path to the images foilder is Images\Products\SM-R-2035.jpg, Conceptually here is what you need to do:
    dim code_var
    dim path_var
    code_var = the code you obtain from your relevant field in the database
    path_var = "Images\Products\" & code_var & ".jpg"
    Now path_var is what you would call to obtain the image from your images folder.

  • "fldigi" from AUR throws error concerning libpng

    Just got fldigi from the AUR using the latest PKGBUILD mentioned at the AUR. It compiles fine, however it throws this error on launch:
    libpng warning: Application built with libpng-1.4.12 but running with 1.5.13
    Any help appreciated.

    karol wrote:Have you tried e.g. http://pastebin.com/raw.php?i=6705A1f3 from the comments?
    Yes, tried the two different PKGBUILD's listed there - same error.

  • Select from wwsbr_url$ throws error

    I have a custom item type with a procedure in which I would like to select from the wwsbr_url$ table. If I execute my select statement from SQL*Plus (as portal30) everything works fine. When I view the items in OP, however, the procedure is returning:
    Error 30584: DBMS_SQL has raised an unhandled exception. ORA-01403: no data found
    The select statement is:
    select * into url from wwsbr_url$ u where u.object_id = id and u.object_siteid = caid;
    where url is of type wwsbr_url$%rowtype and where id and caid are passed as paramters to the procedure to specify the item.
    (I have selectively commented out everything in the procedure to determine that this is the statement causing the error. And yes, if I take the values passed to the procedure and execute the statement directly, the row does exist.)
    null

    I have also tried creating a view on this table and creating a synonym for the view in portal30_public and granting privileges on the synonym to that schema. When I created my own table in portal30, I had to do all this because OP was running as the portal30_public when it tried to access the view.
    Still no luck. Any ideas?

  • How to recover from database consistency errors?

    I have a SQL server cluster 2005. Due to the broken of SAN storage's controller and disks, one of my SharePoint content DB has corrupted and has been causing numerous error to the SharePoint. I have run the command "DBCC CHECKDB WITH NO_INFOMDGS"
    and the truncated output are as following:
    Table error: Object ID 53575229, index ID 1, partition ID 72057594038583296, alloc unit ID 72057594043564032 (type In-row data), page ID (3:21580503) contains an incorrect page ID in its page header. The PageId in the page header = (3:21580511).
    CHECKDB found 0 allocation errors and 6 consistency errors in table 'AllDocs' (object ID 53575229).
    Table error: Object ID 53575229, index ID 1, partition ID 72057594038583296, alloc unit ID 72057594043564032 (type In-row data), page ID (3:21580503) contains an incorrect page ID in its page header. The PageId in the page header = (3:21580511).
    CHECKDB found 0 allocation errors and 6 consistency errors in table 'AllDocs' (object ID 53575229).
    Object ID 1058102810, index ID 4, partition ID 72057594052411392, alloc unit ID 72057594058571776 (type In-row data): Page (3:21580478) could not be processed.  See other errors for details.
    CHECKDB found 0 allocation errors and 4 consistency errors in table 'EventCache' (object ID 1058102810).
    Table error: Object ID 1762105318, index ID 1, partition ID 72057594055819264, alloc unit ID 72057594062897152 (type LOB data). The off-row data node at page (3:21985593), slot 35, text ID 5702751551488 is not referenced.
    Msg 8964, Level 16, State 1, Line 1
    Table error: Object ID 1762105318, index ID 1, partition ID 72057594055819264, alloc unit ID 72057594062897152 (type LOB data). The off-row data node at page (3:21985594), slot 14, text ID 5702751354880 is not referenced.
    Msg 8986, Level 16, State 1, Line 1
    Too many errors found (201) for object ID 1762105318. To see all error messages rerun the statement using "WITH ALL_ERRORMSGS".
    CHECKDB found 0 allocation errors and 307 consistency errors in table 'AuditData' (object ID 1762105318).
    CHECKDB found 0 allocation errors and 363 consistency errors in database 'ALCIM_WSS_Content'.
    repair_allow_data_loss is the minimum repair level for the errors found by DBCC CHECKDB (WSS_Content).
    Error show in the event log:
    SQL Server detected a logical consistency-based I/O error: incorrect pageid (expected 3:21580475; actual 0:0). It occurred during a read of page (3:21580475) in database ID 9 at offset 0x00002929576000 in file 'E:\Microsoft SQL Server\Data\MSSQL.1\MSSQL\DATA\WSS_Content_2.ndf'. 
    The last DB backup creatred was about a month ago so doing DB resotre will be my last choice. Is it possible I can recover the DB without data loss using "DBCC CHECKDB ('WSS_Content', REPAIR_REBUILD)"? Any alternative method to acheive my
    goal?
    Thank you.

    Hi,
    Check this part of the output that you have posted
    "repair_allow_data_loss is the minimum repair level for the errors found by DBCC CHECKDB (WSS_Content)."
    Which clearly states that your only option is "repair_allow_data_loss". This option should ONLY be tried as a last resort. If you have any chance of restoring the backup as Bass_player suggested that should be your way. Even if you run repair_allow_data_loss
    and it runs successfully and fixes the corruption, you still would be facing logical corruption with data, as we never know which all records repair_allow_data_loss removes.
    More over in case of SharePoint databases as far as I know, Microsoft Sharepoint Support never used to support those sharepoint databases which were repaired. They will only support a backup of the database in case of corruptions.
    I would suggest you to start working on a better disaster recovery plan in the mean while you are waiting for the backups :)
    HTH,
    Regards, Ashwin Menon My Blog - http:\\sqllearnings.wordpress.com

Maybe you are looking for