|
Try
string connectionString = "Data Source=srv032k3; Initial Catalog=MuzeDB; User ID=sa; Password=YourPassword";
take a look there[^]
for more information.
|
|
|
|
|
You're also creating an adapter from a select statement. Is it possible to insert through that? That seems a bit weird to me.
|
|
|
|
|
Yes. I have done it. It adds a new row and it also selects all records from the table and puts them into the dataset.
|
|
|
|
|
hello everyone,
I want to calculate the total data download and upload in a particular interval of time, and store it to a database so that it can be viewed later on. data downloaded from internet
browser or uploaded using default downloader and i want to store info - size and time
info. is it possible through system.diagnostics namespace........
thank you for any help...........
|
|
|
|
|
I have created an XML using sql in SQL Server 2005.
I like to Save that XML as a File in a particular location on the disk.
I want only C# to make it done...
It would not be possible to create that file on the disk using SQL Server becoz,
I haven't administrator permission for the Sql Server.
if i use DataReader to get field value, than it's not return complete xml...
what i have to do...?
|
|
|
|
|
|
Presumably you are not asking how to create a file on the SQL Server file system itself given that you do not have access to that file system. So....
Steps
1. Connect to SQL Server
2. Query for xml
3. Open file
4. Read xml
5. Write xml to file.
6. Continue 4 and 6 until all of the xml is read.
7. Close the connection and the file.
The above are distinct parts of the total problem.
|
|
|
|
|
Hi.
I want to make a program to download files from a remote host.
So what i do is to send throw sockets all the binary information + a string used as end "mystyring".
To check if i have to continue writing the buffer to the file i first convert all to string, so if i find "mystring" it will finish, if not, i reconvert all to bytes and i copy data.
The problem im having is that, .txt files are writed well, but binaris not, it always show error at opening. I ve tried copying a pdf, and when i open it show all the pages, but in blank . Also if i check the size of the original file is always some bytes bigger than the copy.
FileStream fs = new FileStream("C:\\Users\\Mauri\\Desktop\\" + item.Name, FileMode.Append, FileAccess.Write);
BinaryWriter writer = new BinaryWriter(fs);
bool continua = true;
while (continua)
{
recibido = getSocket(numsock).socketRecv();
words = recibido.Split('|');
foreach (string s in words)
{
if ((String.Compare(s, "mystring") != 0))
writer.Write(StringToBytes(s));
else
continua = false;
}
}
writer.Close();
fs.Close();
public byte[] StringToBytes(String cadena)
{
System.Text.ASCIIEncoding codificador = new System.Text.ASCIIEncoding();
return codificador.GetBytes(cadena);
}
The strange thing is that .txt files are writed correctly.
I can't use webclient class, beacuse im not downloading the data from an http or ftp server, is for a connection between 2 computers, like a remote access program.
Thanks
|
|
|
|
|
Hi,
your design is seriously flawed for a couple of reasons:
1. When transferring arbitrary files (not just text files), you should use a "binary mode", i.e. you should treat all the data as bytes, and never try and turn them into strings as that will lead to all kinds of problems.
2. In order to determine the length of the file, or the amount of data, at the receiver end, the preferred method is by simply transmitting the length. Looking for a specific data pattern (a bit pattern, a string, it doesn't matter) is unsafe, as the same pattern could exist inside the actual data, resulting in a premature end of transmission. So get an int or a long holding the length and transmit that first, from then on the receiver can count down until it has had enough.
So I suggest you revise your approach and your code completely.
FWIW: your code is losing all '|' characters!
Luc Pattyn [My Articles] Nil Volentibus Arduum
The quality and detail of your question reflects on the effectiveness of the help you are likely to get. Please use <PRE> tags for code snippets, they improve readability. CP Vanity has been updated to V2.4
modified on Sunday, June 12, 2011 8:19 PM
|
|
|
|
|
Thanks for your answer.
I've tried another way to do this, not looking for a data pattern, and i ve found the NetworkStream class.
This is what i have:
NetworkStream nStream = new NetworkStream(getSocket(numsock).getSocket(),true);
byte[] myReadBuffer = new byte[1024];
FileStream fs = new FileStream("C:\\Users\\Mauri\\Desktop\\" + item.Name, FileMode.Append, FileAccess.Write);
BinaryWriter writer = new BinaryWriter(fs);
do
{
nStream.Read(myReadBuffer, 0, myReadBuffer.Length);
writer.Write(myReadBuffer);
}
while (nStream.DataAvailable);
writer.Close();
fs.Close();
When the program makes the first archive, it is ok, rar, zip, pdf, any extension works well, but when i try to download a second file, it is corrupted.
Any idea what is going wrong ?
Thanks
|
|
|
|
|
yes, a typical mistake. A read operation not always returns the amount of data requested. Your first file length isn't necessarily a multiple of 1024, so the last read is bound to return less, yet you write an entire array of 1024 data bytes. The solution is simple: capture the return value of Read() and use it as a parameter to Write() .
BTW: all streams have a Dispose method which you should call to clean up; AFAIK such Dispose() automatically calls Flush() and Close() when necessary. A simple way to get Dispose() called automatically is through the using statement, like so:
using (NetworkStream nStream = new NetworkStream(getSocket(numsock).getSocket(),true)) {
using (FileStream fs = new FileStream("C:\\Users\\Mauri\\Desktop\\" + item.Name, FileMode.Append, FileAccess.Write)) {
using (BinaryWriter writer = new BinaryWriter(fs)) {
for(;;) {
int len=nStream.Read(myReadBuffer, 0, myReadBuffer.Length);
if (len==0) break;
writer.Write(myReadBuffer, 0, len);
}
}
}
}
which avoids a number of potential mistakes and yields the most readable code IMO.
Of course, you might want to reorganize if you need to keep the NetworkStream alive after a file has been transmitted. Then either rearrange the code so it handles a number of files inside the outer using, or drop the using and call nStream.Dispose() explicitly when done.
Luc Pattyn [My Articles] Nil Volentibus Arduum
The quality and detail of your question reflects on the effectiveness of the help you are likely to get. Please use <PRE> tags for code snippets, they improve readability. CP Vanity has been updated to V2.4
|
|
|
|
|
Ok catched that, but the problem is that my socket, never returns "0" so len == 0 gives timeout exception:
Unable to write data to the transport connection: An error occurred during connection attempt because the connected part did not properly respond after a period of time, or failed to established connection and connected host has failed to respond.
in
int len = nStream.Read(myReadBuffer, 0, myReadBuffer.Length); line.
Thanks
PD: If you can explain me, or give me some documentation about the "using", that you put in the code, would be great.
|
|
|
|
|
Actually, there is more to it than what I said earlier. If the NetworkStream remains open and you send another file, it will look like more bytes coming through the cable, and the receiver will not know where the first file ends and the second one begins. You do need something extra to carry that information.
If the length is known in advance, as when sending a file from disk, then you could put a writer.Write(fs.Length); in front of the data copying loop. Your receiver should then read than length and loop until it has read that many bytes. At that point either the transmission is over or another file is coming.
Luc Pattyn [My Articles] Nil Volentibus Arduum
The quality and detail of your question reflects on the effectiveness of the help you are likely to get. Please use <PRE> tags for code snippets, they improve readability. CP Vanity has been updated to V2.4
|
|
|
|
|
In addition to what Luc said in the first post, you are closing the connection after data is no longer available (read=0) so you can't use this socket to read another. If you want to keep the connection open for multiple files you will need to specify a protocol that sends the length first and then the contents; for example have a look at the message handling code in my socket library[^], though that's slightly obfuscated by the encryption support.
|
|
|
|
|
Hi Guys. I want to dev an app which will read ASCII files but using their COBOL copy-books as format reference and then mapping them into a new COBOL copy-book. Is there a plugin that would let me specify a cobol copy book and then reference the input file against it and read it?
I coul probably write the layouts as classes and do it that way bbut this will take ages as I have many copy-books to do.
My aim is to read in a file, refer to the copy book for the format and then convert it to a different copy-book by "cross mapping".
Anybody done anything like this before? I'm just looking for suggestions or references to articles or some web links. All I can find is some IBM stuff, WEBSPHERE etc but not what I am looking for though.
Thanks
Excellence is doing ordinary things extraordinarily well.
|
|
|
|
|
I have no idea what a COBOL copy-book is. Maybe post a snippet of one? Plus a sample of what the input and output would be?
|
|
|
|
|
I think I got one as a present in the thread below. Consider it yours if you want it.
Luc Pattyn [My Articles] Nil Volentibus Arduum
The quality and detail of your question reflects on the effectiveness of the help you are likely to get. Please use <PRE> tags for code snippets, they improve readability. CP Vanity has been updated to V2.4
|
|
|
|
|
|
The one right below this one, titled "PrintPreviewControl and HTML", holding a "contribution" by the same author.
And yes, if you haven't already.
Luc Pattyn [My Articles] Nil Volentibus Arduum
The quality and detail of your question reflects on the effectiveness of the help you are likely to get. Please use <PRE> tags for code snippets, they improve readability. CP Vanity has been updated to V2.4
|
|
|
|
|
|
|
I want to creat a .net app reading "messages" or shall I say files defined by a cobol-copy book format/layout. Do this I want to reference the copy-book and pass the message to it for unmarshalling and then writing it out to another message in yet another cobol copy-book format. Like creating a middleware app. If I have to transform the copy book and write it out to as a file format, it could take ages as they are huge layouts and would be easier just to reference the copy-book. Hope this explains!
Excellence is doing ordinary things extraordinarily well.
|
|
|
|
|
|
Hi all,
I have some html files (Custom Reports) and I want to show the print preview of them to the user.I don't want to use IE print preview or web browser because they are not embedded in my application and I can not control them the way I want. I was wondering if there is a way to preview a html file in PrintPreviewControl (or any other components like that)?
Please help me.
thank you.
Every new thing you learn,Gives you a new personality.
|
|
|
|
|
Assuming your app is a WinForms app, I see three possibilities:
1.
Use a WebBrowser control and have it navigate to your HTML document.
2.
Use any external app you choose (MS Word if you must), and make it show its main form inside your app, by calling SetParent (using P/Invoke).
3.
create your own UserControl, that parses and interprets HTML; it is quite a job, probably not worth the effort it would take.
Luc Pattyn [My Articles] Nil Volentibus Arduum
The quality and detail of your question reflects on the effectiveness of the help you are likely to get. Please use <PRE> tags for code snippets, they improve readability. CP Vanity has been updated to V2.4
|
|
|
|