LOAD DATA LOCAL INFILE in C# from memory - c#

Is there a way to use the LOAD DATA LOCAL INFILE command to load data from memory in c#?
The closest I can come up with is executing a command like:
INSERT INTO tbl_name (a,b,c) VALUES(1,2,3),(4,5,6),(7,8,9);
I'm trying to avoid needing to write a file to the disk (fun with permission issues) on the client's system.

No you cant. It must read fom a file on disk. Txt or csv are most common.
http://dev.mysql.com/doc/refman/5.1/en/load-data.html

Related

Is it possible to use a Memory Mapped File (C#) instead of a file in command Write_Flash of esptool.py?

I have encrypted files which are later decrypted and written to Memory Mapped Files.
I want to write to ESP32's flash a binary file that is decoded into Memory Mapped File. I saw this command in the documentation: esptool --port /dev/ttyUSB0 write_flash --flash_mode qio --flash_size 32m 0x0 bootloader.bin 0x1000 my_app.bin
, but I need to insert the data contained in the Memory Mapped File instead of bootloader.bin and my_app.bin.
Is there a way to send esptool.py the data from the Memory Mapped File other than creating a temporary file and using it as an argument to the command?

How to buffer BCP output rather than writing to a file

I'm exporting data from SQL Server using BCP. The output file is written to disk, but needs to be re-encoded. Using C#, I re-encode the file to UTF8 and re-save it to disk. As is, it has to save the output, re-encode, and then re-save it. Seems inefficient.
I'm wondering if there's a way to eliminate saving the data twice. For example, direct the output to memory or intercept the BCP output file in memory before it's written to disk?
Any advice is greatly appreciated.
Load the data in your C# application and write it to disk using any format you like. BCP does not have inherent efficiency advantages compared to a custom app. You might use more CPU in ADO.NET + C# than the C++ based BCP uses. This is to be tested.
You should look into Windows named pipes. Similar to the Unix concept but not as easily created.
This blog post provides a tool that sets up a pipe and automatically compresses the "file" data that is written to it. We use this to compress bcp output without writing an uncompressed file to disk.
The code is provided so you "should" be able to modify it to convert the encoding instead of compressing the data.

Read Streaming Excel file which is not saving content to hard disk

i can comfortably read excel file via ADO.net and ExcelReader but i have to read an Excel file in which data is streaming(by some other application) and that data is not not getting saved on Hard disk
Problem is filestream reads content of file which is saved in hard disk :( but here data is not saved on hard disk
Task at Glance
1) Some exe named abc.exe (3rd party exe, i have no control over it) writing data to excel named temp.xls in every 1 second,and this excel file is open. We can see this data in excel but that data is not getting saved on hard disk. abc.exe is using excel just to display data where we can merely see data.
2) Now I am trying to read data from excel, since that data is not getting saved on hard disk so we can not read with help of file stream class.
3) I am looking for technique by which we can read data in C# from this opened excel file directly from its memory not from hard disk.
Is it possible to read ?
Please help me out
There is approch you can follow:
open temp.xls with readonly flag with standard way: Workbooks.Open Method
Perform your traitement on data. Peraphs copying content to another Workbook.
detect changes on temp.xls using FileSystemWatcher Class and reopen it as 1st point
Another thing can be useful is to detect end of process from abc.exe. Maybe it is only by detect non-existance of temp.xls or non-existance of abc.exe in table of process (via ManagementEventWatcher Class).
Anyway at this point you should sniff everything passing thru temp.xls.
IF you really want "live access" to those changes you can do this:
Write an Excel-Addin (basically a PlugIn for Excel)
It runs inside Excel and can receive events (like workbook/cell changed, file opened/closed etc.)...
this AddIn then communicates all information needed via IPC (for example MMF) to your EXE
Another option might be to use Interop to communicate directly with Excel - whether this works robustly enought depends on several aspects (how the other EXE communicates with Excel etc.).

Loading text stream from c# to sql server without saving physical file?

I have a text stream that I can save as a txt file and then call sql server stored proc to bulkinsert that txt file.
But I don't want to deal with file system access and all that stuff. and sqlBulkCopy can't do it I beleive. What's the solution then?
If the incoming stream represents rows for a table, then you can write a custom IDataReader implementation that reads from the stream and presents each row in turn (non-buffered). You can then feed this to SqlBulkCopy.
Example: https://groups.google.com/group/microsoft.public.dotnet.languages.csharp/msg/b1d70b504cdee2ad?hl=en&pli=1

Opening byte[] as a file without actually saving it as a file first

What is the best way to open a Word file that was stored as a byte[] in a database?
I have to store some documents in an Access database - Word files, 2003 and up - on an application that is strictly run off of a CD. Unfortunately they have to be in the database and can't be stored loose in folders. I'm storing them as an OLE object, and I can read and write them just fine as a byte[].
However, I don't know the best way of getting these documents back open in Word. Right now I'm using a FileStream to recreate the file in somewhere and then shooting off a System.Diagnostics.Process.Start(filename) to get it to open. This is going to be used on government computers which can have some funky security rules sometimes, so I don't know if this is the best way.
Is it possible to open a file previously stored as a byte[] without using any intermediary file saved to the hard drive? I know they'll at least have Word 2003, so I'm open to using the Word interop.
Thanks for any input!
I doubt you're going to be able to feed Word a file in memory without saving it to at least a RAMDisk or something wild like that.
Why not use the system temp folder or the GetTempFile() method to write the byte array to a file just before opening it using Word and then cleaning up the temp files when you're done?
string fullPathToATempFile = System.IO.Path.GetTempFileName();
// or
string tempDirPath = System.IO.Path.GetTempPath();

Categories

Resources