|
I'm not getting an exception when my code runs thru this method, but it's also not writing out this record. Any suggestion?
<br />
private void WriteRecord(byte[] ByteBuffer, int TrackNumber)<br />
{<br />
SqlConnection myConnection = new SqlConnection(strConnect);<br />
SqlDataReader myReader = null;<br />
SqlTransaction transaction = myConnection.BeginTransaction();<br />
try<br />
{<br />
myConnection.Open();<br />
SqlCommand myCommand = new SqlCommand("SELECT * FROM DMV2 WHERE DMV2_TRACK_NO = " + TrackNumber + " AND DMV2_RCD_TYPE = 'Q'", myConnection);<br />
myCommand.Connection = myConnection;<br />
myReader = myCommand.ExecuteReader();<br />
myReader.Read();<br />
<br />
<br />
String DMV2_T_KEY = myReader["DMV2_T_KEY"].ToString();<br />
String DMV2_UNIT_NO = myReader["DMV2_UNIT_NO"].ToString();<br />
String DMV2_QUERY_TYPE = myReader["DMV2_QUERY_TYPE"].ToString();<br />
String DMV2_TRACK_NO = myReader["DMV2_TRACK_NO"].ToString();<br />
String DMV2_ORG_DTTM = myReader["DMV2_ORG_DTTM"].ToString();<br />
String DMV2_ORG_WORKSTATION = myReader["DMV2_ORG_WORKSTATION"].ToString();<br />
String DMV2_ORG_ID = myReader["DMV2_ORG_ID"].ToString();<br />
String DMV2_RCV_WORKSTATION = myReader["DMV2_RCV_WORKSTATION"].ToString();<br />
<br />
String myText = "INSERT INTO DMV2" +<br />
"(DMV2_RCD_TYPE, DMV2_QUERY_TYPE, DMV2_TRACK_NO, DMV2_T_KEY, DMV2_UNIT_NO, " +<br />
"DMV2_ORG_DTTM, DMV2_ORG_WORKSTATION, DMV2_ORG_ID, DMV2_RCV_DTTM, DMV2_RCV_WORKSTATION, " +<br />
"DMV2_RCV_STATUS, DMV2_DATA_TEXT)" +<br />
"VALUES ('R', '" + DMV2_QUERY_TYPE + "', '" + DMV2_TRACK_NO + "', '" + DMV2_T_KEY + "', '" + DMV2_UNIT_NO + <br />
"', '" + DMV2_ORG_DTTM + "', '" + DMV2_ORG_WORKSTATION + "', '" + DMV2_ORG_ID +<br />
"', CURRENT_TIMESTAMP, '" + DMV2_RCV_WORKSTATION + "', 'P','" + ByteBuffer.ToString() + "')";<br />
myCommand = new SqlCommand(myText, myConnection, transaction).ExecuteNonQuery();<br />
transaction.Commit();<br />
}<br />
catch(SqlException sqlError)<br />
{<br />
MessageBox.Show(sqlError.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);<br />
transaction.Rollback();<br />
}<br />
<br />
myConnection.Close();<br />
}<br />
<br />
<br />
Tom Wright
tawright915@yahoo.com
|
|
|
|
|
You should switch to stored procedures if possible. One thing I see is this 'ByteBuffer.ToString()', this is going to return System.Byte[] -- thats all I see from here, the problem is probably a datatype. Copy the myText to your clipboard during an execution and try to run that query exactly as it was copied into SQL Query Analyzer, or use SQL Profiler to see whats happening.
Empires
|
|
|
|
|
Yeah I'm seeing System.Byte[]. Thanks for the heads up on that. However, if I put a messagebox(I can't step thru it on my pc so I have to use message boxes to see where I am at in the code) before the string is put together, but after the select statement is run, nothing pop's up. It's like it just dropping out of the method with out returning an exception. It's strange.
Would an SP work faster since it's server side? Or does it just make it easier to insert rows?
One other thing. Is looks like the primary key is a seeded key. Would this be something that could be causing the problem?
Thanks
Tom Wright
tawright915@yahoo.com
|
|
|
|
|
Tom Wright wrote: Would an SP work faster since it's server side? Or does it just make it easier to insert rows?
Or even make your application more secure - which is the primary reason I use stored procedures.
|
|
|
|
|
|
Colin Angus Mackay wrote: I don't see how this even compiles as TrackNumber is an int.
C# will work this out for you, if you concatenate a string and an int.
Christian Graus - Microsoft MVP - C++
Metal Musings - Rex and my new metal blog
|
|
|
|
|
Christian Graus wrote: C# will work this out for you, if you concatenate a string and an int.
I just tried it. So it does.
|
|
|
|
|
Learn something new everyday.
By the way I haven't read that link yet, but I did move all of the SQL statements to a SP. It works much better and seems like less of a headache. I should have done that a long time ago. I think I will still change how I'm passing my parameters to the SP as I'm still concatenating them together and do an ExecuteNonQuery. I think I'll look in to the parameters way of passing them, as well as read the link you sent me.
Thanks
Tom Wright
tawright915@gmail.com
|
|
|
|
|
What is a best approach for compressing directories structure witch contains multipile files into single zip file using c#.
|
|
|
|
|
|
i was wondering if it was possible to make a c# user control and imbed/anchor it into a vb6 form. what im trying to do is transition an application to c# 2.0 (three tier appplication with composite application block as teh front end). I would like to use c# user controls (these can be reused in the CAB) and wrapp it with a com/interop wrapper and use that same control in vb6, but im not sure how to approach it. any ideas?
|
|
|
|
|
Hi,
I use the new version of the ListView (.net framework 2.0). I decided to make it virtual (due to the large amount of items) and set the ownerdraw property to true (to have the full control of the items drawing).
The items (and sub items) are correctly displayed as long as i do not move the mouse over the subitems. Since i start to move the mouse over the subitems, the content (a string) disapears. It is like the Invalidate was not correctly done internally by the control. I put a break point in the function that draws the subitems and i never get into it (protected override void OnDrawSubItem) when i move the mouse over.
Here are the functions used to accomplish the work:
protected override void OnDrawColumnHeader(DrawListViewColumnHeaderEventArgs e)
protected override void OnDrawItem(DrawListViewItemEventArgs e)
protected override void OnDrawSubItem(DrawListViewSubItemEventArgs e)
protected override void OnRetrieveVirtualItem(RetrieveVirtualItemEventArgs e)
In my constructor i set the following properties;
SetStyle(ControlStyles.DoubleBuffer, true);
this.OwnerDraw = true;
this.VirtualMode = true;
this.DoubleBuffered = true;
I suspect a bug in the CLR. I would really appreciate if someone could light my candle on that issue.
Thank you!
Regards,
Fred.
- Frédéric dB -
|
|
|
|
|
A dirty (but reliable) solution would be to handle the OnMouseMove event and invalidate the listitems.
As of how to accomplish this I wouldn't have a clue at the moment and I'm too lazy to google it
|
|
|
|
|
I already tested that solution The result is better, the subitems are repainted but the subitem under my mouse pointer is still erased and not repainted till i move my mouse over an other one.
Anyway thanks for the suggestion.
- Frédéric dB -
|
|
|
|
|
Isn't there a ControlStyle for painting related to the mouse?
(You know the Control.SetStyle(..., true); )
As of how to accomplish this I wouldn't have a clue at the moment and I'm too lazy to google it
|
|
|
|
|
You maybe speak about :
Control.SetStyle(ControlStyles.UserMouse, true);)
If true, the control does its own mouse processing, and mouse events are not handled by the operating system.
No, apparently it doesn't help that much.
- Frédéric dB -
|
|
|
|
|
I'm not sure then, I'd take a thorough look through your drawing code since it is more likely to be there (but it's not impossible that it's a CLR bug).
Formula 1 - Short for "F1 Racing" - named after the standard "help" key in Windows, it's a sport where participants desperately search through software help files trying to find actual documentation. It's tedious and somewhat cruel, most matches ending in a draw as no participant is able to find anything helpful. - Shog9
Ed
|
|
|
|
|
I can't count how many .NET remoting tutorials and book excerpts i read. Every single time the example involves a chat client passing strings or some other example where strings, ints, and simple user defined types are begin passed. I am looking for an example which shows me how to pass pointer types, like most things in .NET library. For example, I want to pass a FileInfo or FileStream object from server to client. I tried that, it didn't work. Someone told me that's because System.IO.FileStream object, for example, is a pointer to a memory location which would have meaning on the machine it was instantiated on. If I pass that pointer to another machine than that pointer would have no meaning on that machine.
But I did check and FileInfo object derives from MarshalByRefObject, so I thought that means it could be used accross machine boundries.
I am trying to write the simplest and non-dirties of file transfer apps where the client passes a FileStream to a server, server reads it and saves it localy. Simple stuff. Cannot figure it out.
Please help.
|
|
|
|
|
You have to consider what you're asking the machine to do. You want to pass a file stream from one machine to another. Are you sending all the data in that stream or just a pointer to the stream? Assuming you send a pointer, is the intention for you to read a stream from another computer? It's just not going to work that way. You can either send over the entire file or you can open up a tcp channel and stream it through there.
Logifusion[^]
If not entertaining, write your Congressman.
|
|
|
|
|
Yes, the intention is for server to get a pointer to a FileStream from a client machine then save it on the server. To make things simple, lets say the server needs to read 4 bytes from clients file:
Client:
-------
FileStream fileStream = new FileStram("C:\\Some File.txt");
// Assume all the .NET remoting connection stuff was already established
Server server = new Server();
server.Send(fileStream);
Server:
----------
void Send(FileStream fileStream)
{
byte[] someData = new byte[4];
fileStream.Read(someData, 0, someData.Length);
// then do something with that data
}
That does not work for me, the app will hang. But I do not see why. FileStream is a pointer yes, but it is a type that derives from MarshalByRefObject. So when the server executes "fileStream.Read(someData, 0, someData.Length);" it has to make a call to the client which will execute that method on the FileStream object, then return the read bytes back to server. I thought thats the whole point of .NET remoting, the ability to call objects across machine boundries.
|
|
|
|
|
Well, yes, FileStream is a MarshalByRefObject . But, internally, it has a cursor that is inside the client's file. That cursor is completely invalid on any other machine except the client. Trying to read data from a client machine through the server will just not work. There are only two ways to accomplish this: send the entire file to the server or open up a network channel on the client and allow the server to read the data through that channel.
Logifusion[^]
If not entertaining, write your Congressman.
|
|
|
|
|
See, I'm trying to understand .NET Remoting, and if object were people here is how I think they would talk (based on the code sample in my previous response).
Client To Server: "Server, Im sending u a FileStream object. If you want to know anything about it, let me know. From your point of you, this is just a description of the object. You can't do anything with it. Im just letting you know that I have this object and what features this object has. Ask me and I will tell you anything about it.
Server To Client: "Ok, I want you to read 4 bytes from the object starting at the begining and then send the bytes back to me."
Client To Server: [CLIENT Reads the 4 bytes locally] "Ok, there you go, I read the 4 bytes from the beginning and sent it to you."
So I thought thats the idea with MarshalByRefObjects as opposed to [Serializable] objects. If the cursor is invalid on any other machine then that shouldnt matter. Because the server machine is marshaling all calls to the client, the server is not actually doing anything with the object. When a certain function is executed on the object on the server, the server asks two questions "What do I need to pass to the client and what will the client return to me?" Then it marhals a call to the client.
I the case of "fileStream.Read(someData, 0, someData.Length);" the server doesnt do jack with filesSream, it just lets the client know that the it should read 4 bytes from the file and send it back to the server. Then the sever would store the data in "someData" array. If this is not the case then I am totaly lost.
-- modified at 14:51 Monday 31st July, 2006
|
|
|
|
|
Well, let's clear up the terminology a little bit. MarshalByRefObject indicates to remoting that a proxy has to be created. So, when you send a FileStream to the server, you're actually creating a proxy on the server side that it can pass it's calls through to the client. Calling it a pointer is what was confusing me because it sounded like you wanted to transfer the serialized FileStream object over to the server.
Anyways, you can use the FileStream on the server side, because .Net remoting will create the proxy for you. But this is very inefficient. The call to the proxy will be interpreted and sent to the client, which will do the work then interpret and send it back to the server, which has to be interpreted again and send back to the caller. It's much faster to open a channel and just send the file.
Also, I understand you have a client application and a server application and the file needs to go from client to server. But, in remoting, the side that has the proxy is the client. Your client application will actually have to become a server. This is my understanding of how it works anyway. The server appliation needs a proxy and the only way it can get that is by being a client.
Logifusion[^]
If not entertaining, write your Congressman.
|
|
|
|
|
I don't know why it is failing for you. I've done the same thing with a memory stream between appDomains, which should perform the same way, but it might not. It probably makes more sense to create your own marshalByRef proxy object wrapping the filestream to pass in as a parameter. That will give you more freedom to change the internal implementation in the future and you should be able to debug the methods of your custom object.
Also, if you are running these from seperate systems disable any firewalls that might be causing problems allowing the return connection from the server back to the client.
-- modified at 16:22 Monday 31st July, 2006
I can imagine the sinking feeling one would have after ordering my book,
only to find a laughably ridiculous theory with demented logic once the book arrives - Mark McCutcheon
|
|
|
|
|
I somehow think it has something to do with secuirty. I am going to dig into it a bit, it's just frustrates me how little there is on .net remoting there is. Even books like "Advanced .NET Remoting" would start off with chat client sample and then divulge into writing your own sinks and lease times and all that, not single one tutorial used something like passing a Form or a Button from client to server, its all strings and ints and bytes.
|
|
|
|
|