![]() |
Script for inserting binary file data into a db |
Post Reply
|
Page <12 |
| Author | |
James Horton
Admin Group
Technical Support Joined: 01 Jun 2009 Location: Stoke-on-Trent Posts: 275 |
Post Options
Quote Reply
Topic: Script for inserting binary file data into a dbPosted: 15 Jun 2011 at 1:38pm |
|
The script would be the same, just make sure that the Update Database section of the trigger is referencing your database via the Connection String or builder.
|
|
|
Best Regards,
James Horton Technical Analyst Parker Software |
|
![]() |
|
ash0602
New User
Joined: 14 Jun 2011 Location: United Kingdom Posts: 2 |
Post Options
Quote Reply
Posted: 15 Jun 2011 at 1:45pm |
|
Thanks James,
This is my script, as mentioned earlier, %msg_uid% is not getting updated in the parent table (but getting updated in the child table). I was doing field extraction, and now even after adding in the script below, the cec_contacts.cnt_msg_uid (my parent table's column for %msg_uid%) is not getting updated. Without which I'll not be able to reference attachments from the parent table. Need help on this: Sub Main() ' this script saves the saved attachment filenames in the Attachment table ' we have added a reference to the Microsoft ActiveX Data Objects (ADO). ' it assumes you already have a table called 'cec_contact_attachments' in the database. If MSG_AttachmentCount=0 Then Exit Sub ' if no attachments do nothing Dim DBConnection As New ADODB.Connection ' child table Dim cec_contact_attachments As New ADODB.Recordset ' parent table Dim cec_contacts As New ADODB.Recordset Dim myStream As ADODB.Stream Dim A As Integer On Error GoTo erl DBConnection.ConnectionString="Provider=OraOLEDB.Oracle.1;Password=custemails;Persist Security Info=True;User ID=custemails;Data Source=apexdev;" ' use the connection string specified on the Database tab DBConnection.Open ' open the cec_contacts table cec_contacts.Open "cec_contacts",DBConnection,adOpenDynamic,adLockOptimistic ' update relevant columns cec_contacts.Fields("cnt_msg_uid")=MSG_UID cec_contacts.Fields("cnt_file_count")=MSG_AttachmentCount cec_contacts.Update cec_contacts.Close ' open the cec_contact_attachments table cec_contact_attachments.Open "cec_contact_attachments",DBConnection,adOpenDynamic,adLockOptimistic For A=1 To MSG_AttachmentCount If len(msg_attachment(A)) > 0 Then AddToLog("Processing: " & MSG_Attachment(A)) cec_contact_attachments.AddNew 'cec_contact_attachments.Fields("cat_cnt_id")=CNT_ID cec_contact_attachments.Fields("cat_cnt_msg_uid")=MSG_UID cec_contact_attachments.Fields("cat_file_sequence")=A cec_contact_attachments.Fields("cat_file_name")=MSG_Attachment(A) Set myStream = New ADODB.Stream AddToLog("File is type: " & MSG_AttachmentType(A)) myStream.Type = adTypeBinary AddToLog("Opening temp file: " & MSG_AttachmentTempLocation(A)) myStream.Open myStream.LoadFromFile(MSG_AttachmentTempLocation(A)) cec_contact_attachments.Fields("cat_file_content")=myStream.Read cec_contact_attachments.Fields("cat_file_size")=myStream.Size myStream.Close cec_contact_attachments.Fields("cat_file_mime_type")=MSG_AttachmentType(A) cec_contact_attachments.Update End If Next A cec_contact_attachments.Close DBConnection.Close Call AddToLog("cec_contact_attachments table updated successfully") Exit Sub erl: Call AddToLog("Error in script: " & Err.Description) End Sub |
|
![]() |
|
andyj1970
New User
Joined: 23 Jun 2011 Posts: 27 |
Post Options
Quote Reply
Posted: 27 Jun 2011 at 1:36pm |
|
We had a problem with the script running againt Oracle 11g database to load attachments as above. The first attachment loads fine but subsequent ones were not being loaded. The error message shown in the service log was:
2011-06-22:12:20:07 ## file closed successfully ## 2011-06-22:12:20:07 Error in script: ROW-00014: Cannot update row as the data in the database has changedzfPu 2011-06-22:12:20:07 New record added to database |
|
![]() |
|
jjaroska
New User
Joined: 20 Apr 2012 Posts: 1 |
Post Options
Quote Reply
Posted: 23 Apr 2012 at 3:43pm |
|
I am having a problem when i read the file inserted into the database. i get the error the magic number is wrong. it seems that this is a common asp.net error message when the whole file is not present. i can write and read other files when i use the file component from devexpress but not when i use the script from this thread. can someone help?
Edited by jjaroska - 23 Apr 2012 at 3:44pm |
|
![]() |
|
Post Reply
|
Page <12 |
| Forum Jump | Forum Permissions ![]() You cannot post new topics in this forum You cannot reply to topics in this forum You cannot delete your posts in this forum You cannot edit your posts in this forum You cannot create polls in this forum You cannot vote in polls in this forum |