Solved

Opening an Excel TEMPLATE that is Stored as a BLOB in SQL Server

Posted on 2003-10-21
13
170 Views
Last Modified: 2010-05-01
I have a table that stores EXCEL templates.  :

Here is what I have:

set cn=SERVER.CreateObject("ADODB.CONNECTION")
cn.ConnectionString="Provider=SQLOLEDB.1;Persist Security Info=False;" & _
    "Initial Catalog=dbAS_FAC_CENSUS;Data Source=ASDEV" & _
    ";User Id=" & Request.Form("txtUserID") & _
    ";Password=" & Request.Form("txtPwd")
cn.Open
set rs=server.CreateObject("ADODB.RECORDSET")
set rs.ActiveConnection=cn
rs.Open("SELECT * FROM vwMART_REPORTS WHERE strUserID='" & Request.Form("txtUserID") & "'")

THE rs("Report") field has the actual Template.  How do I open the contents of that field in Excel?
0
Comment
Question by:clangl
  • 8
  • 5
13 Comments
 
LVL 16

Expert Comment

by:Richie_Simonetti
ID: 9593181
you have to create a temporary local file and open it.
0
 

Author Comment

by:clangl
ID: 9593965
But how do I get it from the table to a local file?
0
 
LVL 16

Expert Comment

by:Richie_Simonetti
ID: 9594073
OK. You need to use ADDB.stream object (more on this later)
0
 
LVL 16

Expert Comment

by:Richie_Simonetti
ID: 9594091
0
 
LVL 16

Accepted Solution

by:
Richie_Simonetti earned 250 total points
ID: 9594101
0
 

Author Comment

by:clangl
ID: 9594180
with the ADo stream method....
What my goal is, is to have them click on this link on a web browser that points to that Field in the table and then have excel open right up......
0
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
LVL 16

Expert Comment

by:Richie_Simonetti
ID: 9598881
But that's a complete diferent scenario!!!
0
 
LVL 16

Expert Comment

by:Richie_Simonetti
ID: 9598901
You need to create/extract the file at server side after user does the click and navigate to resulting xls file. It should be opened in web browser window.
0
 

Author Comment

by:clangl
ID: 9608892
This will work but I need to be able to do this with out saving it to a file.  I will post another question.  Thank you for your help.
0
 
LVL 16

Expert Comment

by:Richie_Simonetti
ID: 9609096
Hummm, i think you can't but i maybe wrong.
Thanks for "A" grade.
0
 

Author Comment

by:clangl
ID: 9614325
I ended up not using a stream.
Just in case you ever need something similiar here is what I ended up doing:

<%
Response.buffer = TRUE
'on error resume next
dim strReport
strReport=left(Request.Form.Item,instr(1,Request.Form.Item,"=")-1)
'Response.Write strReport

dim cn, cmd,rs
set cn=SERVER.CreateObject("ADODB.CONNECTION")
set rs=server.CreateObject("ADODB.Recordset")
cn.ConnectionString="Provider=SQLOLEDB.1;Persist Security Info=False;" & _
    "Initial Catalog=dbAS_FAC_CENSUS;Data Source=ASDEV" & _
    ";User Id=" &  Session("User") & _
    ";Password=" & Session("Pwd")
cn.Open
set cmd=server.CreateObject("ADODB.Command")
set cmd.ActiveConnection=cn
cmd.CommandType=4
cmd.CommandText="sp_MART_GetReport"
set rs=cmd.Execute(,strReport)
set fld=rs.Fields(0)
cBytes = fld.ActualSize
Response.Clear
'Response.ContentType = "application/vnd-ms-excel"
      Response.ContentType = rs.Fields(1).Value
      Response.AddHeader "Content-Disposition", "filename=a.xlt;"
      Response.BinaryWrite (fld.GetChunk(cBytes))
rs.Close
set fld=nothing
set rs=nothing
set cmd=nothing
cn.Close
set cn=nothing

%>
0
 
LVL 16

Expert Comment

by:Richie_Simonetti
ID: 9614344
excellent!!, that's for sure far ago from my knowledge. excellent work again.
(I really think you accepted my comment too soon :)
0
 

Author Comment

by:clangl
ID: 9614401
I ended up using your answer to back in all the Templates to the SQL Database.  
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Replace Formatted Numbers with text 9 61
Validating VB6 Function 19 56
Sending a email via excel using vba 6 72
How to measure sizes and angles in scanned images ? 3 54
When designing a form there are several BorderStyles to choose from, all of which can be classified as either 'Fixed' or 'Sizable' and I'd guess that 'Fixed Single' or one of the other fixed types is the most popular choice. I assume it's the most p…
Background What I'm presenting in this article is the result of 2 conditions in my work area: We have a SQL Server production environment but no development or test environment; andWe have an MS Access front end using tables in SQL Server but we a…
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…

895 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

15 Experts available now in Live!

Get 1:1 Help Now