|
Yes I do that everytime before I execute (.ExecuteNonQuery()) any command..the problem is when I return to Form1 (Remember that the transaction is set to a valuer in Form2), I create a new SqlCommand and I write :
sqlcommandObj.Transaction = transactionObj;
But I always get an error here :
sqlcommandObj.ExecuteNonQuery();
|
|
|
|
|
It would be helpful if you told us what the exception type and message were, perhaps even a stack trace. Would you just tell a doctor that you have a pain without specifying where?
Microsoft MVP, Visual C#
My Articles
|
|
|
|
|
for logging purposes, I need to be able to determine the thread ID of the currently executing thread.
I've discovered that I can pretty easily get the thread ID from the ProcessThread class. What I can't figure out is how to determine which ProcessThread corresponds to System.Threading.Thread.CurrentThread.
Any tips on how to get the ID that I'm looking for?
BTW, I've already tried using Thread.CurrentThread.GetHashCode(). While it seems to work (unique numbers), a comparison to the ProcessThread IDs in the app makes it perfectly clear that there's no direct correlation.
Grim (aka Toby) MCDBA, MCSD, MCP+SB
|
|
|
|
|
I used the following two:
System.Diagnositics.ProcessThread Id Property
AppDomain.GetCurrentThreadId()
The former is OS Thread ( so Process)
The latter is CLR Thread ( so AppDomain)
Is that what you are look for ? Any other ways ??
James
|
|
|
|
|
Thanks, James. The AppDomain is what I was looking for.
Grim (aka Toby) MCDBA, MCSD, MCP+SB
|
|
|
|
|
Is this possible? I've done it successfully many times on Controls and UserControls, but I'm having a tough time getting them to show up on a form. For example:
[Designer(typeof(MBen.Windows.Forms.Wizard.Design.WizardDesigner))]
public class Wizard : System.Windows.Forms.Form
{
...
}
</pre/
Here's the designer:
<pre>
public class WizardDesigner : System.Windows.Forms.Design.ControlDesigner
{
private DesignerVerb[] m_Verbs;
public WizardDesigner()
{
System.Diagnostics.Debug.WriteLine("Inited");
m_Verbs = new DesignerVerb[1];
m_Verbs[0] = new DesignerVerb("Add/Remove Pages", new EventHandler(OnAddRemovePages));
}
public override DesignerVerbCollection Verbs
{
get
{
System.Diagnostics.Debug.WriteLine("Doh");
return new DesignerVerbCollection(m_Verbs);
}
}
protected void OnAddRemovePages(object sender, EventArgs e)
{
MessageBox.Show("Clicked");
}
}
When I right-mouse click on my form, no verbs have been added.
Any ideas?
Thanks in advance.
Kyosa Jamie Nordmeyer - Cho Dan
Portland, Oregon, USA
|
|
|
|
|
Got it.
[Designer(typeof(MBen.Windows.Forms.Wizard.Design.WizardDesigner))]
public class Wizard : System.Windows.Forms.Form
should be
[Designer(typeof(MBen.Windows.Forms.Wizard.Design.WizardDesigner), typeof(IRootDesigner))]
public class Wizard : System.Windows.Forms.Form
Kyosa Jamie Nordmeyer - Cho Dan
Portland, Oregon, USA
|
|
|
|
|
Hi,
Is there any painless way to marshal an object [] into a ptr?
I'm writing a plugin wrapper and the object [] is a paramarray ['params'] that represents a structure in the plugin. I was wondering if there was an easy way to do this, similar to the Marshal.StructureToPtr() maybe ..
Here's an example for clearification ..
The wrapper's function:
<br />
void MyPluginFunction (params object [] data)<br />
{<br />
ptr = MarshalObjToPtr(data);<br />
PluginFunction(ptr);<br />
}<br />
The plugin function to be called (written in C# for this example)
<br />
void PluginFunction (IntPtr ptr)<br />
{<br />
myData = (MyStruct)Marshal.PtrToStructure(ptr);<br />
...<br />
}<br />
Now 'myData' now holds all info in ptr, but in MyStruct representation.
NOTE: The plugin may not be written in C#,
and that is why I would need is to be marshalled.
Using the wrapper would be as simple as:
<br />
MyPluginFunction(12, 8, "hello");<br />
The above would map to the plugin's structure:
<br />
private struct MyStruct<br />
{<br />
int a, b;<br />
string s;<br />
}<br />
Thus allowing the above function's 'myData' to be as follows:
myData.a = 12, myData.b = 8, myData.s = "hello"
Or if there's an easier way to do this, that could work too.
Best regards,
- Joe
|
|
|
|
|
An array is already a reference type, so unless you have to marshal it as an IntPtr , just declare your P/Invoke method using the array of whatever Type is needed (if that's what the native API expects).
Otherwise, you must get the address of it by fixing it in memory. See the fixed keyword in the .NET Framework SDK for more information.
Another way to do this (basically, what fixed compiles down to) is to use the GCHandle to pin the object in memory so it doesn't get moved by the garbage collector (GC):
GCHandle handle = GCHandle.Alloc(myObjArray);
IntPtr ptr = handle.AddrOfPinnedObject();
handle.Free();
Microsoft MVP, Visual C#
My Articles
|
|
|
|
|
Hi, everyone
For functions in Win32 libraries that will copy a string value into a string buffer, I try to use string. It works. But recently, I read an article about this, it suggests to use StringBuilder instead of string. Because string type is an immutable type in .Net. If using string for string buffer, it could corrupt the temporary buffer created by the marshaler when a string is translated or corrupt the managed heap. But my program works pretty good and I saw some other people's code is doing the same thing as min. Can anyone give me more ideas about this?
Thanks in advance.
|
|
|
|
|
I've been using string almost every time without problem, and so does Microsoft most of the time in the Framework Class Library (FCL) for various native API P/Invoke declarations and struct fields.
It wouldn't hurt to use a StringBuilder instead, but so long as you take care of allocating and freeing your strings appropriately (when necessary), you probably should be fine.
Microsoft MVP, Visual C#
My Articles
|
|
|
|
|
Hi,
Is posible send XML via Socket?
Where can I found documentation about this?
Thanks
|
|
|
|
|
rbarzallo wrote:
Is posible send XML via Socket?
Yes, you can send any stream of bytes via a socket. However, using higher level methods may be more appropriate.
rbarzallo wrote:
Where can I found documentation about this?
Well, if you already know how to use sockets it is very simple. All you need to do is to convert the string (Encode[^]) to a byte array and then send it. (You'll find other Encoders and Decoders in the System.Text namespace if UTF8 is not what you are looking for - I just chose UTF8 because Visual Studio defaults to that character encoding for XML files.).
At the other end you receive the bytes and convert them (Decode[^]) to a string.
Does this help?
"You can have everything in life you want if you will just help enough other people get what they want." --Zig Ziglar
"On two occasions, I have been asked [by members of Parliament], 'Pray, Mr. Babbage, if you put into the machine wrong figures, will the right answers come out?' I am not able to rightly apprehend the kind of confusion of ideas that could provoke such a question."
--Charles Babbage (1791-1871)
|
|
|
|
|
Sure. But really you probably don't want to use sockets directly as that's fairly low level. You might want to use System.Runtime.Remoting to pass objects (presumably containing XML data) across to another machine. FYI, if you use remoting over HTTP, all data packets are sent in a stream of XML anyway. The other option is using remoting over the TCP channel, in which data gets sent as a stream of binary formatted data.
If you're looking for more info on remoting, MSDN has some good examples, and you might also want to check out Ingo Rammer's remoting site[^].
---------------------------
He who knows that enough is enough will always have enough.
-Lao Tsu
|
|
|
|
|
The transport channel (HTTP or TCP) has nothing to do with the format of the data. This depends on what formatter you specify in your remoting configuration. Both a SoapFormatter and BinaryFormatter are provided in the FCL and can be used for any transport channel (unless some third-party transport channel is anal about that or something).
The transport channels may default to a specific formatter, but it can be changed.
Microsoft MVP, Visual C#
My Articles
|
|
|
|
|
Right you are, I stand corrected. Typically, one would use a binary formatter for use over a TCP channel, and a SOAP formatter for use over an HTTP channel, but yeah you're right it doesn't have to be that way.
---------------------------
He who knows that enough is enough will always have enough.
-Lao Tsu
|
|
|
|
|
Heath,
I think in addition, Formatter sink are used to serialize IMessage, have nothing to do with the XML in IMessage. ie. You can even transmmit XML using BinaryFormatter. Transmitt XML using Socket is realistic since mobile device may not support remoting.
Correct me if I am making mistakes
Thanks
James
|
|
|
|
|
No, you're not wrong, but I fail to see what you're getting at. The DataSet , for example, still serializes as XML even using the BinaryFormatter , but the only point I was making was that no specific formatter must be used with any specific transport channel.
Microsoft MVP, Visual C#
My Articles
|
|
|
|
|
I used to convert a double like so:
double l_dTmp = 0.0;
string l_szTmp = l_dTmp.ToString("e3");
The output was:
0.000e+000
On my new computer (Windows2000, SP4) I do the same but the output is:
0.000e,000
The '-' sign is formatted fine.
Can anyone help?
Thanks
|
|
|
|
|
This is going to sound really weird...
I think your Regional and Language Settings have got screwed up. In the registry, go to HKEY_CURRENT_USER\Control Panel\International and set the sPositiveSign value to an empty string.
I just set mine to ',' and reproduced your problem.
Stability. What an interesting concept. -- Chris Maunder
|
|
|
|
|
Actually, it's recommended you use the "Regional and Language Options" control panel applet. Either way should work, though. Hacking the registry can be dangerous if you screw up.
Microsoft MVP, Visual C#
My Articles
|
|
|
|
|
I checked the registry and the entry for sPositiveSign is blank. I added the + sign and it converts the double values fine. However, my older computer has also a blank entry but it ads the '+' sign.
When I use ToString("e3", new CultureInfo("")) it also works fine but I get ',' instead of '+' with "en-US" culture.
Thanks for your help
|
|
|
|
|
I have an application that runs on our server that I can no longer get support for.
The application runs great for days at a time and then it crashes.
I would like to write a task manager type utility that would automatically cancel the application.
Can you point me in the right direction? C++ or C# code highly desired.
thanks
|
|
|
|
|
I'm not sure I fully understand you. Do you want to monitor when the program has crashed? If so, you can do this quite easily in any .NET language using System.Diagnostics.Process.GetProcessesByName (or one of the other static methods of the Process class) to determine whether the process is still running.
---------------------------
He who knows that enough is enough will always have enough.
-Lao Tsu
|
|
|
|
|
thank you - that was helpful
|
|
|
|