BCP (bulk copy program) binary data c# - c#

I'm working with Microsoft Sql Server. I use bcp to recovery my data and it's ok. I create a binary file.
Now I want read this binary file trought my c# application, but I have problems.
I create binary with o without \r terminator, but I have problems.
I try all web solutions (BinaryReader, convert to byte array etc...) that I find.
Thanks in advance.

Related

Importing a MS-Project mpp file into C# .Net Framework and exporting the data into an SQLite database using MPXJ

**
Hello
**
I'm creating a scheduling app that takes in 2 MS-Project .mpp files (master and updated) and converts the data into SQLite tables then compares them both and displays the results and allows you to write the changes you make back to the master file. I had issues with Microsoft Interop because I don't own Microsoft Project. Is MPXJ a viable solution? The documentation I've read on it doesn't have many examples. If so how would I read it in and read it back? Were using MS-project 2016
I know nothing of MPXJ, so sorry if I overlook a more straightforward answer. It sounds to me like another way of looking at your problem is you want to:
1. Parse a MS Project file (and then do it again) and store results in memory
2. Do some data manipulation and calculations of the in-memory project data
3. Put that data into a database
I think you're stuck at step 1 because without MS Project, you lack a parser; correct? There are other ways to parse a project file. The simplest may be to have your users first convert the files to a more open format (e.g. XML) when they save them from their instances of MS Project. Lacking that, there are certainly libraries out there that can parse a Project file. Try taking a look at Gantt Project, https://sourceforge.net/projects/ganttproject/ . Being open source, you could look at that parser as a starting point; I'm not a license expert, but you may even be able to re-use the code from there.
Good luck!

Convert / Read Btrieve Sequential file to human readable text using C#

Does anyone know if its possible to read ascii the files that Btrieve Maintenance Utility creates during its recover process using C#
We create sequence files using the following command on windows
for %%f in (*.xq?) DO BUTIL -recover %%f %%f.seq
I know these files are Ascii files but when i open them in notepad++ it's almost impossible to make something of it
If i look at the documentation of it,i can't figure out how i need to read these files using C#
Those aren't regular ASCII files. They are byte images of the record. For strings, they come through as ASCII but numbers don't come through as human readable text. You would have to parse the individual bytes within each line and would need record structure.
If you know the record structure, you might be able to parse the data into a structure but not every Btrieve data type is directly accessible through C#.
A better option is to use the Btrieve / PSQL client, read the actual data file, and extract it using a proper Btrieve / PSQL / Actian interface (like ODBC, OLEDB, Managed Provider, even the Btrieve API).

How to Save a Binary Representation to file

I have the following textual binary representation: "0x255044462D312E340D0A25FFFFFFF..."
I know it's a pdf.
I know it's the textual represantation from a sql server column (image data type).
But im lost to find out how to save this binary to a pdf file on my disk and view the content.
Maybe someone can hint me in the right direction.
Best Regards and Thanks in Advance
You're correct that it is a PDF file (at least it masquerades like on. You have hexadecimally encoded bytes; the first read:
255044462D312E340D0A
%PDF-1.4<CR><LF>
So you appear to have a PDF 1.4 string.
Just take two characters from the string, treat them as hex, convert them to the correct byte and write them to a file. Write binary, not textually (you don't want to add additional line-breaks in there, PDF is too binary to let that work.
(I did the conversion using this site: http://www.dolcevie.com/js/converter.html)
I'm not sure what database you are working with or how you are getting your string that you have above.
Many databases allow you to save binary data as a blob or some other byte array type. I believe in MSSQL this is called an "image" but I am not 100% on that. I would start by looking into the two following links in order. The first link talks about how to pull byte array data from a database. The example is in Visual Basic but should be easily changed to C# if that is what you are using.
The second link contains an example of how to save that byte array data to the file system.
I would also suggest posting some of the code you have tried as well so that the community may comment and point out areas you possibly had misunderstandings on.
1.) http://support.microsoft.com/kb/308042
2.) Save and load MemoryStream to/from a file
http://www.pdfsharp.com/PDFsharp/ can read in binary data and you can call .Save() and it will make the PDF file to disk for you.

SSRS report corrupt when writing to file with WriteAllBytes C#

We have a process that has SQL Server Reporting Services create a pdf file via
ReportExecutionService.Render
from data in the database. Then we save the byte array that Render returns to the database. Later I get the byte array and do a
File.WriteAllBytes
to write it to disk before attaching it to an email and sending it. The problem I'm running into is that after writing the file to disk, it is corrupt somehow. I'm not sure what to look at, can anyone help?
Thanks
EDIT:
I can write the file from SSRS to disk before saving the byte array to the database and I can view that fine.
If you work with the byte[] returned by render, then things are fine, but if once you write that to the DB and read it back, you have problems, correct?
Why don't you compare the array written in to the DB with the one you retrieve to find the problem? Then start looking into your DB write and read routines, finally your DB storage.
I've done similar things without problems, such as taking the results of a Reporting Services call into a bytestream and attaching that directly to an email, both using a memorystream and an on-disk file. So the basics of this are sound and should work.
Not sure if this is your issue or not, but if the PDF file itself is corrupt you might want to look at how it's being written. If Windows Preview can view the PDF but Adobe cannot, it may have to do with the fact that Adobe is expecting %PDF in the first 1024 bytes of the file (otherwise it will consider it corrupt).

Edit VSAM file using C#

We are looking at different ways to update a VSAM file.
One of the things that we would like to do is to stop writing any new cobol code.
We were wondering is it possible to download a VSAM file from the Main Frame to a Windows Server, then use a C# program to edit it, then transfer it back to the Main frame?
Has anyone tried this?
And yes we are moving away from the use of VSAM, but it takes time.
There are plenty of other options for updating a VSAM file other than a COBOL program.
Transferring the file and and back again seems a perverse and error prone way to update a simple VSAM file. Most VSAM files contain a mix of character, integer and packed decimal data, C# plain cannot handle mainframe packed decimal and any attempt to translate EBDCIC to ASCII during file transfer will corrupt the packed decimal and binary values, so, you will need to manipulate raw EBCDIC characters.
Obviously you can write a COBOL program! (seems perverse not to!)
You could also write a C, C++, Java or PL/1 program all of which run on the mainframe, all of which have VSAM support.
You could extract to a sequential file update with a script (zsh, Rexx, PERL etc. etc.) and reload. (Your site may have an add-in that allows direct update from Rexx).
Most largish mainframe sites have an add on utility like File-Aid, Startool or Ditto which allow direct editing of VSAM files.
The MS way would be to use Biztalk Microsoft Host Integration Server to access VSAM.
There might be other non-MS drivers, which I am not aware of - maybe via DB2 Windows drivers.

Categories