troubleshooting Question

Is there a better way to insert blob images from SQL to Access DB?

Avatar of Cashmgmt
Cashmgmt asked on
Microsoft SQL Server 2005ASP
4 Comments1 Solution336 ViewsLast Modified:
I'm currently copying blob images from sql to access.  It works fine the way I'm doing it, but I've noticed that the query uses a lot of resources on the server.  Is there a better way I can do this?  I've pasted the code.  Any help would be greatly appreciated.  Thanks!
Set rs = Server.CreateObject("ADODB.Recordset")
rs.Open "SELECT * FROM "&lbxblobtable&" WHERE d_busdate >= CAST('"&BeginDate&"' AS smalldatetime) AND d_busdate <= CAST('"&EndDate&"' AS smalldatetime)", Connection

Set objFirstTable = Server.CreateObject("ADOX.Table")
objFirstTable.Name = ""&lbxblobtable&""

for each column in rs.fields 
ct = column.type 
	if ct = 200 then 
		ct = 202
	elseif ct = 131 then 
		ct = 3		
	else
	end if 
	objFirstTable.Columns.Append column.name, ct
next
	
objADOXDatabase.Tables.Append objFirstTable 
		
Set Connection2 = Server.CreateObject("ADODB.Connection")

Set sqlcmd = CreateObject("ADODB.Command")

Connection2.ConnectionString = "Driver={Microsoft Access Driver (*.mdb)};DBQ=" & Server.MapPath("WebLITS\App\"&randomNumber&"_"&lockboxname&".mdb") 

Connection2.Open

If rs.EOF Then 
'	Response.Write("No BLOB Records to Update!") 
'	Response.write "<br>"  
'	Response.write "<br>" 
Else

'	for each column in rs.fields
'	st = st & column.name & ", "
'	next
'	st = left(st,len(st)-2)

Do While NOT rs.Eof
	SQL = " "
	for each column in rs.fields
	SQL = SQL & " ?,"
	next
	SQL = left(SQL,len(SQL)-1)

	sqlcmd.ActiveConnection = Connection2
	sqlcmd.CommandType = 1
	SqlStmt = "INSERT INTO "&lbxblobtable&" VALUES (" & SQL & ")"
	sqlcmd.CommandText = SqlStmt

   	sqlcmd.Parameters.Append sqlcmd.CreateParameter("ID", 3, 1, , rs("ID"))
	sqlcmd.Parameters.Append sqlcmd.CreateParameter("BUSDATE", 202, 1, Len(Trim(rs("D_BUSDATE"))), Trim(rs("D_BUSDATE")))
	sqlcmd.Parameters.Append sqlcmd.CreateParameter("REFNO", 202, 1, Len(Trim(rs("D_REFNO"))), Trim(rs("D_REFNO")))
	sqlcmd.Parameters.Append sqlcmd.CreateParameter("IMAGE", 205, 1, 2147483647, rs("imgData"))
	Set sqlrst = sqlcmd.Execute()

	sqlcmd.Parameters.Delete ("ID")
	sqlcmd.Parameters.Delete ("BUSDATE")
	sqlcmd.Parameters.Delete ("REFNO")	
	sqlcmd.Parameters.Delete ("IMAGE")		
	rs.MoveNext     	
Loop
End If

rs.Close

Open in new window

ASKER CERTIFIED SOLUTION
Cashmgmt

Our community of experts have been thoroughly vetted for their expertise and industry experience.

Join our community to see this answer!
Unlock 1 Answer and 4 Comments.
Start Free Trial
Learn from the best

Network and collaborate with thousands of CTOs, CISOs, and IT Pros rooting for you and your success.

Andrew Hancock - VMware vExpert
See if this solution works for you by signing up for a 7 day free trial.
Unlock 1 Answer and 4 Comments.
Try for 7 days

”The time we save is the biggest benefit of E-E to our team. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange.

-Mike Kapnisakis, Warner Bros