How can I write binary data to External Datasource

The 1C:Enterprise developers forum

#1
People who like this:0Yes/0No
Active user
Rating: 4
Joined: Mar 14, 2012
Company: GSPD

I have tried to write my PDF file upload to my MSSQL Server (External datasources) but I did not success.
Anyone else tried it before? Can you help me?

This is my code:

Try
KếtNối_SQL = New COMObject("ADODB.Connection");
Command = New COMObject("ADODB.Command");
Selected = New COMObject("ADODB.RecordSet");
KếtNối_SQL.ConnectionString = "driver={SQL Server};" +
"server=" + SQL_ServerName + ";" + "uid=" + SQLUser + ";" +
"pwd="+SQLPassword+";" + "database=" + CSDL_SQL + ";";
KếtNối_SQL.ConnectionTimeout = 30;
KếtNối_SQL.CommandTimeout = 600;
KếtNối_SQL.Open();
Command.ActiveConnection = KếtNối_SQL;
Connected = 1;
Except
Message(ErrorDescription());
Return;
EndTry;
//Chuyển tệp sang máy trạm
If Connected = 1 Then
BinaryData = New BinaryData(lcFilename);
ThưMục = Constants.ThưMụcTệp.Get();
ĐườngDẫn = ThưMục+"\";
Stt = DiễnGiả.Stt;
TenDienGia = DiễnGiả.Description;
TenHoiNghi = DiễnGiả.HộiNghị.Description;
StartTime = DiễnGiả.StartTime;
EndTime = DiễnGiả.EndTime;
Email = DiễnGiả.Email;
Venue = DiễnGiả.Venue;
PresentTitle = DiễnGiả.PresentationTitle;
Country = DiễnGiả.Country;
FileData = Binarydata; //This is field (varbinary(MAX) in SQL server
TextQuerySQL = "INS ERT IN TO DienGia " +
"([Stt], [TenDienGia], [TenHoiNghi], [StartTime], [EndTime], [Email], [Venue], [PresentTitle], [Country], [FileData])
| VALUES ('" + Stt + "', '" + TenDienGia + "', '" + TenHoiNghi + "', '" + StartTime + "', '" + EndTime+ "', '" + Email + "', '" + Venue + "', '" + PresentTitle + "', '" + Country + "', " + FileData + ")"; //CONVERT(" + FileData + ", varbinary(MAX)))
//Message(TextQuerySQL);
KếtNối_SQL.Execute(TextQuerySQL,,128);
Message("Đã chuyển sang máy trạm!");
EndIf;
//ĐÓng kết nối
If Connected = 1 Then
KếtNối_SQL.Close();
EndIf;

When I run it, I have this error:
{CommonModule.DùngChung.Module(252)}: Lỗi khi gọi phương thức ngữ cảnh (Execute)
theo nguyên nhân:
Đã xảy ra tình huống đặc biệt (Microsoft OLE DB Provider for ODBC Drivers): [Microsoft][ODBC SQL Server Driver][SQL Server]Incorrect syntax near '50'.

 
#2
People who like this:0Yes/0No
Just came
Rating: 1
Joined: Oct 4, 2018
Company:

Hello!
Unable to write binary data using SQL ins ert query. Use ADODB.Recordse t method Add.

 
#3
People who like this:0Yes/0No
Active user
Rating: 4
Joined: Mar 14, 2012
Company: GSPD

Thank you, Sergey!

 
Subscribe