![]() |
Script for inserting binary file data into a db |
Post Reply
|
Page 12> |
| Author | |
jjaroska
New User
Joined: 20 Apr 2012 Posts: 1 |
Post Options
Quote Reply
Topic: Script for inserting binary file data into a dbPosted: 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 |
|
![]() |
|
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 |
|
![]() |
|
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 |
|
![]() |
|
James Horton
Admin Group
Technical Support Joined: 01 Jun 2009 Location: Stoke-on-Trent Posts: 277 |
Post Options
Quote Reply
Posted: 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 10:43am |
|
Hi, And where should I put this script into? Thanks, Ashish
Edited by ash0602 - 15 Jun 2011 at 10:45am |
|
![]() |
|
Daniel
Admin Group
Technical Director Joined: 19 Dec 2006 Location: Stoke-on-Trent Posts: 875 |
Post Options
Quote Reply
Posted: 10 May 2010 at 9:36am |
|
That normally means you haven't added the reference to ADO with the references button at the top of the window; have you done this?
|
|
|
Daniel Tallentire
Support Parker Software |
|
![]() |
|
iareanet
New User
Joined: 28 Apr 2010 Posts: 3 |
Post Options
Quote Reply
Posted: 29 Apr 2010 at 7:45pm |
|
Dim DBConnection As New ADODB.Connection
Dim Attachments As New ADODB.Recordset Dim myStream As ADODB.Stream are giving me an error expecting a specific object type |
|
![]() |
|
Daniel
Admin Group
Technical Director Joined: 19 Dec 2006 Location: Stoke-on-Trent Posts: 875 |
Post Options
Quote Reply
Posted: 18 Feb 2010 at 8:50pm |
|
Hi Jen (sorry for the delayed response, I didn't spot this)
As far as I am aware there aren't any issues with file size - I've definitely done 1MB files before. It could be a setting in the database options that controls this, or a time out? What error code does it give?
|
|
|
Daniel Tallentire
Support Parker Software |
|
![]() |
|
jenik
New User
Joined: 15 Jun 2009 Location: San Jose, CA Posts: 2 |
Post Options
Quote Reply
Posted: 14 Jan 2010 at 7:28pm |
|
i'm using a variation on this script to insert an attachment into CRM. but it seems to fail when the attachment is over 200 KB. is there a setting either in Email2DB or on the server that i can do to increase the file size limit? i've added a buffer of 500KB to my code, but it doesn't seem to make a difference:
myStream.Read(512000) thanks, jen |
|
![]() |
|
Stephen
Admin Group
Joined: 21 Oct 2005 Location: Stoke on Trent Posts: 1392 |
Post Options
Quote Reply
Posted: 19 May 2009 at 1:50pm |
|
For SQL Server you could also use:
Attachments.Open "Attachments",DBConnection,adOpenDynamic,adLockOptimistic,adCmdTableDirect
The 'adCmdTableDirect' opens the specified table directly.
Steve
|
|
![]() |
|
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 |