might it have something to do with sql permissions against the table?
Are you executing embedded SQL vs a stored proc? I'm thinking that the tables may not have permissions for direct access.
Just so I understand the environment, is this the setup?:
Test - Web Server1 and SQL Server 1
Production is different servers (web2, sql2) (your dev environment)
Does the account that the connection string is using have the correct permissions?
Are you writing out a surpressed exception to the UI?
Date: Tue, 29 Apr 2008 17:57:44 +0530 From: mishradipak gmail.com To: aspnet-databases aspadvice.com Subject: [aspnet-databases] RE: Error displaying images in gridview
Dear Tim, Rafeeq,
I tried the code but again its not showing Images in Grid View.
I dont know wats the prob with it.
It Shows images on my development machine but not on system.
My payment is stuck bcos of this error.Since on developments machine it works well .... while on client side it sometimes stops showing the image.Also same data base works well on our system.
Need Help.Dont know wat to do..since no error on develpmnt system.
Regards
On Wed, Apr 23, 2008 at 7:27 PM, Tim Curtin < tjc_tek  hotmail.co m">tjc_tek hotmail.com> wrote:
1. Maybe you're supressing an exception. write it out to a label control. 2. try setting the response.contenttype before you response.binarywrite the image bits. Do While (rdimg.Read()) Response.ClearHeaders() Response.ClearContent() Response.ContentType = "image/jpg" Response.BinaryWrite(rdimg.Item("sampimg"))
Loop Incidently, you should add a 'Finally' where you close the connection. Finally always runs regardless of an exception sub page_load(...) Me.lblMessage.Text = "" end sub function theFunction dim con as new SqlConnection() Try con.connectionstring = ConfigurationManager.ConnectionStrings("connectionstring").connectionstring ....... Catch ex As Exception Me.lblMessage.Text = ex.Message 'View an exception Finally If con.State <> ConnectionState.Closed() Then con.Close() End Try
Tim
Date: Wed, 23 Apr 2008 10:36:49 +0530
From: mishradipa k gmail.com">mishradipak gmail.com To: aspnet-databases aspadvice.com">aspnet-databases aspadvice.com Subject: [aspnet-databases] RE: Error displaying images in gridview
Dear Tim
here is the code............ for grid view...............SampImg is the name of the column to display image which has been converted to templte column ..........formaturl is the function used to pass the sno which is identity and primary key.
<asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False" CellPadding="4" DataKeyNames="snoart" DataSourceID="SqlDataSource4" ForeColor="#333333" GridLines="None" AllowPaging="True" AllowSorting="True"> <FooterStyle BackColor="#5D7B9D" Font-Bold="True" ForeColor="White" /> <Columns> <asp:CommandField ShowSelectButton="True" /> <asp:BoundField DataField="snoart" HeaderText="SNoArt" InsertVisible="False" ReadOnly="True" SortExpression="snoart" /> <asp:BoundField DataField="sampname" HeaderText="SampName" SortExpression="sampname" /> <asp:BoundField DataField="artdesign" HeaderText="ArtDesign" SortExpression="artdesign" /> <asp:TemplateField HeaderText="SampImg" SortExpression="sampimg"> <EditItemTemplate> <asp:TextBox ID="TextBox1" runat="server" Text='<%# Bind("sampimg") %>'></asp:TextBox> </EditItemTemplate> <ItemTemplate> <asp:Image ID="Image1" width="75" Height="75" runat="server" ImageUrl='<%# formaturl(databinder.Eval(container.dataitem,("snoart"))) %>' /> </ItemTemplate> </asp:TemplateField> </Columns> <RowStyle BackColor="#F7F6F3" ForeColor="#333333" /> <EditRowStyle BackColor="#999999" /> <SelectedRowStyle BackColor="#E2DED6" Font-Bold="True" ForeColor="#333333" /> <PagerStyle BackColor="#284775" ForeColor="White" HorizontalAlign="Center" /> <HeaderStyle BackColor="#5D7B9D" Font-Bold="True" ForeColor="White" /> <AlternatingRowStyle BackColor="White" ForeColor="#284775" />
</asp:GridView>
then there is this format url function in code behind page:--
Function formaturl(ByVal strarguement) As String Return ("imgdisp1.aspx?id=" & strarguement) End Function this function passes the snoart as string argument to page imgdisp1 coding for which is:---
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load Try Dim strimageid As String = Request.QueryString("id") Dim conn As New SqlConnection(ConfigurationManager.ConnectionStrings("erpfmgConnectionString").ConnectionString) Dim cmd3 As SqlCommand conn.Open() cmd3 = New SqlCommand("select * from catalogmast where snoart=" & strimageid, conn) 'cmd3 = New SqlCommand("select * from photos", conn) Dim rdimg As SqlDataReader rdimg = cmd3.ExecuteReader
Do While (rdimg.Read()) Response.BinaryWrite(rdimg.Item( "sampimg")) Loop conn.Close()
Catch ex As Exception End Try
End Sub this is the coding i have used the problem is when i make changes and updates the virtual directory with new changes then it stops showing image and after 1-2 days it starts showing image. Also in between it stops showing image for articles which it used to show. Note:--- All the articles have image uploaded and saved...so there is no question of Null Values...
below is the code i used to save image to database:---
If FileUpload1.HasFile Then If FileUpload1.PostedFile.ContentType <> "image/pjpeg" And FileUpload1.PostedFile.ContentType <> "image/gif" And FileUpload1.PostedFile.ContentType <> "image/bmp" And FileUpload1.PostedFile.ContentType <> "image/jpeg" Then lblmsg.Text = "Select Image File Only" Exit Sub End If Dim reader As IO.BinaryReader = New IO.BinaryReader(FileUpload1.PostedFile.InputStream) Dim image() As Byte = reader.ReadBytes(FileUpload1.PostedFile.ContentLength) Dim insertSql As String = "INSERT INTO catalogmast (sampname,sampdesc,sampimg,arttype,artdesign,buyfrm,buydept) VALUES ( samp, desc, Photo1, arttype, artdesign, buyfrm, buydept)" cmd2 = New SqlCommand(insertSql, conn) cmd2.Parameters.Add( " samp", SqlDbType.NVarChar, 50) cmd2.Parameters( " samp").Value = Trim(txtname.Text) cmd2.Parameters.Add( " desc", SqlDbType.NVarChar, 200) cmd2.Parameters( " desc").Value = Trim(txtdesc.Text) cmd2.Parameters.Add( " Photo1", SqlDbType.Image) cmd2.Parameters( " Photo1").Value = image cmd2.Parameters.AddWithValue( " arttype", DropDownList2.SelectedItem.Text) cmd2.Parameters.AddWithValue( " artdesign", DropDownList4.SelectedItem.Text) cmd2.Parameters.AddWithValue( " buyfrm", ddbuyer.SelectedItem.Text) cmd2.Parameters.AddWithValue( " buydept", dddept.SelectedItem.Text) cmd2.ExecuteNonQuery() end if conn.Close() lblmsg.Text = "Sample Data Saved Successfully" the above coding is in transaction with one more query and with try catch....... Hope i have made problem clear now..... Waiting for reply................. Regards Dipak
On Tue, Apr 22, 2008 at 5:41 PM, Tim Curtin < tjc_tek  hotmail.co m">tjc_tek hotmail.com> wrote:
- can you post the code/html for the grid?  ; - did you check that the field is not null on the server? - are you using a page/handler to write the bits back to the page-image? - are you setting the correct mime type for the image output? - how are you retrieving the image?
Date: Tue, 22 Apr 2008 12:42:11 +0530
From: mishradipak gmail.com">mishradipak gmail.com To: aspnet-databases aspadvice.com">aspnet-databases aspadvice.com Subject: [aspnet-databases] RE: Error displaying images in gridview
Tim,
It shows image individually always... not in grid view.... while sometimes it shows image even in grid view.
Regards
Surendra
On Mon, Apr 21, 2008 at 5:41 AM, Tim Curtin < tjc_tek  hotmail.co m">tjc_tek hotmail.com> wrote:
Well, not knowing your app, the only things that come to mind are that the image field in the database is null or the url from the page that is creating the web image (<img src='fetch Image.aspx?id=123'> ) is perhaps to another domain and getting shut down by security on the server. Other than that, can you post the code that is retrieving the image?
Date: Mon, 21 Apr 2008 00:35:53 +0530
while the 2nd link shows how to store image to database and read image from database singly.. but the problem i am facing is that sometimes its not displayed in gridview wherein i have converted a column to template insert a image box into it and pass serial no as primary key to other page (where i am reading image and displaying it by response.write (bibary thing) whose url i am setting as url for image control.
So may be now my problem is clearer.
Regards
Dipak
Thanks in Advance
On Mon, Apr 21, 2008 at 12:26 AM, dipak mishra < mishradipa k gmail.com">mishradipak gmail.com> wrote:
Thanks TIM, Rafeeq , and others for help,
I think i have not made myself clear i am getting the images to be displayed ... storing or displaying image is anot an issue.... but the problem is that at my clients place it sometimes stops showing the images in grid view.... while it shows on image box individually..
Regards
Dipak
On Fri, Apr 18, 2008 at 6:17 PM, Rafeeq . < kpmrafeeq  gmail.com" >kpmrafeeq gmail.com> wrote:
Yes Tim,
I think he can apply the same concept to display the image.
-- Regards, >Rafeeq >Keralam
> > Subject: [aspnet-databases] RE: Error displaying images in gridview
&g t; > > To: aspnet-databases aspadvice.com">aspnet-databases aspadvice.com > > > > Hi Dipak, > > > > Try below method. > > > > str = "SELECT image FROM album where id =" & ID > > rs.Open str, conn > > if rs.eof then 'No records found > > Response.End > > else 'Display the contents > > Response.ContentType = "image/gif" > > Response.BinaryWrite(rs("image")) > > end if > > > > You can use red highlighted code in the grid, if you are using extended > > grid. > > > > As you are storing it as binary format. you need to reload it in binary, > > try.. this > > > > Happy coding, > > -- > > With Warm Regards, > > > > >Rafeeq > > >Keralam > > > > > > > > > > On Fri, Apr 18, 2008 at 12:51 PM, dipak mishra < mishradipak gmail.com">mishradipak gmail.com> > > wrote: > > > > > Dear Allen, > > > I am storing Image itself in database not the path to it. > > > How to display that using image field. > > > I am not able to do so. > > > Plz Help > > > > > > On 4/18/08, Allen Moon < howlmoon clearwire.net">howlmoon clearwire.net> wrote: > > > > Hey there > > > > In ASP 2.0 there is a ImageField in gridview that you need to use. > > > > > > > > -----Original Message----- > > > > From: dipak mishra [mailto: mishradipak gmail.com">mishradipak gmail.com] > > > > Sent: Thursday, April 17, 2008 1:15 PM > > > > To: aspnet-databases aspadvice.com">aspnet |