Sunday, March 25, 2012
Cannot display image from Database
When i try to display an image from the database,it does not give any error
and does not show the image either. It does not show the box also which has
the cross sign. On seeing the report it seems there is no image eventhough
i have an image from the db on the report.
Please help.
Thanx,
Warm Regards,
Kalpnacan you list down the steps that you performed to display an image?
"kalpna" <kalpna.prakash@.grapecity.com> wrote in message
news:%23jvG%23G4rEHA.3868@.TK2MSFTNGP15.phx.gbl...
> Hi,
> When i try to display an image from the database,it does not give any
> error
> and does not show the image either. It does not show the box also which
> has
> the cross sign. On seeing the report it seems there is no image
> eventhough
> i have an image from the db on the report.
> Please help.
> Thanx,
> Warm Regards,
> Kalpna
>|||i drag an image object from the toolbox
Then in the image wizard that pops up i select image from Database and set
the datset that has the image item from the database and the corresponding
field and the mime type(tried with all the available mime types) and then
say OK and finish.
When i preview /view the report nothing is shown.It does not even show the
image box with a cross or something like that.
Any help wud be of great use.
Thanx,
Kalpna
"avnrao" <avn@.newsgroups.com> wrote in message
news:Ofay1n5rEHA.868@.TK2MSFTNGP12.phx.gbl...
> can you list down the steps that you performed to display an image?
> "kalpna" <kalpna.prakash@.grapecity.com> wrote in message
> news:%23jvG%23G4rEHA.3868@.TK2MSFTNGP15.phx.gbl...
> > Hi,
> >
> > When i try to display an image from the database,it does not give any
> > error
> > and does not show the image either. It does not show the box also which
> > has
> > the cross sign. On seeing the report it seems there is no image
> > eventhough
> > i have an image from the db on the report.
> >
> > Please help.
> >
> > Thanx,
> > Warm Regards,
> > Kalpna
> >
> >
>|||Any solution to this?
I have the same problem :( No images are served from the database allthough
I have verified that they are there...
"kalpna" wrote:
> i drag an image object from the toolbox
> Then in the image wizard that pops up i select image from Database and set
> the datset that has the image item from the database and the corresponding
> field and the mime type(tried with all the available mime types) and then
> say OK and finish.
> When i preview /view the report nothing is shown.It does not even show the
> image box with a cross or something like that.
> Any help wud be of great use.
> Thanx,
> Kalpna
> "avnrao" <avn@.newsgroups.com> wrote in message
> news:Ofay1n5rEHA.868@.TK2MSFTNGP12.phx.gbl...
> > can you list down the steps that you performed to display an image?
> >
> > "kalpna" <kalpna.prakash@.grapecity.com> wrote in message
> > news:%23jvG%23G4rEHA.3868@.TK2MSFTNGP15.phx.gbl...
> > > Hi,
> > >
> > > When i try to display an image from the database,it does not give any
> > > error
> > > and does not show the image either. It does not show the box also which
> > > has
> > > the cross sign. On seeing the report it seems there is no image
> > > eventhough
> > > i have an image from the db on the report.
> > >
> > > Please help.
> > >
> > > Thanx,
> > > Warm Regards,
> > > Kalpna
> > >
> > >
> >
> >
>
>|||This sounds like the images are stored as OLE images in the database (e.g.
Access would convert images into OLE images). You can try the following
expression to get rid of the OLE chunk:
=System.Convert.FromBase64String(Mid(System.Convert.ToBase64String(Fields!Pi
cture.Value), 105))
--
This posting is provided "AS IS" with no warranties, and confers no rights.
"alfgaba" <alfgaba@.discussions.microsoft.com> wrote in message
news:C49DC28A-BEA6-4827-AC27-5025DED46EF2@.microsoft.com...
> Any solution to this?
> I have the same problem :( No images are served from the database
allthough
> I have verified that they are there...
> "kalpna" wrote:
> > i drag an image object from the toolbox
> >
> > Then in the image wizard that pops up i select image from Database and
set
> > the datset that has the image item from the database and the
corresponding
> > field and the mime type(tried with all the available mime types) and
then
> > say OK and finish.
> >
> > When i preview /view the report nothing is shown.It does not even show
the
> > image box with a cross or something like that.
> >
> > Any help wud be of great use.
> >
> > Thanx,
> >
> > Kalpna
> >
> > "avnrao" <avn@.newsgroups.com> wrote in message
> > news:Ofay1n5rEHA.868@.TK2MSFTNGP12.phx.gbl...
> > > can you list down the steps that you performed to display an image?
> > >
> > > "kalpna" <kalpna.prakash@.grapecity.com> wrote in message
> > > news:%23jvG%23G4rEHA.3868@.TK2MSFTNGP15.phx.gbl...
> > > > Hi,
> > > >
> > > > When i try to display an image from the database,it does not give
any
> > > > error
> > > > and does not show the image either. It does not show the box also
which
> > > > has
> > > > the cross sign. On seeing the report it seems there is no image
> > > > eventhough
> > > > i have an image from the db on the report.
> > > >
> > > > Please help.
> > > >
> > > > Thanx,
> > > > Warm Regards,
> > > > Kalpna
> > > >
> > > >
> > >
> > >
> >
> >
> >|||I am having the same problem. I tried the expression below but it doesn't
work for me. All of my images are inserted with an Access Data Project to SQL
Image fields. Some are BMP files, JPG files, or even AutoCAD files. Access
displays them correctly, but Reporting Services will not. Is there any other
way to strip away the OLE junk and get the image placeholder to display? Any
help is greatly appreciated.
"Robert Bruckner [MSFT]" wrote:
> This sounds like the images are stored as OLE images in the database (e.g.
> Access would convert images into OLE images). You can try the following
> expression to get rid of the OLE chunk:
> =System.Convert.FromBase64String(Mid(System.Convert.ToBase64String(Fields!Pi
> cture.Value), 105))
> --
> This posting is provided "AS IS" with no warranties, and confers no rights.
> "alfgaba" <alfgaba@.discussions.microsoft.com> wrote in message
> news:C49DC28A-BEA6-4827-AC27-5025DED46EF2@.microsoft.com...
> > Any solution to this?
> >
> > I have the same problem :( No images are served from the database
> allthough
> > I have verified that they are there...
> >
> > "kalpna" wrote:
> >
> > > i drag an image object from the toolbox
> > >
> > > Then in the image wizard that pops up i select image from Database and
> set
> > > the datset that has the image item from the database and the
> corresponding
> > > field and the mime type(tried with all the available mime types) and
> then
> > > say OK and finish.
> > >
> > > When i preview /view the report nothing is shown.It does not even show
> the
> > > image box with a cross or something like that.
> > >
> > > Any help wud be of great use.
> > >
> > > Thanx,
> > >
> > > Kalpna
> > >
> > > "avnrao" <avn@.newsgroups.com> wrote in message
> > > news:Ofay1n5rEHA.868@.TK2MSFTNGP12.phx.gbl...
> > > > can you list down the steps that you performed to display an image?
> > > >
> > > > "kalpna" <kalpna.prakash@.grapecity.com> wrote in message
> > > > news:%23jvG%23G4rEHA.3868@.TK2MSFTNGP15.phx.gbl...
> > > > > Hi,
> > > > >
> > > > > When i try to display an image from the database,it does not give
> any
> > > > > error
> > > > > and does not show the image either. It does not show the box also
> which
> > > > > has
> > > > > the cross sign. On seeing the report it seems there is no image
> > > > > eventhough
> > > > > i have an image from the db on the report.
> > > > >
> > > > > Please help.
> > > > >
> > > > > Thanx,
> > > > > Warm Regards,
> > > > > Kalpna
> > > > >
> > > > >
> > > >
> > > >
> > >
> > >
> > >
>
>|||That doesn't help. I get exactly the same thing as before -- red x in little
square indicating no source for the image. (I am trying to display a Visio,
AutoCAD, or other OLE object drawing).
What should MIMEType be set to?
-prophead
"Robert Bruckner [MSFT]" wrote:
> This sounds like the images are stored as OLE images in the database (e.g.
> Access would convert images into OLE images). You can try the following
> expression to get rid of the OLE chunk:
> =System.Convert.FromBase64String(Mid(System.Convert.ToBase64String(Fields!Pi
> cture.Value), 105))
> --
> This posting is provided "AS IS" with no warranties, and confers no rights.
> "alfgaba" <alfgaba@.discussions.microsoft.com> wrote in message
> news:C49DC28A-BEA6-4827-AC27-5025DED46EF2@.microsoft.com...
> > Any solution to this?
> >
> > I have the same problem :( No images are served from the database
> allthough
> > I have verified that they are there...
> >
> > "kalpna" wrote:
> >
> > > i drag an image object from the toolbox
> > >
> > > Then in the image wizard that pops up i select image from Database and
> set
> > > the datset that has the image item from the database and the
> corresponding
> > > field and the mime type(tried with all the available mime types) and
> then
> > > say OK and finish.
> > >
> > > When i preview /view the report nothing is shown.It does not even show
> the
> > > image box with a cross or something like that.
> > >
> > > Any help wud be of great use.
> > >
> > > Thanx,
> > >
> > > Kalpna
> > >
> > > "avnrao" <avn@.newsgroups.com> wrote in message
> > > news:Ofay1n5rEHA.868@.TK2MSFTNGP12.phx.gbl...
> > > > can you list down the steps that you performed to display an image?
> > > >
> > > > "kalpna" <kalpna.prakash@.grapecity.com> wrote in message
> > > > news:%23jvG%23G4rEHA.3868@.TK2MSFTNGP15.phx.gbl...
> > > > > Hi,
> > > > >
> > > > > When i try to display an image from the database,it does not give
> any
> > > > > error
> > > > > and does not show the image either. It does not show the box also
> which
> > > > > has
> > > > > the cross sign. On seeing the report it seems there is no image
> > > > > eventhough
> > > > > i have an image from the db on the report.
> > > > >
> > > > > Please help.
> > > > >
> > > > > Thanx,
> > > > > Warm Regards,
> > > > > Kalpna
> > > > >
> > > > >
> > > >
> > > >
> > >
> > >
> > >
>
>|||The supported image types in RS are listed in the "Remarks" section of this
MSDN page:
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/RSRDL/htm/rsp_ref_rdl_elements_fp_5er8.asp
RS does not support any arbitrary OLE object drawing, because we need to be
able to export images correctly to various output formats like PDF etc.
--
This posting is provided "AS IS" with no warranties, and confers no rights.
"prophead" <prophead@.discussions.microsoft.com> wrote in message
news:67A353DB-16BD-4910-9B68-CF6E19053FD6@.microsoft.com...
> That doesn't help. I get exactly the same thing as before -- red x in
> little
> square indicating no source for the image. (I am trying to display a
> Visio,
> AutoCAD, or other OLE object drawing).
> What should MIMEType be set to?
> -prophead
> "Robert Bruckner [MSFT]" wrote:
>> This sounds like the images are stored as OLE images in the database
>> (e.g.
>> Access would convert images into OLE images). You can try the following
>> expression to get rid of the OLE chunk:
>> =System.Convert.FromBase64String(Mid(System.Convert.ToBase64String(Fields!Pi
>> cture.Value), 105))
>> --
>> This posting is provided "AS IS" with no warranties, and confers no
>> rights.
>> "alfgaba" <alfgaba@.discussions.microsoft.com> wrote in message
>> news:C49DC28A-BEA6-4827-AC27-5025DED46EF2@.microsoft.com...
>> > Any solution to this?
>> >
>> > I have the same problem :( No images are served from the database
>> allthough
>> > I have verified that they are there...
>> >
>> > "kalpna" wrote:
>> >
>> > > i drag an image object from the toolbox
>> > >
>> > > Then in the image wizard that pops up i select image from Database
>> > > and
>> set
>> > > the datset that has the image item from the database and the
>> corresponding
>> > > field and the mime type(tried with all the available mime types) and
>> then
>> > > say OK and finish.
>> > >
>> > > When i preview /view the report nothing is shown.It does not even
>> > > show
>> the
>> > > image box with a cross or something like that.
>> > >
>> > > Any help wud be of great use.
>> > >
>> > > Thanx,
>> > >
>> > > Kalpna
>> > >
>> > > "avnrao" <avn@.newsgroups.com> wrote in message
>> > > news:Ofay1n5rEHA.868@.TK2MSFTNGP12.phx.gbl...
>> > > > can you list down the steps that you performed to display an image?
>> > > >
>> > > > "kalpna" <kalpna.prakash@.grapecity.com> wrote in message
>> > > > news:%23jvG%23G4rEHA.3868@.TK2MSFTNGP15.phx.gbl...
>> > > > > Hi,
>> > > > >
>> > > > > When i try to display an image from the database,it does not give
>> any
>> > > > > error
>> > > > > and does not show the image either. It does not show the box also
>> which
>> > > > > has
>> > > > > the cross sign. On seeing the report it seems there is no image
>> > > > > eventhough
>> > > > > i have an image from the db on the report.
>> > > > >
>> > > > > Please help.
>> > > > >
>> > > > > Thanx,
>> > > > > Warm Regards,
>> > > > > Kalpna
>> > > > >
>> > > > >
>> > > >
>> > > >
>> > >
>> > >
>> > >
>>|||Thanks, Robert.
Is there a way to specify an ActiveX container to be deployed and used for
other types of OLE objects stored in the db, or even as files on the server
(using Source = External) in the RS 2000 report design?
-prophead
"Robert Bruckner [MSFT]" wrote:
> The supported image types in RS are listed in the "Remarks" section of this
> MSDN page:
> http://msdn.microsoft.com/library/default.asp?url=/library/en-us/RSRDL/htm/rsp_ref_rdl_elements_fp_5er8.asp
> RS does not support any arbitrary OLE object drawing, because we need to be
> able to export images correctly to various output formats like PDF etc.
> --
> This posting is provided "AS IS" with no warranties, and confers no rights.
>
> "prophead" <prophead@.discussions.microsoft.com> wrote in message
> news:67A353DB-16BD-4910-9B68-CF6E19053FD6@.microsoft.com...
> > That doesn't help. I get exactly the same thing as before -- red x in
> > little
> > square indicating no source for the image. (I am trying to display a
> > Visio,
> > AutoCAD, or other OLE object drawing).
> >
> > What should MIMEType be set to?
> >
> > -prophead
> >
> > "Robert Bruckner [MSFT]" wrote:
> >
> >> This sounds like the images are stored as OLE images in the database
> >> (e.g.
> >> Access would convert images into OLE images). You can try the following
> >> expression to get rid of the OLE chunk:
> >> =System.Convert.FromBase64String(Mid(System.Convert.ToBase64String(Fields!Pi
> >> cture.Value), 105))
> >>
> >> --
> >> This posting is provided "AS IS" with no warranties, and confers no
> >> rights.
> >>
> >> "alfgaba" <alfgaba@.discussions.microsoft.com> wrote in message
> >> news:C49DC28A-BEA6-4827-AC27-5025DED46EF2@.microsoft.com...
> >> > Any solution to this?
> >> >
> >> > I have the same problem :( No images are served from the database
> >> allthough
> >> > I have verified that they are there...
> >> >
> >> > "kalpna" wrote:
> >> >
> >> > > i drag an image object from the toolbox
> >> > >
> >> > > Then in the image wizard that pops up i select image from Database
> >> > > and
> >> set
> >> > > the datset that has the image item from the database and the
> >> corresponding
> >> > > field and the mime type(tried with all the available mime types) and
> >> then
> >> > > say OK and finish.
> >> > >
> >> > > When i preview /view the report nothing is shown.It does not even
> >> > > show
> >> the
> >> > > image box with a cross or something like that.
> >> > >
> >> > > Any help wud be of great use.
> >> > >
> >> > > Thanx,
> >> > >
> >> > > Kalpna
> >> > >
> >> > > "avnrao" <avn@.newsgroups.com> wrote in message
> >> > > news:Ofay1n5rEHA.868@.TK2MSFTNGP12.phx.gbl...
> >> > > > can you list down the steps that you performed to display an image?
> >> > > >
> >> > > > "kalpna" <kalpna.prakash@.grapecity.com> wrote in message
> >> > > > news:%23jvG%23G4rEHA.3868@.TK2MSFTNGP15.phx.gbl...
> >> > > > > Hi,
> >> > > > >
> >> > > > > When i try to display an image from the database,it does not give
> >> any
> >> > > > > error
> >> > > > > and does not show the image either. It does not show the box also
> >> which
> >> > > > > has
> >> > > > > the cross sign. On seeing the report it seems there is no image
> >> > > > > eventhough
> >> > > > > i have an image from the db on the report.
> >> > > > >
> >> > > > > Please help.
> >> > > > >
> >> > > > > Thanx,
> >> > > > > Warm Regards,
> >> > > > > Kalpna
> >> > > > >
> >> > > > >
> >> > > >
> >> > > >
> >> > >
> >> > >
> >> > >
> >>
> >>
> >>
>
>|||You cannot use ActiveX directly - you would need to go through a custom
assembly and convert the data into an image format RS can work with.
For external server files we allow only the given list of MimeTypes - also
for security reasons. Another reason is that when you create a history
snapshot, you would not only expect to get an exact snapshot of your data,
but also an exact snapshot of external images that were available at
snapshot creation time. So, when you render the history snapshot years
later, you still get *exactly* the same data and images across the supported
output formats.
--
This posting is provided "AS IS" with no warranties, and confers no rights.
"prophead" <prophead@.discussions.microsoft.com> wrote in message
news:B92199A9-BAA7-4CC4-97BD-11FE05AA2A53@.microsoft.com...
> Thanks, Robert.
> Is there a way to specify an ActiveX container to be deployed and used for
> other types of OLE objects stored in the db, or even as files on the
> server
> (using Source = External) in the RS 2000 report design?
> -prophead
> "Robert Bruckner [MSFT]" wrote:
>> The supported image types in RS are listed in the "Remarks" section of
>> this
>> MSDN page:
>> http://msdn.microsoft.com/library/default.asp?url=/library/en-us/RSRDL/htm/rsp_ref_rdl_elements_fp_5er8.asp
>> RS does not support any arbitrary OLE object drawing, because we need to
>> be
>> able to export images correctly to various output formats like PDF etc.
>> --
>> This posting is provided "AS IS" with no warranties, and confers no
>> rights.
>>
>> "prophead" <prophead@.discussions.microsoft.com> wrote in message
>> news:67A353DB-16BD-4910-9B68-CF6E19053FD6@.microsoft.com...
>> > That doesn't help. I get exactly the same thing as before -- red x in
>> > little
>> > square indicating no source for the image. (I am trying to display a
>> > Visio,
>> > AutoCAD, or other OLE object drawing).
>> >
>> > What should MIMEType be set to?
>> >
>> > -prophead
>> >
>> > "Robert Bruckner [MSFT]" wrote:
>> >
>> >> This sounds like the images are stored as OLE images in the database
>> >> (e.g.
>> >> Access would convert images into OLE images). You can try the
>> >> following
>> >> expression to get rid of the OLE chunk:
>> >> =System.Convert.FromBase64String(Mid(System.Convert.ToBase64String(Fields!Pi
>> >> cture.Value), 105))
>> >>
>> >> --
>> >> This posting is provided "AS IS" with no warranties, and confers no
>> >> rights.
>> >>
>> >> "alfgaba" <alfgaba@.discussions.microsoft.com> wrote in message
>> >> news:C49DC28A-BEA6-4827-AC27-5025DED46EF2@.microsoft.com...
>> >> > Any solution to this?
>> >> >
>> >> > I have the same problem :( No images are served from the database
>> >> allthough
>> >> > I have verified that they are there...
>> >> >
>> >> > "kalpna" wrote:
>> >> >
>> >> > > i drag an image object from the toolbox
>> >> > >
>> >> > > Then in the image wizard that pops up i select image from Database
>> >> > > and
>> >> set
>> >> > > the datset that has the image item from the database and the
>> >> corresponding
>> >> > > field and the mime type(tried with all the available mime types)
>> >> > > and
>> >> then
>> >> > > say OK and finish.
>> >> > >
>> >> > > When i preview /view the report nothing is shown.It does not even
>> >> > > show
>> >> the
>> >> > > image box with a cross or something like that.
>> >> > >
>> >> > > Any help wud be of great use.
>> >> > >
>> >> > > Thanx,
>> >> > >
>> >> > > Kalpna
>> >> > >
>> >> > > "avnrao" <avn@.newsgroups.com> wrote in message
>> >> > > news:Ofay1n5rEHA.868@.TK2MSFTNGP12.phx.gbl...
>> >> > > > can you list down the steps that you performed to display an
>> >> > > > image?
>> >> > > >
>> >> > > > "kalpna" <kalpna.prakash@.grapecity.com> wrote in message
>> >> > > > news:%23jvG%23G4rEHA.3868@.TK2MSFTNGP15.phx.gbl...
>> >> > > > > Hi,
>> >> > > > >
>> >> > > > > When i try to display an image from the database,it does not
>> >> > > > > give
>> >> any
>> >> > > > > error
>> >> > > > > and does not show the image either. It does not show the box
>> >> > > > > also
>> >> which
>> >> > > > > has
>> >> > > > > the cross sign. On seeing the report it seems there is no
>> >> > > > > image
>> >> > > > > eventhough
>> >> > > > > i have an image from the db on the report.
>> >> > > > >
>> >> > > > > Please help.
>> >> > > > >
>> >> > > > > Thanx,
>> >> > > > > Warm Regards,
>> >> > > > > Kalpna
>> >> > > > >
>> >> > > > >
>> >> > > >
>> >> > > >
>> >> > >
>> >> > >
>> >> > >
>> >>
>> >>
>> >>
>>
Wednesday, March 7, 2012
Cannot Convet Sql image to Byte[]
I am somewhat confused because the INSERT statement for your upload process only contains 4 parameters (even though 5 parameters are specified). So my guess is that the image is not gettng into the database (and is therefore NULL), and that is why you are getting the exception on the download portion?
//
// sqlUploadImage
//
this.sqlUploadImage.CommandText = "INSERT INTO Image_Table (Description, Type, Lenth, DocName) VALUES (@.Description," +
" @.Type, @.Length, @.DocName)";
this.sqlUploadImage.Connection = this.sqlConnection2;
this.sqlUploadImage.Parameters.Add(new System.Data.SqlClient.SqlParameter("@.Description", System.Data.SqlDbType.VarChar, 50, "Description"));
this.sqlUploadImage.Parameters.Add(new System.Data.SqlClient.SqlParameter("@.Type", System.Data.SqlDbType.VarChar, 50, "Type"));
this.sqlUploadImage.Parameters.Add(new System.Data.SqlClient.SqlParameter("@.Length", System.Data.SqlDbType.Int, 4, "Lenth"));
this.sqlUploadImage.Parameters.Add(new System.Data.SqlClient.SqlParameter("@.DocName", System.Data.SqlDbType.VarChar, 50, "DocName"));
this.sqlUploadImage.Parameters.Add(new System.Data.SqlClient.SqlParameter("@.Image", System.Data.SqlDbType.Image, 16, "ImgField"));
this.Button2.Click += new System.EventHandler(this.Button2_Click);
//
// sqlDownLoadImage
//
this.sqlDownLoadImage.CommandText = "SELECT Image_Table.* FROM Image_Table";
this.sqlDownLoadImage.Connection = this.sqlConnection2;//upload file
private void Button1_Click(object sender, System.EventArgs e)
{
//Get the filename of the pdf file to be uploaded.
string strFilename = File1.PostedFile.FileName.Substring(File1.PostedFile.FileName.LastIndexOf("\\") +1);//Get the file type
string strFileType = File1.PostedFile.ContentType;//Get the file size
int intImageSize = File1.PostedFile.ContentLength;// Reads the Image
Stream ImageStream = File1.PostedFile.InputStream;byte[] ImageContent = new byte[intImageSize + 1];
int intStatus = 0;
intStatus = ImageStream.Read(ImageContent, 0, intImageSize);//Response.Write(strFilename.ToString());
//Response.Write("<br>Image Type: " + strFileType.ToString());
//Response.Write("<br>Image Size: "+intImageSize.ToString());this.sqlUploadImage.Parameters["@.Description"].Value = strFilename;
this.sqlUploadImage.Parameters["@.Type"].Value = strFileType;
this.sqlUploadImage.Parameters["@.Length"].Value = intImageSize;
this.sqlUploadImage.Parameters["@.DocName"].Value = "TestPDF";
this.sqlUploadImage.Parameters["@.Image"].Value = ImageContent;try
{
this.sqlConnection2.Open();
this.sqlUploadImage.ExecuteNonQuery();this.Label2.Text = "File Uploaded Successfully";
this.Button2.Visible = true;
}
catch(SqlException ex)
{
Response.Write(ex.ToString());
}
finally
{
this.sqlConnection2.Close();
}
}//download file
private void Button2_Click(object sender, System.EventArgs e)
{
try
{
this.sqlConnection2.Open();
SqlDataReader r = this.sqlDownLoadImage.ExecuteReader(CommandBehavior.CloseConnection);if(r.Read())
{Response.ContentType = r["Type"].ToString();
byte[] image = (byte[])r["ImgField"];
Response.BinaryWrite(image);
}
}
catch(SqlException ex)
{
Response.Write(ex.ToString());
}
finally
{
this.sqlConnection2.Close();
}
}
Terri|||Thanks for the reply, but there are 5 parameters.
I have double check the database and all information is there for the upload and all information is valid.
The problem is on the download.
byte[] image = (byte[])r["ImgField"];
throughs an invalid cast.... I have found many articles using this exact cast.|||HOly cow, I see it now.
only 4 parameters.
let me see if i change itl|||ok fixed my insert string.
Now I have verifity there is nothing being uploaded to hte ImgField... it is DBNULL.|||Why are you adding 1 to the image file size when dimensioning the byte array? I thought the size of the byte array should match the file size?
byte[] ImageContent = new byte[intImageSize];
Terri|||Yes, fixed that also.
Ok it uploads now.
BUT, when I download I get just the binary information to output. And it doesn't output on in the browser but in a new webform.
any ideas?
Updated code here
|||Ok, if I am working with photos, jpeg, gif etc.. the above code works great. But I need to store and view pdf files and this code is not working for that type of application/pdf
//
// sqlConnection2
//
this.sqlConnection2.ConnectionString = ((string)(configurationAppSettings.GetValue("sqlConnection2.ConnectionString", typeof(string))));
//
// sqlDownLoadImage
//
this.sqlDownLoadImage.CommandText = "SELECT Image_Table.* FROM Image_Table";
this.sqlDownLoadImage.Connection = this.sqlConnection2;
//
// sqlCommand1
//
this.sqlCommand1.CommandText = "SELECT ImgField, Type FROM Image_Table WHERE (ImageID = 1)";
this.sqlCommand1.Connection = this.sqlConnection2;
this.Load += new System.EventHandler(this.Page_Load);}
#endregion//upload file
private void Button1_Click(object sender, System.EventArgs e)
{
//Get the filename of the pdf file to be uploaded.
string strFilename = File1.PostedFile.FileName.Substring(File1.PostedFile.FileName.LastIndexOf("\\") +1);//Get the file type
string strFileType = File1.PostedFile.ContentType;//Get the file size
int intImageSize = File1.PostedFile.ContentLength;//Reads teh image
Stream imgStream = File1.PostedFile.InputStream;byte[] ImageContent = new byte[intImageSize];
int intStatus = imgStream.Read(ImageContent, 0, intImageSize);//Response.Write(strFilename.ToString());
//Response.Write("<br>Image Type: " + strFileType.ToString());
//Response.Write("<br>Image Size: "+intImageSize.ToString());SqlCommand sqlUpload = new SqlCommand("INSERT INTO Image_Table(Description, ImgField, Type, Lenth, DocName)" +
"VALUES (@.Description, @.Image, @.Type, @.Length, @.DocName)", this.sqlConnection2);SqlParameter param0 = new SqlParameter("@.Description", SqlDbType.VarChar, 50);
param0.Value = strFilename;
sqlUpload.Parameters.Add( param0 );SqlParameter param1 = new SqlParameter("@.Image", SqlDbType.Image);
param1.Value = ImageContent;
sqlUpload.Parameters.Add( param1 );SqlParameter param2 = new SqlParameter("@.Type", SqlDbType.VarChar, 50);
param2.Value = strFileType;
sqlUpload.Parameters.Add( param2 );SqlParameter param3 = new SqlParameter("@.Length", SqlDbType.Int);
param3.Value = intImageSize;
sqlUpload.Parameters.Add( param3 );SqlParameter param4 = new SqlParameter("@.DocName", SqlDbType.VarChar, 50);
param4.Value = "Test PDF";
sqlUpload.Parameters.Add( param4 );try
{
this.sqlConnection2.Open();
sqlUpload.ExecuteNonQuery();this.Label2.Text = "File Uploaded Successfully";
this.Button2.Visible = true;
}
catch(SqlException ex)
{
Response.Write(ex.ToString());
}
finally
{
this.sqlConnection2.Close();
}
}//download file
private void Button2_Click(object sender, System.EventArgs e)
{
try
{
this.sqlConnection2.Open();
SqlDataReader r = this.sqlDownLoadImage.ExecuteReader(CommandBehavior.CloseConnection);if(r.Read())
{
Response.ContentType = r["Type"].ToString();
Response.BinaryWrite((byte[])r["ImgField"]);
Response.
}
}
catch(SqlException ex)
{
Response.Write(ex.ToString());
}
finally
{
this.sqlConnection2.Close();
}
}
please any ideas?|||I believe you need to use the Response object's AddHeader method in order to get that to work for you. I don't have any direct experience with that, but this post might help:view post 463798
Terri|||Thanks,
I am getting the same results it won't open in a broswer window when I use inline. I would like this to happen, but does this mean i must save the file first to a spot before I can view it.
If that is true, will it be easier for me to just store the pdf's in a file structure on teh server and have teh database store a path to it?
Thanks|||I am having a similar problem
i am trying to use the example at:
http://aspalliance.com/articleViewer.aspx?aId=140
got the upload working
the download is another story though.
when i use the following code i get a conversion issue
Response.BinaryWrite(myDataReader.Item("PersonImage"))
it says that with option strict on, i can not make an implicit conversion from system.object to a 1-dimensional array of Byte.
this is driving me crazy and all the above is way beyond me - as a beginner in this arena|||Instead of this:
Response.BinaryWrite(myDataReader.Item("PersonImage"))
try this:
Response.BinaryWrite(CType(myDataReader.Item("PersonImage"), Byte()))
That should explicitly do the conversion to a byte array.
Terri|||
Terri is a Stud!!!!!!!
That worked FOR ME
Sunday, February 19, 2012
Cannot connect to SQL Server
I've just restored my Windows and installed apps using a Norton Ghost image, which is as good as reinstalling Windows and the applications. I had to reinstall SQL Server Express and VB Express after the restore since I hadn't included them in the original image.
Now ever since I've done that, I cannot add my database to the data sources of any project in VB. When I click on 'add new data source', select 'database' and click next, I get to the screen 'Chose your data connection'. Clicking the 'New Connection' button brings us to the dialog 'Add connection, where we are asked to select the database file we would like to connect to. I select the file, and select Windows Security mode (which was selected during the install of the db engine) and click 'Ok'. The system seems to hang for a while after that, and later, I get this error message -
'An error has occurred while establishing a connection to the server. When connecting to SQL Server 2005, this faliure may be caused by the fact that under the default settings SQL Server does not allow remote connections. (provider: SQL Network Interfaces, error: 26 - Error Locating Server/Instance Specified)'
This problem did not exist before I restored my system. There is also one more thing - when installing SQL Express, I tried to select the SQL Server Service, as well as Reporting Services to run as 'Local Service' instead of Network Service and Local System. But the installation didn't accept it, and threw an error, and didn't install the db engine correctly. It also gave me an error message at the end of the installation that it couldn't start the SQL Server service, as well as the Reporting Server service.
I had to remove and reinstall SQL Server, and this time I had to select both services to run as Local System. The installation went fine after that. I am using Win XP Pro on my home system. What seems to be the issue with SQL Server?
Help would be greatly appreciated.
Please check my blog: http://blogs.msdn.com/sql_protocols/archive/2007/05/13/sql-network-interfaces-error-26-error-locating-server-instance-specified.aspx
If this does not solve your issue, please post more info according to:
http://forums.microsoft.com/MSDN/ShowPost.aspx?PostID=362498&SiteID=1
Thanks.
|||More info according to the MS guidelines page (second link you provided) -
Client Side
1) No connection string entered manually, the program is supposed to generate a connection string after I have selected the database file (data source). Never reach that point. (I have provided detailed information about this in my first post itself).
2) Again, exact error message reproduced above.
3) local. SQL Server Express installed on home computer on Win XP Pro, and (tried to be) accessed from VBExpress and SQL Management Studio Express also installed on local machine.
4) can ping -a localhost, reponse ok (no client server scenario here)
5) The system cannot find the file specified (I think I have telnet disabled in services)
6) Already specified
7) No domains scenario, no network exists. Everything is on the same workgroup
8) TCPIP
9) No alias exists. (Note, never configured this before either, when everything used to work fine)
10) Don't know.
[II] Server Side
1) SQL Server 2005
2) Express
3) TCP/IP
4) Do you mean the db engine service? If so, then yes, it does. I can access the database, and do pretty much everything with it from within Management Studio.
5) It is default instance - MSSQLServer. SQL Browser not enabled.
6) Local System. (Tried to install it as local service, but installation gave an error, sql server service failed to start, and had to remove completely and reinstall and this time selected local system, and installation went fine).
7) not applicable. no remote connections.
8) not applicable. no remote connections. no sql browser started.
[III]
1) Win XP Pro
2) Norton Internet Security 2005, Spybot Search and Destroy. (autorun feature is disabled in both, except norton personal firewall)
[IV]
1) not applicable.
Ok, on your blog it says you never see error message 26 on default instance, but I am seeing it on the very same default instance. I even started the SQL Browser service, which was disabled previously, but I still get the same error.
Alright, checked it seems to alternate between error 25 and error 26 arbitrarily.
|||Are you using "localhost\mssqlserver" in your connection string? This IS NOT correct. For default instance, just use servername(i.e. localhost in your case) and never specify "mssqlserver" as instance name.
error 25 means your connection is not valid.
SQL Network Interfaces, error: 25 - Connection string is not valid) (Microsoft SQL Server, Error: 87)
|||I cannot enter any connection string myself at all. It is generated automatically, based on the options that I select. Here,
let me show you.
First, I select 'add a new data source' for my solution in vbexpress. http://img507.imageshack.us/img507/2595/image1wl3.jpg
Then I select 'database' and click next. http://img507.imageshack.us/img507/4564/image2fb0.jpg
Now, note, in the box circled, though I can place a cursor, it won't allow me to manually enter any text at all. I select the 'new connection' button at the top, which brings me to the next screen. http://img168.imageshack.us/img168/1936/image3nn7.jpg
I select 'browse' to add the name of the database file I wish to connect to. http://img514.imageshack.us/img514/4107/image4ty1.jpg
http://img514.imageshack.us/img514/8822/image5xi4.jpg
Since I had selected 'windows security' mode when installing the db engine, I let it remain at that and hit ok. http://img525.imageshack.us/img525/4291/image6br0.jpg
After hitting Ok, the system seems to hang for a while. Check top left corner. http://img514.imageshack.us/img514/6544/image7vn0.jpg
Then I get this error message. http://img168.imageshack.us/img168/1359/image8md1.jpg
Then I realise that I have not installed this instance as 'SQLExpress', but as the default instance 'MSSQLServer'. So I go to the advanced settings to change a parameter. http://img168.imageshack.us/img168/5230/image9hy6.jpg
Now it has 'SQLExpress' selected by default, even though I haven't got that instance, so I change it to the proper instance name listed below. http://img514.imageshack.us/img514/812/image10rp7.jpg
When I hit ok now on the add connection page, I get the following error message. http://img168.imageshack.us/img168/3346/image11ar8.jpg
There is no way I can enter any connection string myself.
|||Thanks.
When you first connect to .\sqlexpress, you got "error 26" beacause there is no such an instance installed. This is understood, right?
Then you changed to .\mssqlserver, this is an invalid connection string. As I said, you should not use "\mssqlserver" if it's a default instance. This is a bug in Visual Studio, I have reported it a while back and it should be fixed in next release. They should just use "."
There is a workaround for your case, before you add Data Source, do the following:
From Visual Studio, --> Tools menu --> Options --> Database Tools --> Data Connections -->
Change your "SQL Server Instance Name" from "sqlexpress" to blank.
Then go back to add your data source, in the "advanced" tab, you should be able to find an entry "."
|||I tried everything you mentioned. Nothing worked. The solution in the last post solved the original issue, but the db engine began giving me other errors after that. (I don't recall what error or exception it gave me, I was really frustrated and irritated by that time).
So I ultimately went ahead and reinstalled the OS and reinstalled SQL Server, but this time, I chose to select all the default settings for SQL Server. Everything works now.
If Microsoft only ever intended the default settings to work in its products, then why does it include additional settings/features in the first place?
Thanks for your help anyway, Mr. Hong. You don't have anything to do with Microsoft's incompetence, so please be assured that the above rant isn't directed at you.
|||I'm glad things are working for you now. Usually, if you don't know the impact of a configuration, the recommendation is to use the default settings. The default setting has been optimized for most common usage, but may not be the best for a specific case.
|||I got exactly the SAME problem
I've reinstalled SQL Server 2005 with Defaults Settings, but the problem is always present. It really suck! Why Microsoft products cannot communicate togheter? pffff
I remplace "SQLexpress" instance name in Visual Studio by a blank but nothing changed.... So what can i do? I think there is no solution and my project in vb.net will be not finished.
Thank you Microsoft
|||Can you post your connection string and also check my blog about this error message? What instance do you have and where? Thanks.|||Hi !
I've followed all the steps on your blog but nothing...
My instance name is the default name -> MSSQLSERVER
The Connection String is :
-> Data Source=.\SQLEXPRESS;AttachDbFilename="C:\DataWarehouse.mdf";Integrated Security=True;Connect Timeout=30;User Instance=True
If I change the datasource value and set ".\MSSQLSERVER" it fails.
It's like Reachrishikh, the wizard doesn't allow me to put other values that ".\sqlexpress" and ".\mssqlserver". I wanna replace it by (local) or something else
Thank you for your help !!!
|||please read my post on " 04 Jun 2007, 5:28 PM UTC " of this thread for the workaround. ".\MSSQLSERVER" is invalid.|||Hi !
I think that the problem is serious.
Look at this (Sorry for french language)
But nothing change in the wizard
What do you think about that?
Thank you !!
Cannot connect to SQL Server
I've just restored my Windows and installed apps using a Norton Ghost image, which is as good as reinstalling Windows and the applications. I had to reinstall SQL Server Express and VB Express after the restore since I hadn't included them in the original image.
Now ever since I've done that, I cannot add my database to the data sources of any project in VB. When I click on 'add new data source', select 'database' and click next, I get to the screen 'Chose your data connection'. Clicking the 'New Connection' button brings us to the dialog 'Add connection, where we are asked to select the database file we would like to connect to. I select the file, and select Windows Security mode (which was selected during the install of the db engine) and click 'Ok'. The system seems to hang for a while after that, and later, I get this error message -
'An error has occurred while establishing a connection to the server. When connecting to SQL Server 2005, this faliure may be caused by the fact that under the default settings SQL Server does not allow remote connections. (provider: SQL Network Interfaces, error: 26 - Error Locating Server/Instance Specified)'
This problem did not exist before I restored my system. There is also one more thing - when installing SQL Express, I tried to select the SQL Server Service, as well as Reporting Services to run as 'Local Service' instead of Network Service and Local System. But the installation didn't accept it, and threw an error, and didn't install the db engine correctly. It also gave me an error message at the end of the installation that it couldn't start the SQL Server service, as well as the Reporting Server service.
I had to remove and reinstall SQL Server, and this time I had to select both services to run as Local System. The installation went fine after that. I am using Win XP Pro on my home system. What seems to be the issue with SQL Server?
Help would be greatly appreciated.
Please check my blog: http://blogs.msdn.com/sql_protocols/archive/2007/05/13/sql-network-interfaces-error-26-error-locating-server-instance-specified.aspx
If this does not solve your issue, please post more info according to:
http://forums.microsoft.com/MSDN/ShowPost.aspx?PostID=362498&SiteID=1
Thanks.
|||More info according to the MS guidelines page (second link you provided) -
Client Side
1) No connection string entered manually, the program is supposed to generate a connection string after I have selected the database file (data source). Never reach that point. (I have provided detailed information about this in my first post itself).
2) Again, exact error message reproduced above.
3) local. SQL Server Express installed on home computer on Win XP Pro, and (tried to be) accessed from VBExpress and SQL Management Studio Express also installed on local machine.
4) can ping -a localhost, reponse ok (no client server scenario here)
5) The system cannot find the file specified (I think I have telnet disabled in services)
6) Already specified
7) No domains scenario, no network exists. Everything is on the same workgroup
8) TCPIP
9) No alias exists. (Note, never configured this before either, when everything used to work fine)
10) Don't know.
[II] Server Side
1) SQL Server 2005
2) Express
3) TCP/IP
4) Do you mean the db engine service? If so, then yes, it does. I can access the database, and do pretty much everything with it from within Management Studio.
5) It is default instance - MSSQLServer. SQL Browser not enabled.
6) Local System. (Tried to install it as local service, but installation gave an error, sql server service failed to start, and had to remove completely and reinstall and this time selected local system, and installation went fine).
7) not applicable. no remote connections.
8) not applicable. no remote connections. no sql browser started.
[III]
1) Win XP Pro
2) Norton Internet Security 2005, Spybot Search and Destroy. (autorun feature is disabled in both, except norton personal firewall)
[IV]
1) not applicable.
Ok, on your blog it says you never see error message 26 on default instance, but I am seeing it on the very same default instance. I even started the SQL Browser service, which was disabled previously, but I still get the same error.
Alright, checked it seems to alternate between error 25 and error 26 arbitrarily.
|||Are you using "localhost\mssqlserver" in your connection string? This IS NOT correct. For default instance, just use servername(i.e. localhost in your case) and never specify "mssqlserver" as instance name.
error 25 means your connection is not valid.
SQL Network Interfaces, error: 25 - Connection string is not valid) (Microsoft SQL Server, Error: 87)
|||I cannot enter any connection string myself at all. It is generated automatically, based on the options that I select. Here,
let me show you.
First, I select 'add a new data source' for my solution in vbexpress. http://img507.imageshack.us/img507/2595/image1wl3.jpg
Then I select 'database' and click next. http://img507.imageshack.us/img507/4564/image2fb0.jpg
Now, note, in the box circled, though I can place a cursor, it won't allow me to manually enter any text at all. I select the 'new connection' button at the top, which brings me to the next screen. http://img168.imageshack.us/img168/1936/image3nn7.jpg
I select 'browse' to add the name of the database file I wish to connect to. http://img514.imageshack.us/img514/4107/image4ty1.jpg
http://img514.imageshack.us/img514/8822/image5xi4.jpg
Since I had selected 'windows security' mode when installing the db engine, I let it remain at that and hit ok. http://img525.imageshack.us/img525/4291/image6br0.jpg
After hitting Ok, the system seems to hang for a while. Check top left corner. http://img514.imageshack.us/img514/6544/image7vn0.jpg
Then I get this error message. http://img168.imageshack.us/img168/1359/image8md1.jpg
Then I realise that I have not installed this instance as 'SQLExpress', but as the default instance 'MSSQLServer'. So I go to the advanced settings to change a parameter. http://img168.imageshack.us/img168/5230/image9hy6.jpg
Now it has 'SQLExpress' selected by default, even though I haven't got that instance, so I change it to the proper instance name listed below. http://img514.imageshack.us/img514/812/image10rp7.jpg
When I hit ok now on the add connection page, I get the following error message. http://img168.imageshack.us/img168/3346/image11ar8.jpg
There is no way I can enter any connection string myself.
|||Thanks.
When you first connect to .\sqlexpress, you got "error 26" beacause there is no such an instance installed. This is understood, right?
Then you changed to .\mssqlserver, this is an invalid connection string. As I said, you should not use "\mssqlserver" if it's a default instance. This is a bug in Visual Studio, I have reported it a while back and it should be fixed in next release. They should just use "."
There is a workaround for your case, before you add Data Source, do the following:
From Visual Studio, --> Tools menu --> Options --> Database Tools --> Data Connections -->
Change your "SQL Server Instance Name" from "sqlexpress" to blank.
Then go back to add your data source, in the "advanced" tab, you should be able to find an entry "."
|||I tried everything you mentioned. Nothing worked. The solution in the last post solved the original issue, but the db engine began giving me other errors after that. (I don't recall what error or exception it gave me, I was really frustrated and irritated by that time).
So I ultimately went ahead and reinstalled the OS and reinstalled SQL Server, but this time, I chose to select all the default settings for SQL Server. Everything works now.
If Microsoft only ever intended the default settings to work in its products, then why does it include additional settings/features in the first place?
Thanks for your help anyway, Mr. Hong. You don't have anything to do with Microsoft's incompetence, so please be assured that the above rant isn't directed at you.
|||I'm glad things are working for you now. Usually, if you don't know the impact of a configuration, the recommendation is to use the default settings. The default setting has been optimized for most common usage, but may not be the best for a specific case.
|||I got exactly the SAME problem
I've reinstalled SQL Server 2005 with Defaults Settings, but the problem is always present. It really suck! Why Microsoft products cannot communicate togheter? pffff
I remplace "SQLexpress" instance name in Visual Studio by a blank but nothing changed.... So what can i do? I think there is no solution and my project in vb.net will be not finished.
Thank you Microsoft
|||Can you post your connection string and also check my blog about this error message? What instance do you have and where? Thanks.|||Hi !
I've followed all the steps on your blog but nothing...
My instance name is the default name -> MSSQLSERVER
The Connection String is :
-> Data Source=.\SQLEXPRESS;AttachDbFilename="C:\DataWarehouse.mdf";Integrated Security=True;Connect Timeout=30;User Instance=True
If I change the datasource value and set ".\MSSQLSERVER" it fails.
It's like Reachrishikh, the wizard doesn't allow me to put other values that ".\sqlexpress" and ".\mssqlserver". I wanna replace it by (local) or something else
Thank you for your help !!!
|||please read my post on " 04 Jun 2007, 5:28 PM UTC " of this thread for the workaround. ".\MSSQLSERVER" is invalid.|||Hi !
I think that the problem is serious.
Look at this (Sorry for french language)
But nothing change in the wizard
What do you think about that?
Thank you !!