N/APosted on - 10/31/2012
I have installed SQL server 2012 and I'm storing google-map-like tiles into it as a BLOB. I'd like to show these tiles on user's web browser. How can I do this using SQL server?
EDIT: I'm using C# and ASP.NET (.NET 4 framework) with LINQ to SQL.
Serving Google map tiles from local SQL Server
You need to retrieve the image in to a byte array and stream it to the web form. Below is a sample code which shows you how to achieve it. Sample contains two page one page to get the image and store it on a byte array and the other page is to display it to the user.
stringimageID = Request["imageid"];
string DBconnstr = "server=server;uid=sa;pwd=;database=database";
SqlConnection conn = new SqlConnection(DBconnstr);
SqlCommand cmd = new SqlCommand("spGetImage", conn);
cmd.CommandType = CommandType.StoredProcedure;
SqlParameter imageid = new SqlParameter("@imageid", SqlDbType.Int, 4);
imageid.Value = Convert.ToInt32(imageID);
imageid.Direction = ParameterDirection.Input;
SqlDataReader dr = cmd.ExecuteReader();
byte buffer = (byte)dr;
Response.ContentType = "image/jpeg";
“spGetImage” is a stored procedure and can be written as below
Create procedure spGetImage
Select Image –BLOB image
Where [email protected]
Then on the web form you can bind the image to an ASP.NET Image control as below
<asp:Image ImageAlign =”Middle” ImageUrl =’getImage.aspx?imageid=1 ' Runat =server />